This commit is contained in:
ScorpioMiku
2018-09-03 17:41:34 +08:00
parent e50c80694f
commit c5157f9a02
12 changed files with 353 additions and 42 deletions

View File

@@ -55,8 +55,6 @@ dependencies {
implementation project(':todaystepcounterlib')
//打分ui
compile 'com.github.CB-ysx:CBRatingBar:3.0.1'
// //蛛网
// implementation 'me.panpf:spider-web-score-view:1.0.1'
//折线
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
//searchview
@@ -66,4 +64,6 @@ dependencies {
//recycler and card
implementation 'com.android.support:recyclerview-v7:26.1.0'
implementation 'com.android.support:cardview-v7:26.1.0'
//混合式recyclerview
compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.30'
}

View File

@@ -8,7 +8,7 @@ import android.support.v4.app.FragmentPagerAdapter;
import com.example.ninefourone.nutritionmaster.R;
import com.example.ninefourone.nutritionmaster.modules.viewpagerfragments.customization.CustomizationFragment;
import com.example.ninefourone.nutritionmaster.modules.viewpagerfragments.bodyinformation.BodyInformationFragment;
import com.example.ninefourone.nutritionmaster.modules.viewpagerfragments.page3.Page3;
import com.example.ninefourone.nutritionmaster.modules.viewpagerfragments.recommend.RecommendFragment;
/**
@@ -36,7 +36,7 @@ public class HomePagerAdapter extends FragmentPagerAdapter {
fragments[position] = BodyInformationFragment.getInstance();
break;
case 2:
fragments[position] = Page3.getInstance();
fragments[position] = RecommendFragment.getInstance();
break;
default:
break;

View File

@@ -0,0 +1,46 @@
package com.example.ninefourone.nutritionmaster.adapter;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.ninefourone.nutritionmaster.R;
import com.example.ninefourone.nutritionmaster.bean.RecommendFood;
import java.util.List;
/**
* Created by ScorpioMiku on 2018/9/3.
*/
public class RecommendAdapter extends BaseMultiItemQuickAdapter<RecommendFood, BaseViewHolder> {
/**
* Same as QuickAdapter#QuickAdapter(Context,int) but with
* some initialization data.
*
* @param data A new list is created out of this one to avoid mutable list
*/
public RecommendAdapter(List<RecommendFood> data) {
super(data);
addItemType(RecommendFood.TYPE_BIG, R.layout.recommend_item_big);
addItemType(RecommendFood.TYPE_DETAIL, R.layout.recommend_item_detail);
addItemType(RecommendFood.TYPE_MIDDLE, R.layout.recommend_item_middle);
}
@Override
protected void convert(BaseViewHolder helper, RecommendFood item) {
switch (item.getItemType()) {
case RecommendFood.TYPE_BIG:
helper.setImageResource(R.id.recommend_item_imageview, R.drawable.food_test);
helper.setText(R.id.recommend_item_title, "红烧肉");
break;
case RecommendFood.TYPE_DETAIL:
helper.setImageResource(R.id.recommend_item_imageview, R.drawable.food_test);
helper.setText(R.id.recommend_item_title, item.getTitle());
helper.setText(R.id.recommend_item_description, item.getDescription());
break;
case RecommendFood.TYPE_MIDDLE:
helper.setImageResource(R.id.recommend_item_imageview, R.drawable.food_test);
helper.setText(R.id.recommend_item_title, "红烧");
break;
}
}
}

View File

@@ -0,0 +1,59 @@
package com.example.ninefourone.nutritionmaster.bean;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.orhanobut.logger.Logger;
/**
* Created by ScorpioMiku on 2018/9/3.
*/
public class RecommendFood implements MultiItemEntity {
public static final int TYPE_BIG = 0;
public static final int TYPE_MIDDLE = 1;
public static final int TYPE_DETAIL = 2;
private int picture;
private String title;
private String description;
private int type;
public RecommendFood(int picture, String title, String description, int type) {
this.picture = picture;
this.title = title;
this.description = description;
this.type = type;
if (type > 2) {
Logger.e("混合recycler type不对");
}
}
public int getPicture() {
return picture;
}
public void setPicture(int picture) {
this.picture = picture;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public int getItemType() {
return type;
}
}

View File

@@ -1,27 +0,0 @@
package com.example.ninefourone.nutritionmaster.modules.viewpagerfragments.page3;
import android.os.Bundle;
import com.example.ninefourone.nutritionmaster.R;
import com.example.ninefourone.nutritionmaster.base.BaseFragment;
/**
* Created by ScorpioMiku on 2018/8/26.
*/
public class Page3 extends BaseFragment {
@Override
public int getLayoutResId() {
return R.layout.page_3;
}
@Override
public void initView(Bundle state) {
}
public static BaseFragment getInstance() {
return new Page3();
}
}

View File

@@ -0,0 +1,85 @@
package com.example.ninefourone.nutritionmaster.modules.viewpagerfragments.recommend;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.ninefourone.nutritionmaster.R;
import com.example.ninefourone.nutritionmaster.adapter.RecommendAdapter;
import com.example.ninefourone.nutritionmaster.base.BaseFragment;
import com.example.ninefourone.nutritionmaster.bean.RecommendFood;
import java.util.ArrayList;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
/**
* Created by ScorpioMiku on 2018/8/26.
*/
public class RecommendFragment extends BaseFragment {
@BindView(R.id.recycler_view)
RecyclerView recyclerView;
Unbinder unbinder;
private RecommendAdapter adapter;
private ArrayList<RecommendFood> datas = new ArrayList<>();
@Override
public int getLayoutResId() {
return R.layout.normal_recommend_fragment_layout;
}
@Override
public void initView(Bundle state) {
loadData();
initRecyclerView();
}
public static BaseFragment getInstance() {
return new RecommendFragment();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// TODO: inflate a fragment view
View rootView = super.onCreateView(inflater, container, savedInstanceState);
unbinder = ButterKnife.bind(this, rootView);
return rootView;
}
@Override
public void onDestroyView() {
super.onDestroyView();
unbinder.unbind();
}
/**
* 初始化recyclerview
*/
@Override
protected void initRecyclerView() {
adapter = new RecommendAdapter(datas);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new GridLayoutManager(getContext(), 2));
}
/**
* 加载数据
*/
@Override
protected void loadData() {
super.loadData();
for (int i = 0; i < 20; i++) {
RecommendFood recommendFood = new RecommendFood(1, "烧肉", "好吃", i % 3);
datas.add(recommendFood);
}
}
}

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
</LinearLayout>

View File

@@ -1,11 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorControlNormal">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="page3" />
</android.support.constraint.ConstraintLayout>

View File

@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="@dimen/recommend_item_big_height"
android:layout_margin="@dimen/recommend_margin"
app:cardCornerRadius="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/recommend_item_imageview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:scaleType="centerCrop"
tools:src="@drawable/food_test" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/recommend_item_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="20sp"
android:textStyle="bold"
tools:text="红烧肉" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>

View File

@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="@dimen/recommend_item_default_hight"
android:layout_margin="@dimen/recommend_margin"
android:orientation="horizontal">
<android.support.v7.widget.CardView
android:layout_width="@dimen/recommend_item_default_hight"
android:layout_height="@dimen/recommend_item_default_hight"
android:layout_marginRight="5dp"
app:cardCornerRadius="20dp">
<ImageView
android:id="@+id/recommend_item_imageview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
tools:src="@drawable/food_test" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
app:cardCornerRadius="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="15dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="15dp">
<TextView
android:id="@+id/recommend_item_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
tools:text="红烧肉" />
<TextView
android:id="@+id/recommend_item_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:textSize="10sp"
tools:text="红烧肉是最美味的菜了!超级好吃!" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>

View File

@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="170dp"
android:layout_height="@dimen/recommend_item_default_hight"
android:layout_margin="@dimen/recommend_margin"
android:layout_weight="1"
app:cardCornerRadius="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/recommend_item_imageview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:scaleType="centerCrop"
tools:src="@drawable/food_test" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/recommend_item_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="14sp"
android:textStyle="bold"
tools:text="红烧肉" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>

View File

@@ -20,5 +20,9 @@
<dimen name="icon_size">20dp</dimen>
<dimen name="recommend_item_default_hight">130dp</dimen>
<dimen name="recommend_item_big_height">250dp</dimen>
<dimen name="recommend_margin">10dp</dimen>
</resources>