wang
This commit is contained in:
@@ -61,6 +61,7 @@
|
||||
<activity android:name=".modules.addinformation.AddInformationActivity" />
|
||||
<activity android:name=".modules.classifyresult.DishResultActivity" />
|
||||
<activity android:name=".modules.classifyresult.MaterialResultActivity" />
|
||||
<activity android:name=".modules.historysearch.HistoryActivity"></activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.example.ninefourone.nutritionmaster.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
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.bean.History;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/11/7.
|
||||
*/
|
||||
|
||||
public class HistoryAdapter extends RecyclerView.Adapter<HistoryHolder> {
|
||||
private Context context;
|
||||
private List<History> mList;
|
||||
|
||||
public HistoryAdapter(Context context, List mList) {
|
||||
this.context = context;
|
||||
this.mList = mList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HistoryHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.dish_item, parent, false);
|
||||
HistoryHolder historyHolder = new HistoryHolder(view);
|
||||
return historyHolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(HistoryHolder holder, int position) {
|
||||
holder.bindView(mList.get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mList.size();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.example.ninefourone.nutritionmaster.adapter;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.bean.History;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/11/7.
|
||||
*/
|
||||
|
||||
public class HistoryHolder extends RecyclerView.ViewHolder {
|
||||
@BindView(R.id.image)
|
||||
ImageView image;
|
||||
@BindView(R.id.name)
|
||||
TextView name;
|
||||
@BindView(R.id.describle)
|
||||
TextView describle;
|
||||
|
||||
public HistoryHolder(View itemView) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
|
||||
public void bindView(History history) {
|
||||
Glide.with(itemView.getContext()).load(history.getMenu().getImage_url()).into(image);
|
||||
name.setText(history.getMenu().getName());
|
||||
}
|
||||
}
|
||||
@@ -28,9 +28,11 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||
this.user = NutritionMaster.user;
|
||||
setContentView(getLayoutId());
|
||||
unbinder = ButterKnife.bind(this);
|
||||
initViews(savedInstanceState);
|
||||
webUtil = WebUtil.getInstance();
|
||||
|
||||
initViews(savedInstanceState);
|
||||
initToolBar();
|
||||
|
||||
}
|
||||
|
||||
public WebUtil getWebUtil() {
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.example.ninefourone.nutritionmaster.bean.Illness;
|
||||
import com.example.ninefourone.nutritionmaster.camera.ClassifierCamera;
|
||||
import com.example.ninefourone.nutritionmaster.modules.addinformation.AddInformationActivity;
|
||||
import com.example.ninefourone.nutritionmaster.modules.addinformation.AddPhysiqueActivity;
|
||||
import com.example.ninefourone.nutritionmaster.modules.historysearch.HistoryActivity;
|
||||
import com.example.ninefourone.nutritionmaster.modules.information.InformationActivity;
|
||||
import com.example.ninefourone.nutritionmaster.ui.NoScrollViewPager;
|
||||
import com.example.ninefourone.nutritionmaster.utils.CalculateUtils;
|
||||
@@ -189,7 +190,7 @@ public class MainActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
public void initToolBar() {
|
||||
toolBarNickname.setText(user.getUsername());
|
||||
toolBarNickname.setText("NutritionMaster");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -219,6 +220,24 @@ public class MainActivity extends BaseActivity {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 点击事件
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.id_action_search:
|
||||
return true;
|
||||
case R.id.id_action_record:
|
||||
Intent intent = new Intent(MainActivity.this, HistoryActivity.class);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
// Logger.d("prepareMenu");
|
||||
@@ -228,10 +247,6 @@ public class MainActivity extends BaseActivity {
|
||||
|
||||
//mDrawer.openMenu();
|
||||
|
||||
/**
|
||||
* 点击事件
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 初始化蛛网图
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.example.ninefourone.nutritionmaster.modules.historysearch;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.adapter.HistoryAdapter;
|
||||
import com.example.ninefourone.nutritionmaster.base.BaseActivity;
|
||||
import com.example.ninefourone.nutritionmaster.bean.History;
|
||||
import com.example.ninefourone.nutritionmaster.utils.WebUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class HistoryActivity extends BaseActivity {
|
||||
|
||||
|
||||
@BindView(R.id.recycler_view)
|
||||
RecyclerView recyclerView;
|
||||
private ArrayList<History> mList = new ArrayList<>();
|
||||
private HistoryAdapter adapter;
|
||||
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_history;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initViews(Bundle savedInstanceState) {
|
||||
adapter = new HistoryAdapter(this, mList);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
recyclerView.setAdapter(adapter);
|
||||
recyclerView.setNestedScrollingEnabled(false);
|
||||
loadData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initToolBar() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPointerCaptureChanged(boolean hasCapture) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadData() {
|
||||
super.loadData();
|
||||
Logger.d(user.getUsername());
|
||||
getWebUtil().getEatenHistory(user.getUsername(), new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
String json = response.body().string();
|
||||
History[] histories = new Gson().fromJson(json, History[].class);
|
||||
Logger.d(Arrays.toString(histories));
|
||||
mList.clear();
|
||||
for (History temp: histories) {
|
||||
|
||||
mList.add(temp);
|
||||
}
|
||||
|
||||
recyclerView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// TODO: add setContentView(...) invocation
|
||||
ButterKnife.bind(this);
|
||||
}
|
||||
}
|
||||
16
app/src/main/res/layout/activity_history.xml
Normal file
16
app/src/main/res/layout/activity_history.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<?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="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context="com.example.ninefourone.nutritionmaster.modules.historysearch.HistoryActivity">
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
</android.support.v7.widget.RecyclerView>
|
||||
</LinearLayout>
|
||||
Reference in New Issue
Block a user