Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xuexiangjys
TemplateAppProject
提交
0ddff69c
T
TemplateAppProject
项目概览
xuexiangjys
/
TemplateAppProject
通知
17
Star
0
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
4
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TemplateAppProject
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
4
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0ddff69c
编写于
3月 23, 2020
作者:
xuexiangjys
😊
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化演示demo
上级
d97794e4
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
739 addition
and
124 deletion
+739
-124
README.md
README.md
+1
-0
app/build.gradle
app/build.gradle
+1
-0
app/src/main/java/com/xuexiang/templateproject/adapter/NewsCardViewListAdapter.java
...iang/templateproject/adapter/NewsCardViewListAdapter.java
+0
-115
app/src/main/java/com/xuexiang/templateproject/adapter/base/delegate/BaseDelegateAdapter.java
...ateproject/adapter/base/delegate/BaseDelegateAdapter.java
+61
-0
app/src/main/java/com/xuexiang/templateproject/adapter/base/delegate/SimpleDelegateAdapter.java
...eproject/adapter/base/delegate/SimpleDelegateAdapter.java
+64
-0
app/src/main/java/com/xuexiang/templateproject/adapter/base/delegate/SingleDelegateAdapter.java
...eproject/adapter/base/delegate/SingleDelegateAdapter.java
+72
-0
app/src/main/java/com/xuexiang/templateproject/adapter/base/delegate/XDelegateAdapter.java
...mplateproject/adapter/base/delegate/XDelegateAdapter.java
+300
-0
app/src/main/java/com/xuexiang/templateproject/fragment/news/NewsFragment.java
.../xuexiang/templateproject/fragment/news/NewsFragment.java
+89
-9
app/src/main/java/com/xuexiang/templateproject/utils/DemoDataProvider.java
.../com/xuexiang/templateproject/utils/DemoDataProvider.java
+20
-0
app/src/main/res/layout/adapter_common_grid_item.xml
app/src/main/res/layout/adapter_common_grid_item.xml
+52
-0
app/src/main/res/layout/adapter_title_item.xml
app/src/main/res/layout/adapter_title_item.xml
+45
-0
app/src/main/res/layout/fragment_news.xml
app/src/main/res/layout/fragment_news.xml
+1
-0
app/src/main/res/values/arrays.xml
app/src/main/res/values/arrays.xml
+22
-0
app/src/main/res/values/colors.xml
app/src/main/res/values/colors.xml
+11
-0
未找到文件。
README.md
浏览文件 @
0ddff69c
...
...
@@ -84,6 +84,7 @@ git clone https://github.com/xuexiangjys/TemplateAppProject.git
姓名 | 金额 | 方式
:-|:-|:-
myie9 | 100¥ | 微信
*
鸥 | 10.24¥ | 微信
## 联系方式
...
...
app/build.gradle
浏览文件 @
0ddff69c
...
...
@@ -95,6 +95,7 @@ dependencies {
//分包
implementation
deps
.
androidx
.
multidex
implementation
'com.alibaba.android:vlayout:1.2.8'
//下拉刷新
implementation
'com.github.xuexiangjys.SmartRefreshLayout:refresh-header:1.1.5'
implementation
'com.github.xuexiangjys.SmartRefreshLayout:refresh-layout:1.1.5'
...
...
app/src/main/java/com/xuexiang/templateproject/adapter/NewsCardViewListAdapter.java
已删除
100644 → 0
浏览文件 @
d97794e4
/*
* Copyright (C) 2020 xuexiangjys(xuexiangjys@163.com)
*
* 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.
*
*/
package
com.xuexiang.templateproject.adapter
;
import
android.view.View
;
import
androidx.annotation.NonNull
;
import
com.xuexiang.templateproject.R
;
import
com.xuexiang.templateproject.adapter.entity.NewInfo
;
import
com.xuexiang.templateproject.utils.XToastUtils
;
import
com.xuexiang.xui.adapter.recyclerview.BaseRecyclerAdapter
;
import
com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder
;
import
com.xuexiang.xui.adapter.recyclerview.XRecyclerAdapter
;
import
com.xuexiang.xui.widget.banner.widget.banner.BannerItem
;
import
com.xuexiang.xui.widget.banner.widget.banner.SimpleImageBanner
;
import
com.xuexiang.xui.widget.banner.widget.banner.base.BaseBanner
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* 首页动态新闻【只是用于演示效果】
*
* @author XUE
* @since 2019/5/9 10:41
*/
public
class
NewsCardViewListAdapter
extends
BaseRecyclerAdapter
<
NewInfo
>
{
private
static
final
int
TYPE_BANNER_HEAD
=
0
;
private
static
final
int
TYPE_COMMON
=
1
;
private
List
<
BannerItem
>
mData
;
/**
* @param bannerData 轮播条的内容
*/
public
NewsCardViewListAdapter
(
List
<
BannerItem
>
bannerData
)
{
super
();
mData
=
bannerData
;
}
/**
* 适配的布局
*
* @param viewType
* @return
*/
@Override
protected
int
getItemLayoutId
(
int
viewType
)
{
if
(
viewType
==
TYPE_BANNER_HEAD
)
{
return
R
.
layout
.
include_head_view_banner
;
}
else
{
return
R
.
layout
.
adapter_news_card_view_list_item
;
}
}
@Override
public
int
getItemViewType
(
int
position
)
{
if
(
position
==
0
)
{
return
TYPE_BANNER_HEAD
;
}
else
{
return
TYPE_COMMON
;
}
}
public
XRecyclerAdapter
refresh
(
List
<
NewInfo
>
data
)
{
List
<
NewInfo
>
list
=
new
ArrayList
<>(
data
);
//用于占位
list
.
add
(
0
,
new
NewInfo
());
return
super
.
refresh
(
list
);
}
@Override
public
void
bindData
(
@NonNull
RecyclerViewHolder
holder
,
int
position
,
NewInfo
model
)
{
if
(
model
==
null
)
{
return
;
}
if
(
getItemViewType
(
position
)
==
TYPE_BANNER_HEAD
)
{
SimpleImageBanner
headBanner
=
holder
.
findViewById
(
R
.
id
.
sib_simple_usage
);
headBanner
.
setSource
(
mData
)
.
setOnItemClickListener
(
new
BaseBanner
.
OnItemClickListener
<
BannerItem
>()
{
@Override
public
void
onItemClick
(
View
view
,
BannerItem
item
,
int
position
)
{
XToastUtils
.
toast
(
"点击轮播条--->"
+
position
);
}
}).
startScroll
();
}
else
{
holder
.
text
(
R
.
id
.
tv_user_name
,
model
.
getUserName
());
holder
.
text
(
R
.
id
.
tv_tag
,
model
.
getTag
());
holder
.
text
(
R
.
id
.
tv_title
,
model
.
getTitle
());
holder
.
text
(
R
.
id
.
tv_summary
,
model
.
getSummary
());
holder
.
text
(
R
.
id
.
tv_praise
,
model
.
getPraise
()
==
0
?
"点赞"
:
String
.
valueOf
(
model
.
getPraise
()));
holder
.
text
(
R
.
id
.
tv_comment
,
model
.
getComment
()
==
0
?
"评论"
:
String
.
valueOf
(
model
.
getComment
()));
holder
.
text
(
R
.
id
.
tv_read
,
"阅读量 "
+
model
.
getRead
());
holder
.
image
(
R
.
id
.
iv_image
,
model
.
getImageUrl
());
}
}
}
app/src/main/java/com/xuexiang/templateproject/adapter/base/delegate/BaseDelegateAdapter.java
0 → 100644
浏览文件 @
0ddff69c
/*
* Copyright (C) 2020 xuexiangjys(xuexiangjys@163.com)
*
* 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.
*
*/
package
com.xuexiang.templateproject.adapter.base.delegate
;
import
android.view.ViewGroup
;
import
androidx.annotation.NonNull
;
import
com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder
;
import
java.util.Collection
;
/**
* 通用的DelegateAdapter适配器
*
* @author xuexiang
* @since 2020/3/20 12:44 AM
*/
public
abstract
class
BaseDelegateAdapter
<
T
>
extends
XDelegateAdapter
<
T
,
RecyclerViewHolder
>
{
public
BaseDelegateAdapter
()
{
super
();
}
public
BaseDelegateAdapter
(
Collection
<
T
>
list
)
{
super
(
list
);
}
public
BaseDelegateAdapter
(
T
[]
data
)
{
super
(
data
);
}
/**
* 适配的布局
*
* @param viewType
* @return
*/
protected
abstract
int
getItemLayoutId
(
int
viewType
);
@NonNull
@Override
protected
RecyclerViewHolder
getViewHolder
(
@NonNull
ViewGroup
parent
,
int
viewType
)
{
return
new
RecyclerViewHolder
(
inflateView
(
parent
,
getItemLayoutId
(
viewType
)));
}
}
app/src/main/java/com/xuexiang/templateproject/adapter/base/delegate/SimpleDelegateAdapter.java
0 → 100644
浏览文件 @
0ddff69c
/*
* Copyright (C) 2020 xuexiangjys(xuexiangjys@163.com)
*
* 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.
*
*/
package
com.xuexiang.templateproject.adapter.base.delegate
;
import
com.alibaba.android.vlayout.LayoutHelper
;
import
java.util.Collection
;
/**
* 简易DelegateAdapter适配器
*
* @author xuexiang
* @since 2020/3/20 12:55 AM
*/
public
abstract
class
SimpleDelegateAdapter
<
T
>
extends
BaseDelegateAdapter
<
T
>
{
private
int
mLayoutId
;
private
LayoutHelper
mLayoutHelper
;
public
SimpleDelegateAdapter
(
int
layoutId
,
LayoutHelper
layoutHelper
)
{
super
();
mLayoutId
=
layoutId
;
mLayoutHelper
=
layoutHelper
;
}
public
SimpleDelegateAdapter
(
int
layoutId
,
LayoutHelper
layoutHelper
,
Collection
<
T
>
list
)
{
super
(
list
);
mLayoutId
=
layoutId
;
mLayoutHelper
=
layoutHelper
;
}
public
SimpleDelegateAdapter
(
int
layoutId
,
LayoutHelper
layoutHelper
,
T
[]
data
)
{
super
(
data
);
mLayoutId
=
layoutId
;
mLayoutHelper
=
layoutHelper
;
}
@Override
protected
int
getItemLayoutId
(
int
viewType
)
{
return
mLayoutId
;
}
@Override
public
LayoutHelper
onCreateLayoutHelper
()
{
return
mLayoutHelper
;
}
}
app/src/main/java/com/xuexiang/templateproject/adapter/base/delegate/SingleDelegateAdapter.java
0 → 100644
浏览文件 @
0ddff69c
/*
* Copyright (C) 2020 xuexiangjys(xuexiangjys@163.com)
*
* 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.
*
*/
package
com.xuexiang.templateproject.adapter.base.delegate
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
androidx.annotation.LayoutRes
;
import
androidx.annotation.NonNull
;
import
com.alibaba.android.vlayout.DelegateAdapter
;
import
com.alibaba.android.vlayout.LayoutHelper
;
import
com.alibaba.android.vlayout.layout.SingleLayoutHelper
;
import
com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder
;
/**
* 单独布局的DelegateAdapter
*
* @author xuexiang
* @since 2020/3/20 1:04 AM
*/
public
abstract
class
SingleDelegateAdapter
extends
DelegateAdapter
.
Adapter
<
RecyclerViewHolder
>
{
private
int
mLayoutId
;
public
SingleDelegateAdapter
(
int
layoutId
)
{
mLayoutId
=
layoutId
;
}
@Override
public
LayoutHelper
onCreateLayoutHelper
()
{
return
new
SingleLayoutHelper
();
}
/**
* 加载布局获取控件
*
* @param parent 父布局
* @param layoutId 布局ID
* @return
*/
protected
View
inflateView
(
ViewGroup
parent
,
@LayoutRes
int
layoutId
)
{
return
LayoutInflater
.
from
(
parent
.
getContext
()).
inflate
(
layoutId
,
parent
,
false
);
}
@NonNull
@Override
public
RecyclerViewHolder
onCreateViewHolder
(
@NonNull
ViewGroup
parent
,
int
viewType
)
{
return
new
RecyclerViewHolder
(
inflateView
(
parent
,
mLayoutId
));
}
@Override
public
int
getItemCount
()
{
return
1
;
}
}
app/src/main/java/com/xuexiang/templateproject/adapter/base/delegate/XDelegateAdapter.java
0 → 100644
浏览文件 @
0ddff69c
/*
* Copyright (C) 2020 xuexiangjys(xuexiangjys@163.com)
*
* 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.
*
*/
package
com.xuexiang.templateproject.adapter.base.delegate
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
androidx.annotation.LayoutRes
;
import
androidx.annotation.NonNull
;
import
androidx.recyclerview.widget.RecyclerView
;
import
com.alibaba.android.vlayout.DelegateAdapter
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.List
;
/**
* 基础DelegateAdapter
*
* @author xuexiang
* @since 2020/3/20 12:17 AM
*/
public
abstract
class
XDelegateAdapter
<
T
,
V
extends
RecyclerView
.
ViewHolder
>
extends
DelegateAdapter
.
Adapter
<
V
>
{
/**
* 数据源
*/
protected
final
List
<
T
>
mData
=
new
ArrayList
<>();
/**
* 当前点击的条目
*/
protected
int
mSelectPosition
=
-
1
;
public
XDelegateAdapter
()
{
}
public
XDelegateAdapter
(
Collection
<
T
>
list
)
{
if
(
list
!=
null
)
{
mData
.
addAll
(
list
);
}
}
public
XDelegateAdapter
(
T
[]
data
)
{
if
(
data
!=
null
&&
data
.
length
>
0
)
{
mData
.
addAll
(
Arrays
.
asList
(
data
));
}
}
/**
* 构建自定义的ViewHolder
*
* @param parent
* @param viewType
* @return
*/
@NonNull
protected
abstract
V
getViewHolder
(
@NonNull
ViewGroup
parent
,
int
viewType
);
/**
* 绑定数据
*
* @param holder
* @param position 索引
* @param item 列表项
*/
protected
abstract
void
bindData
(
@NonNull
V
holder
,
int
position
,
T
item
);
/**
* 加载布局获取控件
*
* @param parent 父布局
* @param layoutId 布局ID
* @return
*/
protected
View
inflateView
(
ViewGroup
parent
,
@LayoutRes
int
layoutId
)
{
return
LayoutInflater
.
from
(
parent
.
getContext
()).
inflate
(
layoutId
,
parent
,
false
);
}
@NonNull
@Override
public
V
onCreateViewHolder
(
@NonNull
ViewGroup
parent
,
int
viewType
)
{
return
getViewHolder
(
parent
,
viewType
);
}
@Override
public
void
onBindViewHolder
(
@NonNull
V
holder
,
int
position
)
{
bindData
(
holder
,
position
,
mData
.
get
(
position
));
}
/**
* 获取列表项
*
* @param position
* @return
*/
public
T
getItem
(
int
position
)
{
return
checkPosition
(
position
)
?
mData
.
get
(
position
)
:
null
;
}
private
boolean
checkPosition
(
int
position
)
{
return
position
>=
0
&&
position
<=
mData
.
size
()
-
1
;
}
public
boolean
isEmpty
()
{
return
getItemCount
()
==
0
;
}
@Override
public
int
getItemCount
()
{
return
mData
.
size
();
}
/**
* @return 数据源
*/
public
List
<
T
>
getData
()
{
return
mData
;
}
/**
* 给指定位置添加一项
*
* @param pos
* @param item
* @return
*/
public
XDelegateAdapter
add
(
int
pos
,
T
item
)
{
mData
.
add
(
pos
,
item
);
notifyItemInserted
(
pos
);
return
this
;
}
/**
* 在列表末端增加一项
*
* @param item
* @return
*/
public
XDelegateAdapter
add
(
T
item
)
{
mData
.
add
(
item
);
notifyItemInserted
(
mData
.
size
()
-
1
);
return
this
;
}
/**
* 删除列表中指定索引的数据
*
* @param pos
* @return
*/
public
XDelegateAdapter
delete
(
int
pos
)
{
mData
.
remove
(
pos
);
notifyItemRemoved
(
pos
);
return
this
;
}
/**
* 刷新列表中指定位置的数据
*
* @param pos
* @param item
* @return
*/
public
XDelegateAdapter
refresh
(
int
pos
,
T
item
)
{
mData
.
set
(
pos
,
item
);
notifyItemChanged
(
pos
);
return
this
;
}
/**
* 刷新列表数据
*
* @param collection
* @return
*/
public
XDelegateAdapter
refresh
(
Collection
<
T
>
collection
)
{
if
(
collection
!=
null
)
{
mData
.
clear
();
mData
.
addAll
(
collection
);
mSelectPosition
=
-
1
;
notifyDataSetChanged
();
}
return
this
;
}
/**
* 刷新列表数据
*
* @param array
* @return
*/
public
XDelegateAdapter
refresh
(
T
[]
array
)
{
if
(
array
!=
null
&&
array
.
length
>
0
)
{
mData
.
clear
();
mData
.
addAll
(
Arrays
.
asList
(
array
));
mSelectPosition
=
-
1
;
notifyDataSetChanged
();
}
return
this
;
}
/**
* 加载更多
*
* @param collection
* @return
*/
public
XDelegateAdapter
loadMore
(
Collection
<
T
>
collection
)
{
if
(
collection
!=
null
)
{
mData
.
addAll
(
collection
);
notifyDataSetChanged
();
}
return
this
;
}
/**
* 加载更多
*
* @param array
* @return
*/
public
XDelegateAdapter
loadMore
(
T
[]
array
)
{
if
(
array
!=
null
&&
array
.
length
>
0
)
{
mData
.
addAll
(
Arrays
.
asList
(
array
));
notifyDataSetChanged
();
}
return
this
;
}
/**
* 添加一个
*
* @param item
* @return
*/
public
XDelegateAdapter
load
(
T
item
)
{
if
(
item
!=
null
)
{
mData
.
add
(
item
);
notifyDataSetChanged
();
}
return
this
;
}
/**
* @return 当前列表的选中项
*/
public
int
getSelectPosition
()
{
return
mSelectPosition
;
}
/**
* 设置当前列表的选中项
*
* @param selectPosition
* @return
*/
public
XDelegateAdapter
setSelectPosition
(
int
selectPosition
)
{
mSelectPosition
=
selectPosition
;
notifyDataSetChanged
();
return
this
;
}
/**
* 获取当前列表选中项
*
* @return 当前列表选中项
*/
public
T
getSelectItem
()
{
return
getItem
(
mSelectPosition
);
}
/**
* 清除数据
*/
public
void
clear
()
{
if
(!
isEmpty
())
{
mData
.
clear
();
mSelectPosition
=
-
1
;
notifyDataSetChanged
();
}
}
}
app/src/main/java/com/xuexiang/templateproject/fragment/news/NewsFragment.java
浏览文件 @
0ddff69c
...
...
@@ -17,18 +17,30 @@
package
com.xuexiang.templateproject.fragment.news
;
import
androidx.annotation.NonNull
;
import
androidx.recyclerview.widget.RecyclerView
;
import
com.alibaba.android.vlayout.DelegateAdapter
;
import
com.alibaba.android.vlayout.VirtualLayoutManager
;
import
com.alibaba.android.vlayout.layout.GridLayoutHelper
;
import
com.alibaba.android.vlayout.layout.LinearLayoutHelper
;
import
com.scwang.smartrefresh.layout.SmartRefreshLayout
;
import
com.xuexiang.templateproject.R
;
import
com.xuexiang.templateproject.adapter.NewsCardViewListAdapter
;
import
com.xuexiang.templateproject.adapter.base.delegate.SimpleDelegateAdapter
;
import
com.xuexiang.templateproject.adapter.base.delegate.SingleDelegateAdapter
;
import
com.xuexiang.templateproject.adapter.entity.NewInfo
;
import
com.xuexiang.templateproject.core.BaseFragment
;
import
com.xuexiang.templateproject.utils.DemoDataProvider
;
import
com.xuexiang.templateproject.utils.Utils
;
import
com.xuexiang.templateproject.utils.XToastUtils
;
import
com.xuexiang.xpage.annotation.Page
;
import
com.xuexiang.xpage.enums.CoreAnim
;
import
com.xuexiang.xui.utils.WidgetUtils
;
import
com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder
;
import
com.xuexiang.xui.adapter.simple.AdapterItem
;
import
com.xuexiang.xui.widget.actionbar.TitleBar
;
import
com.xuexiang.xui.widget.banner.widget.banner.SimpleImageBanner
;
import
com.xuexiang.xui.widget.imageview.ImageLoader
;
import
com.xuexiang.xui.widget.imageview.RadiusImageView
;
import
butterknife.BindView
;
...
...
@@ -46,7 +58,7 @@ public class NewsFragment extends BaseFragment {
@BindView
(
R
.
id
.
refreshLayout
)
SmartRefreshLayout
refreshLayout
;
private
NewsCardViewListAdapter
m
Adapter
;
private
SimpleDelegateAdapter
<
NewInfo
>
mNews
Adapter
;
/**
* @return 返回为 null意为不需要导航栏
...
...
@@ -71,8 +83,78 @@ public class NewsFragment extends BaseFragment {
*/
@Override
protected
void
initViews
()
{
WidgetUtils
.
initRecyclerView
(
recyclerView
,
0
);
recyclerView
.
setAdapter
(
mAdapter
=
new
NewsCardViewListAdapter
(
DemoDataProvider
.
getBannerList
()));
VirtualLayoutManager
virtualLayoutManager
=
new
VirtualLayoutManager
(
getContext
());
recyclerView
.
setLayoutManager
(
virtualLayoutManager
);
RecyclerView
.
RecycledViewPool
viewPool
=
new
RecyclerView
.
RecycledViewPool
();
recyclerView
.
setRecycledViewPool
(
viewPool
);
viewPool
.
setMaxRecycledViews
(
0
,
10
);
//轮播条
SingleDelegateAdapter
bannerAdapter
=
new
SingleDelegateAdapter
(
R
.
layout
.
include_head_view_banner
)
{
@Override
public
void
onBindViewHolder
(
@NonNull
RecyclerViewHolder
holder
,
int
position
)
{
SimpleImageBanner
banner
=
holder
.
findViewById
(
R
.
id
.
sib_simple_usage
);
banner
.
setSource
(
DemoDataProvider
.
getBannerList
())
.
setOnItemClickListener
((
view
,
item
,
position1
)
->
XToastUtils
.
toast
(
"headBanner position--->"
+
position1
)).
startScroll
();
}
};
//九宫格菜单
GridLayoutHelper
gridLayoutHelper
=
new
GridLayoutHelper
(
4
);
gridLayoutHelper
.
setPadding
(
0
,
16
,
0
,
0
);
gridLayoutHelper
.
setVGap
(
10
);
gridLayoutHelper
.
setHGap
(
0
);
SimpleDelegateAdapter
<
AdapterItem
>
commonAdapter
=
new
SimpleDelegateAdapter
<
AdapterItem
>(
R
.
layout
.
adapter_common_grid_item
,
gridLayoutHelper
,
DemoDataProvider
.
getGridItems
(
getContext
()))
{
@Override
protected
void
bindData
(
@NonNull
RecyclerViewHolder
holder
,
int
position
,
AdapterItem
item
)
{
if
(
item
!=
null
)
{
RadiusImageView
imageView
=
holder
.
findViewById
(
R
.
id
.
riv_item
);
imageView
.
setCircle
(
true
);
ImageLoader
.
get
().
loadImage
(
imageView
,
item
.
getIcon
());
holder
.
text
(
R
.
id
.
tv_title
,
item
.
getTitle
().
toString
().
substring
(
0
,
1
));
holder
.
text
(
R
.
id
.
tv_sub_title
,
item
.
getTitle
());
holder
.
click
(
R
.
id
.
ll_container
,
v
->
XToastUtils
.
toast
(
"点击了:"
+
item
.
getTitle
()));
}
}
};
//资讯的标题
SingleDelegateAdapter
titleAdapter
=
new
SingleDelegateAdapter
(
R
.
layout
.
adapter_title_item
)
{
@Override
public
void
onBindViewHolder
(
@NonNull
RecyclerViewHolder
holder
,
int
position
)
{
holder
.
text
(
R
.
id
.
tv_title
,
"资讯"
);
holder
.
text
(
R
.
id
.
tv_action
,
"更多"
);
holder
.
click
(
R
.
id
.
tv_action
,
v
->
XToastUtils
.
toast
(
"更多"
));
}
};
//资讯
mNewsAdapter
=
new
SimpleDelegateAdapter
<
NewInfo
>(
R
.
layout
.
adapter_news_card_view_list_item
,
new
LinearLayoutHelper
())
{
@Override
protected
void
bindData
(
@NonNull
RecyclerViewHolder
holder
,
int
position
,
NewInfo
model
)
{
if
(
model
!=
null
)
{
holder
.
text
(
R
.
id
.
tv_user_name
,
model
.
getUserName
());
holder
.
text
(
R
.
id
.
tv_tag
,
model
.
getTag
());
holder
.
text
(
R
.
id
.
tv_title
,
model
.
getTitle
());
holder
.
text
(
R
.
id
.
tv_summary
,
model
.
getSummary
());
holder
.
text
(
R
.
id
.
tv_praise
,
model
.
getPraise
()
==
0
?
"点赞"
:
String
.
valueOf
(
model
.
getPraise
()));
holder
.
text
(
R
.
id
.
tv_comment
,
model
.
getComment
()
==
0
?
"评论"
:
String
.
valueOf
(
model
.
getComment
()));
holder
.
text
(
R
.
id
.
tv_read
,
"阅读量 "
+
model
.
getRead
());
holder
.
image
(
R
.
id
.
iv_image
,
model
.
getImageUrl
());
holder
.
click
(
R
.
id
.
card_view
,
v
->
Utils
.
goWeb
(
getContext
(),
model
.
getDetailUrl
()));
}
}
};
DelegateAdapter
delegateAdapter
=
new
DelegateAdapter
(
virtualLayoutManager
);
delegateAdapter
.
addAdapter
(
bannerAdapter
);
delegateAdapter
.
addAdapter
(
commonAdapter
);
delegateAdapter
.
addAdapter
(
titleAdapter
);
delegateAdapter
.
addAdapter
(
mNewsAdapter
);
recyclerView
.
setAdapter
(
delegateAdapter
);
}
@Override
...
...
@@ -81,7 +163,7 @@ public class NewsFragment extends BaseFragment {
refreshLayout
.
setOnRefreshListener
(
refreshLayout
->
{
// TODO: 2020-02-25 这里只是模拟了网络请求
refreshLayout
.
getLayout
().
postDelayed
(()
->
{
mAdapter
.
refresh
(
DemoDataProvider
.
getDemoNewInfos
());
m
News
Adapter
.
refresh
(
DemoDataProvider
.
getDemoNewInfos
());
refreshLayout
.
finishRefresh
();
},
1000
);
});
...
...
@@ -89,12 +171,10 @@ public class NewsFragment extends BaseFragment {
refreshLayout
.
setOnLoadMoreListener
(
refreshLayout
->
{
// TODO: 2020-02-25 这里只是模拟了网络请求
refreshLayout
.
getLayout
().
postDelayed
(()
->
{
mAdapter
.
loadMore
(
DemoDataProvider
.
getDemoNewInfos
());
m
News
Adapter
.
loadMore
(
DemoDataProvider
.
getDemoNewInfos
());
refreshLayout
.
finishLoadMore
();
},
1000
);
});
refreshLayout
.
autoRefresh
();
//第一次进入触发自动刷新,演示效果
mAdapter
.
setOnItemClickListener
((
itemView
,
item
,
position
)
->
Utils
.
goWeb
(
getContext
(),
item
.
getDetailUrl
()));
}
}
app/src/main/java/com/xuexiang/templateproject/utils/DemoDataProvider.java
浏览文件 @
0ddff69c
...
...
@@ -17,8 +17,14 @@
package
com.xuexiang.templateproject.utils
;
import
android.content.Context
;
import
android.graphics.drawable.Drawable
;
import
com.xuexiang.templateproject.R
;
import
com.xuexiang.templateproject.adapter.entity.NewInfo
;
import
com.xuexiang.xaop.annotation.MemoryCache
;
import
com.xuexiang.xui.adapter.simple.AdapterItem
;
import
com.xuexiang.xui.utils.ResUtils
;
import
com.xuexiang.xui.widget.banner.widget.banner.BannerItem
;
import
java.util.ArrayList
;
...
...
@@ -96,5 +102,19 @@ public class DemoDataProvider {
return
list
;
}
public
static
List
<
AdapterItem
>
getGridItems
(
Context
context
)
{
return
getGridItems
(
context
,
R
.
array
.
grid_titles_entry
,
R
.
array
.
grid_icons_entry
);
}
private
static
List
<
AdapterItem
>
getGridItems
(
Context
context
,
int
titleArrayId
,
int
iconArrayId
)
{
List
<
AdapterItem
>
list
=
new
ArrayList
<>();
String
[]
titles
=
ResUtils
.
getStringArray
(
titleArrayId
);
Drawable
[]
icons
=
ResUtils
.
getDrawableArray
(
context
,
iconArrayId
);
for
(
int
i
=
0
;
i
<
titles
.
length
;
i
++)
{
list
.
add
(
new
AdapterItem
(
titles
[
i
],
icons
[
i
]));
}
return
list
;
}
}
app/src/main/res/layout/adapter_common_grid_item.xml
0 → 100644
浏览文件 @
0ddff69c
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2020 xuexiangjys(xuexiangjys@163.com)
~
~ 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.
~
-->
<com.xuexiang.xui.widget.alpha.XUIAlphaLinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
android:id=
"@+id/ll_container"
android:layout_width=
"match_parent"
android:layout_height=
"80dp"
android:gravity=
"center"
android:orientation=
"vertical"
>
<FrameLayout
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
>
<com.xuexiang.xui.widget.imageview.RadiusImageView
android:id=
"@+id/riv_item"
android:layout_width=
"50dp"
android:layout_height=
"50dp"
tools:src=
"@mipmap/ic_launcher"
/>
<TextView
android:id=
"@+id/tv_title"
style=
"@style/TextStyle.Title"
android:layout_gravity=
"center"
android:textColor=
"@color/xui_config_color_white"
tools:text=
"菜"
/>
</FrameLayout>
<TextView
android:id=
"@+id/tv_sub_title"
style=
"@style/TextStyle.Explain"
android:layout_marginTop=
"5dp"
tools:text=
"菜单1"
/>
</com.xuexiang.xui.widget.alpha.XUIAlphaLinearLayout>
\ No newline at end of file
app/src/main/res/layout/adapter_title_item.xml
0 → 100644
浏览文件 @
0ddff69c
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2020 xuexiangjys(xuexiangjys@163.com)
~
~ 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.
~
-->
<FrameLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"8dp"
android:layout_marginBottom=
"4dp"
>
<TextView
android:id=
"@+id/tv_title"
style=
"@style/TextStyle.Title"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"start|center_vertical"
android:paddingStart=
"16dp"
android:paddingEnd=
"16dp"
tools:text=
"标题"
/>
<TextView
android:id=
"@+id/tv_action"
style=
"@style/TextStyle.Explain"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"end|center_vertical"
android:paddingStart=
"16dp"
android:paddingEnd=
"16dp"
tools:text=
"更多"
/>
</FrameLayout>
app/src/main/res/layout/fragment_news.xml
浏览文件 @
0ddff69c
...
...
@@ -20,6 +20,7 @@
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"@color/xui_config_color_white"
android:orientation=
"vertical"
>
<com.scwang.smartrefresh.layout.SmartRefreshLayout
...
...
app/src/main/res/values/arrays.xml
浏览文件 @
0ddff69c
...
...
@@ -57,5 +57,27 @@
<item>
bayimob.com
</item>
</string-array>
<string-array
name=
"grid_titles_entry"
>
<item>
美食
</item>
<item>
甜点
</item>
<item>
烧烤
</item>
<item>
夜宵
</item>
<item>
水果
</item>
<item>
药品
</item>
<item>
蔬菜
</item>
<item>
跑腿
</item>
</string-array>
<!-- 修改这里的图标 -->
<array
name=
"grid_icons_entry"
>
<item>
@color/app_color_theme_1
</item>
<item>
@color/app_color_theme_2
</item>
<item>
@color/app_color_theme_3
</item>
<item>
@color/app_color_theme_4
</item>
<item>
@color/app_color_theme_5
</item>
<item>
@color/app_color_theme_6
</item>
<item>
@color/app_color_theme_7
</item>
<item>
@color/app_color_theme_8
</item>
</array>
</resources>
\ No newline at end of file
app/src/main/res/values/colors.xml
浏览文件 @
0ddff69c
...
...
@@ -13,4 +13,15 @@
<color
name=
"toast_warning_color"
tools:ignore=
"PrivateResource"
>
@color/xui_config_color_waring
</color>
<color
name=
"toast_normal_tint_color"
tools:ignore=
"PrivateResource"
>
#353A3E
</color>
<color
name=
"app_color_theme_1"
>
#EF5362
</color>
<!-- Grapefruit -->
<color
name=
"app_color_theme_2"
>
#FE6D4B
</color>
<!-- Bittersweet -->
<color
name=
"app_color_theme_3"
>
#FFCF47
</color>
<!-- Sunflower -->
<color
name=
"app_color_theme_4"
>
#9FD661
</color>
<!-- Grass -->
<color
name=
"app_color_theme_5"
>
#3FD0AD
</color>
<!-- Mint -->
<color
name=
"app_color_theme_6"
>
#2BBDF3
</color>
<!-- Aqua -->
<color
name=
"app_color_theme_7"
>
#5A9AEF
</color>
<!-- Blue Jeans -->
<color
name=
"app_color_theme_8"
>
#AC8FEF
</color>
<!-- Lavender -->
<color
name=
"app_color_theme_9"
>
#EE85C1
</color>
<!-- Pink Rose -->
</resources>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录