home update frame

ongbodev
ongbo 6 years ago
parent 48545bca10
commit fbd9a5f41c

@ -75,18 +75,23 @@ public class SlideFragment extends Fragment {
mItemTouchHelperCallback = new ItemTouchHelperCallback(mRecyclerView.getAdapter(), mList); mItemTouchHelperCallback = new ItemTouchHelperCallback(mRecyclerView.getAdapter(), mList);
mItemTouchHelper = new ItemTouchHelper(mItemTouchHelperCallback); mItemTouchHelper = new ItemTouchHelper(mItemTouchHelperCallback);
mSlideLayoutManager = new SlideLayoutManager(mRecyclerView, mItemTouchHelper); mSlideLayoutManager = new SlideLayoutManager(mRecyclerView, mItemTouchHelper);
mItemTouchHelper.attachToRecyclerView(mRecyclerView); mItemTouchHelper.attachToRecyclerView(mRecyclerView);
mRecyclerView.setLayoutManager(mSlideLayoutManager); mRecyclerView.setLayoutManager(mSlideLayoutManager);
} }
private void initListener() { private void initListener() {
//往左滑就是不喜欢,往右滑就是喜欢
mItemTouchHelperCallback.setOnSlideListener(new OnSlideListener() { mItemTouchHelperCallback.setOnSlideListener(new OnSlideListener() {
@Override @Override
public void onSliding(RecyclerView.ViewHolder viewHolder, float ratio, int direction) { public void onSliding(RecyclerView.ViewHolder viewHolder, float ratio, int direction) {
if (direction == ItemConfig.SLIDING_LEFT) { if (direction == ItemConfig.SLIDING_LEFT) {
} else if (direction == ItemConfig.SLIDING_RIGHT) { } else if (direction == ItemConfig.SLIDING_RIGHT) {
} }
} }
@ -107,6 +112,8 @@ public class SlideFragment extends Fragment {
@Override @Override
public void onClear() { public void onClear() {
// 一旦几个页面的数据加载完了,就在这里重新加载数据
addData(); addData();
} }
}); });
@ -114,6 +121,7 @@ public class SlideFragment extends Fragment {
/** /**
* *
*
*/ */
private void addData(){ private void addData(){
int[] icons = {R.mipmap.header_icon_1, R.mipmap.header_icon_2, R.mipmap.header_icon_3, int[] icons = {R.mipmap.header_icon_1, R.mipmap.header_icon_2, R.mipmap.header_icon_3,
@ -151,6 +159,14 @@ public class SlideFragment extends Fragment {
@Override @Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(appCompatActivity).inflate(R.layout.item_slide, parent, false); View view = LayoutInflater.from(appCompatActivity).inflate(R.layout.item_slide, parent, false);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i("你呗","你点接了");
//这里可以设置点开文章好查看
// 可以新开一个Activity来查看文章
}
});
return new ViewHolder(view); return new ViewHolder(view);
} }
@ -168,10 +184,10 @@ public class SlideFragment extends Fragment {
} }
public class ViewHolder extends RecyclerView.ViewHolder { public class ViewHolder extends RecyclerView.ViewHolder {
ImageView imgBg; ImageView imgBg;//背景图片
ImageView userIcon; ImageView userIcon;//读者头像
TextView tvTitle; TextView tvTitle;//推文标题
TextView userSay; TextView userSay;//用户名或者到时候改成一段摘要也可以
public ViewHolder(View itemView) { public ViewHolder(View itemView) {
super(itemView); super(itemView);

@ -83,7 +83,8 @@ public class PersonContent extends Fragment {
public void onActivityCreated(@Nullable Bundle savedInstanceState) { public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
// rvFeed = (RecyclerView) appCompatActivity.findViewById(R.id.rvFeed); // rvFeed = (RecyclerView) appCompatActivity.findViewById(R.id.rvFeed);
viewPager = (ViewPager) appCompatActivity.findViewById(R.id.vp_vertical_ntb); // 原来的viewpager
// viewPager = (ViewPager) appCompatActivity.findViewById(R.id.vp_vertical_ntb);
mDrawer = (FlowingDrawer) appCompatActivity.findViewById(R.id.drawerlayout); mDrawer = (FlowingDrawer) appCompatActivity.findViewById(R.id.drawerlayout);
mDrawer.setTouchMode(ElasticDrawer.TOUCH_MODE_BEZEL); mDrawer.setTouchMode(ElasticDrawer.TOUCH_MODE_BEZEL);
//设置工具栏 //设置工具栏
@ -91,17 +92,22 @@ public class PersonContent extends Fragment {
setuptoolbar(); setuptoolbar();
//设置直接页面 //设置直接页面
// setupFeed(); // setupFeed();
setupViewpager(); // setupViewpager();
//设置侧滑菜单 //设置侧滑菜单
setupMenu(); setupMenu();
} }
protected void setuptoolbar(){ protected void setuptoolbar(){
//分别设置背景和头像 //分别设置背景和头像
//背景
ImageView blurimageView = (ImageView) appCompatActivity.findViewById(R.id.iv_blur); ImageView blurimageView = (ImageView) appCompatActivity.findViewById(R.id.iv_blur);
//头像
ImageView avatarImageView = (ImageView) appCompatActivity.findViewById(R.id.iv_avatar); ImageView avatarImageView = (ImageView) appCompatActivity.findViewById(R.id.iv_avatar);
Glide.with(appCompatActivity).load(R.drawable.draw7) int width = blurimageView.getWidth();
.apply(RequestOptions.bitmapTransform(new BlurTransformation(25,3))).into(blurimageView);
Glide.with(appCompatActivity).load(R.drawable.draw7)
.apply(RequestOptions.bitmapTransform(new BlurTransformation(18,3))).into(blurimageView);
// Glide.with(appCompatActivity).load(R.drawable.draw7).override(width,450)
// .into(blurimageView);
Glide.with(appCompatActivity).load(R.drawable.draw6).into(avatarImageView); Glide.with(appCompatActivity).load(R.drawable.draw6).into(avatarImageView);
//用户名 //用户名
final TextView rainbowTextView = (TextView) appCompatActivity.findViewById(R.id.user_name_person); final TextView rainbowTextView = (TextView) appCompatActivity.findViewById(R.id.user_name_person);
@ -112,156 +118,157 @@ public class PersonContent extends Fragment {
} }
}); });
avatarOnclickListener avatarOnclickListener = new avatarOnclickListener(getAppCompatActivity(),this); avatarOnclickListener avatarOnclickListener = new avatarOnclickListener(getAppCompatActivity(),this);
avatarOnclickListener.setFlowingDrawerl(mDrawer);
avatarImageView.setOnClickListener(avatarOnclickListener); avatarImageView.setOnClickListener(avatarOnclickListener);
} }
// //
//设置没有侧滑之前的状态页面 //设置没有侧滑之前的状态页面
//在这里将东西其改成几个按钮 //在这里将东西其改成几个按钮
private void setupViewpager(){ // private void setupViewpager(){
/* // /*
* // * 先设置适配器
* */ // * */
viewPager.setAdapter(new PagerAdapter() { // viewPager.setAdapter(new PagerAdapter() {
//设置菜单栏个数 // //设置菜单栏个数
@Override // @Override
public int getCount() { // public int getCount() {
return 5; // return 5;
} // }
@Override
public boolean isViewFromObject(final View view, final Object object) {
return view.equals(object);
}
//移除某一个
@Override
public void destroyItem(final View container, final int position, final Object object) {
((ViewPager) container).removeView((View) object);
}
/*
*
*
* */
@Override
public Object instantiateItem(final ViewGroup container, final int position) {
//每个position代表一个菜单根据position来设置不同视图
// //
switch (position){ // @Override
case 0: // public boolean isViewFromObject(final View view, final Object object) {
//饮食爱好 // return view.equals(object);
case 1: // }
//日历 // //移除某一个
View view = setCanlendar(); // @Override
container.addView(view); // public void destroyItem(final View container, final int position, final Object object) {
return view; // ((ViewPager) container).removeView((View) object);
case 2: // }
//消息通知 // /*
case 3: // *这里用来加载视图区,也就是每个菜单的对应的内容
//我的文章 // *但是这里应该针对不同的菜单填选对应不同的内容
case 4: // * */
//养生推荐 // @Override
// public Object instantiateItem(final ViewGroup container, final int position) {
// //每个position代表一个菜单根据position来设置不同视图
} ////
//这是默认的,不要管,因为上面必须有个返回值 // switch (position){
final View view = LayoutInflater.from( // case 0:
appCompatActivity.getBaseContext()).inflate(R.layout.item_vp, null, false); // //饮食爱好
final TextView txtPage = (TextView) view.findViewById(R.id.txt_vp_item_page); // case 1:
txtPage.setText(String.format("Page #%d", position)); // //日历
container.addView(view); // View view = setCanlendar();
// container.addView(view);
return view; // return view;
// case 2:
} // //消息通知
//设置日历 // case 3:
public View setCanlendar(){ // //我的文章
final View view = LayoutInflater.from( // case 4:
appCompatActivity.getBaseContext() // //养生推荐
).inflate(R.layout.canlendar_layout, null, false); //
return view; //
} // }
//设置饮食爱好 // //这是默认的,不要管,因为上面必须有个返回值
public View setfoodhobby(){ // final View view = LayoutInflater.from(
return null; // appCompatActivity.getBaseContext()).inflate(R.layout.item_vp, null, false);
} // final TextView txtPage = (TextView) view.findViewById(R.id.txt_vp_item_page);
}); // txtPage.setText(String.format("Page #%d", position));
/* // container.addView(view);
* //
* */ // return view;
//每个菜单选取了不同的颜色 //
final String[] colors = getResources().getStringArray(R.array.vertical_ntb); // }
//这里菜单栏选取的是NavigationTabBar // //设置日历
final NavigationTabBar navigationTabBar = (NavigationTabBar) appCompatActivity.findViewById(R.id.ntb_vertical); // public View setCanlendar(){
//这里用来加载每个model可以设置几个菜单 // final View view = LayoutInflater.from(
final ArrayList<NavigationTabBar.Model> models = new ArrayList<>(); // appCompatActivity.getBaseContext()
models.add( // ).inflate(R.layout.canlendar_layout, null, false);
new NavigationTabBar.Model.Builder( // return view;
getResources().getDrawable(R.drawable.ic_first), // }
Color.parseColor(colors[0])) // //设置饮食爱好
.title("ic_first") // public View setfoodhobby(){
.selectedIcon(getResources().getDrawable(R.drawable.ic_eighth)) // return null;
.build() // }
); // });
models.add( // /*
new NavigationTabBar.Model.Builder( // * 这里开始设置菜单栏
getResources().getDrawable(R.drawable.ic_second), // * */
Color.parseColor(colors[1])) // //每个菜单选取了不同的颜色
.selectedIcon(getResources().getDrawable(R.drawable.ic_eighth)) // final String[] colors = getResources().getStringArray(R.array.vertical_ntb);
.title("ic_second") // //这里菜单栏选取的是NavigationTabBar
.build() // final NavigationTabBar navigationTabBar = (NavigationTabBar) appCompatActivity.findViewById(R.id.ntb_vertical);
); // //这里用来加载每个model可以设置几个菜单
models.add( // final ArrayList<NavigationTabBar.Model> models = new ArrayList<>();
new NavigationTabBar.Model.Builder(
getResources().getDrawable(R.drawable.ic_third),
Color.parseColor(colors[2]))
.selectedIcon(getResources().getDrawable(R.drawable.ic_eighth))
.title("ic_third")
.build()
);
models.add(
new NavigationTabBar.Model.Builder(
getResources().getDrawable(R.drawable.ic_fourth),
Color.parseColor(colors[3]))
.selectedIcon(getResources().getDrawable(R.drawable.ic_eighth))
.title("ic_fourth")
.build()
);
models.add(
new NavigationTabBar.Model.Builder(
getResources().getDrawable(R.drawable.ic_fifth),
Color.parseColor(colors[4]))
.selectedIcon(getResources().getDrawable(R.drawable.ic_eighth))
.title("ic_fifth")
.build()
);
// models.add( // models.add(
// new NavigationTabBar.Model.Builder( // new NavigationTabBar.Model.Builder(
// getResources().getDrawable(R.drawable.ic_sixth), // getResources().getDrawable(R.drawable.ic_first),
// Color.parseColor(colors[5])) // Color.parseColor(colors[0]))
// .title("ic_first")
// .selectedIcon(getResources().getDrawable(R.drawable.ic_eighth)) // .selectedIcon(getResources().getDrawable(R.drawable.ic_eighth))
// .title("ic_sixth")
// .build() // .build()
// ); // );
// models.add( // models.add(
// new NavigationTabBar.Model.Builder( // new NavigationTabBar.Model.Builder(
// getResources().getDrawable(R.drawable.ic_seventh), // getResources().getDrawable(R.drawable.ic_second),
// Color.parseColor(colors[6])) // Color.parseColor(colors[1]))
// .selectedIcon(getResources().getDrawable(R.drawable.ic_eighth)) // .selectedIcon(getResources().getDrawable(R.drawable.ic_eighth))
// .title("ic_seventh") // .title("ic_second")
// .build() // .build()
// ); // );
// models.add( // models.add(
// new NavigationTabBar.Model.Builder( // new NavigationTabBar.Model.Builder(
// getResources().getDrawable(R.drawable.ic_eighth), // getResources().getDrawable(R.drawable.ic_third),
// Color.parseColor(colors[7])) // Color.parseColor(colors[2]))
// .selectedIcon(getResources().getDrawable(R.drawable.ic_eighth)) // .selectedIcon(getResources().getDrawable(R.drawable.ic_eighth))
// .title("ic_eighth") // .title("ic_third")
// .build() // .build()
// ); // );
//设置菜单 // models.add(
navigationTabBar.setModels(models); // new NavigationTabBar.Model.Builder(
//设置每个子菜单对一个的viewpager // getResources().getDrawable(R.drawable.ic_fourth),
navigationTabBar.setViewPager(viewPager, 0); // Color.parseColor(colors[3]))
} // .selectedIcon(getResources().getDrawable(R.drawable.ic_eighth))
// .title("ic_fourth")
// .build()
// );
// models.add(
// new NavigationTabBar.Model.Builder(
// getResources().getDrawable(R.drawable.ic_fifth),
// Color.parseColor(colors[4]))
// .selectedIcon(getResources().getDrawable(R.drawable.ic_eighth))
// .title("ic_fifth")
// .build()
// );
//// models.add(
//// new NavigationTabBar.Model.Builder(
//// getResources().getDrawable(R.drawable.ic_sixth),
//// Color.parseColor(colors[5]))
//// .selectedIcon(getResources().getDrawable(R.drawable.ic_eighth))
//// .title("ic_sixth")
//// .build()
//// );
//// models.add(
//// new NavigationTabBar.Model.Builder(
//// getResources().getDrawable(R.drawable.ic_seventh),
//// Color.parseColor(colors[6]))
//// .selectedIcon(getResources().getDrawable(R.drawable.ic_eighth))
//// .title("ic_seventh")
//// .build()
//// );
//// models.add(
//// new NavigationTabBar.Model.Builder(
//// getResources().getDrawable(R.drawable.ic_eighth),
//// Color.parseColor(colors[7]))
//// .selectedIcon(getResources().getDrawable(R.drawable.ic_eighth))
//// .title("ic_eighth")
//// .build()
//// );
// //设置菜单
// navigationTabBar.setModels(models);
// //设置每个子菜单对一个的viewpager
// navigationTabBar.setViewPager(viewPager, 0);
// }
//设置菜单 //设置菜单

@ -7,10 +7,26 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import com.example.cmknowledgegraph.LoginActivity; import com.example.cmknowledgegraph.LoginActivity;
import com.mxn.soul.flowingdrawer_core.FlowingDrawer;
/*
*
*
*
*
* */
public class avatarOnclickListener implements View.OnClickListener { public class avatarOnclickListener implements View.OnClickListener {
AppCompatActivity appCompatActivity; AppCompatActivity appCompatActivity;
Fragment personFragment; Fragment personFragment;
private FlowingDrawer flowingDrawerl;
public FlowingDrawer getFlowingDrawerl() {
return flowingDrawerl;
}
public void setFlowingDrawerl(FlowingDrawer flowingDrawerl){
this.flowingDrawerl = flowingDrawerl;
}
public avatarOnclickListener(AppCompatActivity appCompatActivity, Fragment fragment){ public avatarOnclickListener(AppCompatActivity appCompatActivity, Fragment fragment){
this.personFragment = fragment; this.personFragment = fragment;
this.appCompatActivity = appCompatActivity; this.appCompatActivity = appCompatActivity;
@ -19,7 +35,9 @@ public class avatarOnclickListener implements View.OnClickListener {
public void onClick(View v) { public void onClick(View v) {
//这里监听就是如果未登录就跳到登录界面 //这里监听就是如果未登录就跳到登录界面
if(User.isLogin()){ if(User.isLogin()){
//登陆了 //登陆了,登录了点击主界面头像就可以打开左边菜单栏
flowingDrawerl.toggleMenu();
}else{ }else{
//没有登录 //没有登录
//跳转到登录界面 //跳转到登录界面

@ -18,69 +18,43 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
> >
<!-- 主要页面的内容也就是在person直接能看到的--> <!-- 主要页面的内容也就是在person直接能看到的-->
<!-- 在这里添加自定义主页面 可支持自定义背景图还有头像然后几个cardview--> <!-- 在这里添加自定义主页面 可支持自定义背景图还有头像然后几个cardview-->
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<ImageView //上面的背景
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="@drawable/draw1"/>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="440dp"
android:orientation="horizontal"
android:background="#423752">
<devlight.io.library.ntb.NavigationTabBar
app:ntb_title_mode="all"
app:ntb_titled="true"
app:ntb_title_size="14sp"
android:id="@+id/ntb_vertical"
android:layout_width="50dp"
android:layout_height="match_parent"
app:ntb_preview_colors="@array/vertical_ntb"/>
<androidx.viewpager.widget.ViewPager
android:id="@+id/vp_vertical_ntb"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
//最上面的菜单栏
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:background="#423752">
//背景
<ImageView android:id="@+id/iv_blur" <ImageView android:id="@+id/iv_blur"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="300dp" /> android:layout_height="410dp"
android:scaleType="fitXY"
android:paddingTop="0dp"/>
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="horizontal"
android:layout_centerInParent="true"> android:layout_centerInParent="true">
//头像
<de.hdodenhof.circleimageview.CircleImageView <de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/iv_avatar" android:id="@+id/iv_avatar"
android:layout_width="80dp" android:layout_width="80dp"
android:layout_height="80dp" android:layout_height="80dp"
android:src="@drawable/draw1" android:src="@drawable/draw7"
app:civ_border_width="2dp" app:civ_border_width="2dp"
app:civ_border_color="#FF000000" app:civ_border_color="#FF000000"
/> />
//用户名
<TextView <TextView
android:id="@+id/user_name_person" android:id="@+id/user_name_person"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -94,6 +68,35 @@
</LinearLayout> </LinearLayout>
</RelativeLayout> </RelativeLayout>
<!--原来的竖向菜单-->
<!-- <LinearLayout-->
<!-- xmlns:android="http://schemas.android.com/apk/res/android"-->
<!-- xmlns:app="http://schemas.android.com/apk/res-auto"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent"-->
<!-- android:layout_marginBottom="50dp"-->
<!-- android:orientation="horizontal"-->
<!-- android:background="#423752">-->
<!-- <devlight.io.library.ntb.NavigationTabBar-->
<!-- app:ntb_title_mode="all"-->
<!-- app:ntb_titled="true"-->
<!-- app:ntb_title_size="14sp"-->
<!-- android:id="@+id/ntb_vertical"-->
<!-- android:layout_width="50dp"-->
<!-- android:layout_height="match_parent"-->
<!-- app:ntb_preview_colors="@array/vertical_ntb"/>-->
<!-- <androidx.viewpager.widget.ViewPager-->
<!-- android:id="@+id/vp_vertical_ntb"-->
<!-- android:layout_width="0dp"-->
<!-- android:layout_height="match_parent"-->
<!-- android:layout_weight="1"/>-->
<!-- </LinearLayout>-->
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

@ -10,8 +10,11 @@
android:id="@+id/recycler_view" android:id="@+id/recycler_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@drawable/draw7"
/> />
<!-- 喜欢或者不喜欢-->
<com.example.HomeContent.SmileView <com.example.HomeContent.SmileView
android:id="@+id/smile_view" android:id="@+id/smile_view"
android:layout_width="match_parent" android:layout_width="match_parent"

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" <androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="321dp" android:layout_width="match_parent"
android:layout_height="456dp" android:layout_height="620dp"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
app:cardCornerRadius="5dp" app:cardCornerRadius="5dp"

Loading…
Cancel
Save