搜索详情s

显示页面的

model层

package com.bawai.xiangqing.mvp.model;

import com.bawai.xiangqing.mvp.view.IView;

/**

  • @Author:不要不要

  • @E-mail: 2930851278@qq.com

  • @Date:2019/3/18 19:14

  • @Description:描述信息
    */
    public interface IModel {
    void getData(String sOuname,String page,String count, ModelCallBack modelCallBack);

    interface ModelCallBack{
    void onSuccess(Object data);
    void onFail(Exception e);
    }
    }

//model层实现类

package com.bawai.xiangqing.mvp.model;

import com.bawai.xiangqing.bean.Bean;
import com.bawai.xiangqing.http.OkHttp;

/**

  • @Author:不要不要

  • @E-mail: 2930851278@qq.com

  • @Date:2019/3/18 19:25

  • @Description:描述信息
    */
    public class ModelImpl implements IModel {
    String Base_url=“http://172.17.8.100/small/commodity/v1/findCommodityByKeyword”;
    @Override
    public void getData(String sOuname, String page, String count, ModelCallBack modelCallBack) {
    OkHttp.getInstance().doGet(Base_url+"?"+“keyword=”+sOuname+"&page=1&count=10", Bean.class, new OkHttp.NetCallBack() {
    @Override
    public void LoadSuccess(Object obj) {

             modelCallBack.onSuccess(obj);
         }
    
         @Override
         public void LoadFail() {
    
         }
     });
    

    }
    }

//presenter

package com.bawai.xiangqing.mvp.presenter;

import com.bawai.xiangqing.mvp.view.IView;

/**

  • @Author:不要不要

  • @E-mail: 2930851278@qq.com

  • @Date:2019/3/18 19:14

  • @Description:描述信息
    */
    public interface IPresenter {

    void getPreData(String sOuname,String page,String count);
    void Attch(IView iView);
    void Datch();
    }
    //presenter实现类
    package com.bawai.xiangqing.mvp.presenter;

import com.bawai.xiangqing.MainActivity;
import com.bawai.xiangqing.mvp.model.IModel;
import com.bawai.xiangqing.mvp.model.ModelImpl;
import com.bawai.xiangqing.mvp.view.IView;

import java.lang.ref.SoftReference;

/**

  • @Author:不要不要

  • @E-mail: 2930851278@qq.com

  • @Date:2019/3/18 19:51

  • @Description:描述信息
    */
    public class PresenterImpl implements IPresenter {
    private ModelImpl model;
    MainActivity mainActivity;
    private SoftReference modelSoftReference;

    @Override
    public void getPreData(String sOuname, String page, String count) {
    model.getData(sOuname, page, count, new IModel.ModelCallBack() {
    @Override
    public void onSuccess(Object data) {
    mainActivity.getView(data);
    }

         @Override
         public void onFail(Exception e) {
    
         }
     });
    

    }

    @Override
    public void Attch(IView iView) {
    this.mainActivity= (MainActivity) iView;
    model=new ModelImpl();
    modelSoftReference = new SoftReference(model);
    }

    @Override
    public void Datch() {
    modelSoftReference.clear();
    }
    }
    ~~

//view层

~~
package com.bawai.xiangqing.mvp.view;

/**

  • @Author:不要不要

  • @E-mail: 2930851278@qq.com

  • @Date:2019/3/18 19:14

  • @Description:描述信息
    */
    public interface IView {

    void getView(Object data);
    }

//显示activity

package com.bawai.xiangqing;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.bawai.xiangqing.adapter.Adapter;
import com.bawai.xiangqing.bean.Bean;
import com.bawai.xiangqing.mvp.presenter.PresenterImpl;
import com.bawai.xiangqing.mvp.view.IView;

public class MainActivity extends AppCompatActivity implements IView {

private static final String TAG = "MainActivity";
private RecyclerView rec_list;
private PresenterImpl presenterImpl;
private Button button_cha;
private EditText edi_cha;
String page="1";
String count="10";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    button_cha = findViewById(R.id.button_cha);
    edi_cha = findViewById(R.id.edi_cha);

    rec_list = findViewById(R.id.Rec_list);
    rec_list.setLayoutManager(new GridLayoutManager(this,2));

    presenterImpl = new PresenterImpl();
    presenterImpl.Attch(this);
    presenterImpl.getPreData("电脑",page,count);

    button_cha.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String sOuname = edi_cha.getText().toString();
            if (!sOuname.isEmpty()){
            presenterImpl.getPreData(sOuname,page,count);
            }else{
                Toast.makeText(MainActivity.this,"不能为空",Toast.LENGTH_SHORT).show();
            }
        }
    });
}


@Override
public void getView(Object data) {
                Bean bean= (Bean) data;
        Adapter adapter=new Adapter(MainActivity.this,bean);
        rec_list.setAdapter(adapter);
        adapter.setRectlistener(new Adapter.Rectlistener() {
        @Override
        public void Callback(int i, String id) {
            Intent intent = new Intent(MainActivity.this, XiangActivity.class);
            intent.putExtra("id",id);
            startActivity(intent);
        }
    });
}

}
//显示的适配器
package com.bawai.xiangqing.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bawai.xiangqing.R;
import com.bawai.xiangqing.bean.Bean;
import com.bumptech.glide.Glide;

/**

  • @Author:不要不要

  • @E-mail: 2930851278@qq.com

  • @Date:2019/3/18 20:01

  • @Description:描述信息
    */
    public class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder> {
    Context context;
    Bean bean;

    public Adapter(Context context, Bean bean) {
    this.context = context;
    this.bean = bean;
    }

    @NonNull
    @Override
    public Adapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    View view = LayoutInflater.from(context).inflate(R.layout.items, viewGroup, false);

     return new ViewHolder(view);
    

    }

    @Override
    public void onBindViewHolder(@NonNull Adapter.ViewHolder viewHolder, int i) {

     Glide.with(context).load(bean.getResult().get(i).getMasterPic()).into(viewHolder.image111);
        viewHolder.text.setText(bean.getResult().get(i).getCommodityName());
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                rectlistener.Callback(v.getId(),bean.getResult().get(i).getCommodityId());
            }
        });
    

    }

    @Override
    public int getItemCount() {
    return bean.getResult().size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

     private final TextView text;
     private final ImageView image111;
    
     public ViewHolder(@NonNull View itemView) {
         super(itemView);
         text = itemView.findViewById(R.id.text111);
         image111 = itemView.findViewById(R.id.image111);
     }
    

    }

      private   Rectlistener rectlistener;
    

    public void setRectlistener(Rectlistener rectlistener){
    this.rectlistener=rectlistener;
    }
    public interface Rectlistener{
    void Callback(int i,String id);
    }
    }

//详情页面

//model

package com.bawai.xiangqing.mvp.model;

/**

  • @Author:不要不要
  • @E-mail: 2930851278@qq.com
  • @Date:2019/3/19 14:34
  • @Description:描述信息
    */
    public interface IShowmodel {

void requwe(String page,CallBack callBack);

  interface  CallBack{

      void onSuccon(Object data);
      void onFail();
}

}

model实现类

package com.bawai.xiangqing.mvp.model;

import com.bawai.xiangqing.bean.JsonBean;
import com.bawai.xiangqing.http.OkHttp;

/**

  • @Author:不要不要

  • @E-mail: 2930851278@qq.com

  • @Date:2019/3/19 14:39

  • @Description:描述信息
    */
    public class Showmodelmpl implements IShowmodel {

    @Override
    public void requwe(String page, CallBack callBack) {
    String url = “http://172.17.8.100/small/commodity/v1/findCommodityDetailsById?commodityId=” + page + “”;

     OkHttp.getInstance().doGet(url, JsonBean.class, new OkHttp.NetCallBack() {
         @Override
         public void LoadSuccess(Object obj) {
             callBack.onSuccon(obj);
         }
    
         @Override
         public void LoadFail() {
    
         }
     });
    

    }
    }

//presenter

package com.bawai.xiangqing.mvp.presenter;

import com.bawai.xiangqing.mvp.view.IShowview;

/**

  • @Author:不要不要
  • @E-mail: 2930851278@qq.com
  • @Date:2019/3/19 14:35
  • @Description:描述信息
    */
    public interface IShowpresenter {
    void getSur(String page);
    void onAttch(IShowview iShowview);
    void onDatch();
    }

//presneter实现类

package com.bawai.xiangqing.mvp.presenter;

import com.bawai.xiangqing.XiangActivity;
import com.bawai.xiangqing.mvp.model.IShowmodel;
import com.bawai.xiangqing.mvp.model.Showmodelmpl;
import com.bawai.xiangqing.mvp.view.IShowview;

import java.lang.ref.SoftReference;

/**

  • @Author:不要不要

  • @E-mail: 2930851278@qq.com

  • @Date:2019/3/19 14:48

  • @Description:描述信息
    */
    public class Showpresenter implements IShowpresenter {
    private Showmodelmpl showmodelmpl;
    XiangActivity xiangActivity;
    IShowview showview;
    private SoftReference saaa;

    @Override
    public void getSur(String page) {
    showmodelmpl.requwe(page, new IShowmodel.CallBack() {
    @Override
    public void onSuccon(Object data) {
    xiangActivity.getRess(data);
    }
    @Override
    public void onFail() {
    }
    });
    }
    @Override
    public void onAttch(IShowview iShowview) {
    this.xiangActivity= (XiangActivity) iShowview;
    showmodelmpl=new Showmodelmpl();
    saaa = new SoftReference<>(showmodelmpl);

    }

    @Override
    public void onDatch() {
    saaa.clear();
    }
    }

//view层

package com.bawai.xiangqing.mvp.view;

/**

  • @Author:不要不要

  • @E-mail: 2930851278@qq.com

  • @Date:2019/3/19 14:35

  • @Description:描述信息
    */
    public interface IShowview {

    void getRess(Object data);
    }

//详情activity

package com.bawai.xiangqing;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.bawai.xiangqing.bean.JsonBean;
import com.bawai.xiangqing.mvp.presenter.Showpresenter;
import com.bawai.xiangqing.mvp.view.IShowview;
import com.bumptech.glide.Glide;

import java.util.ArrayList;

public class XiangActivity extends AppCompatActivity implements IShowview {

private TextView xiangtext1;
private TextView xiangtext2;
private TextView xiangtext3;
private ViewPager page_view;
private WebView web_view;

private Showpresenter showpresenter1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_xiang);
    init();
    Intent intent = getIntent();
    String id1 = intent.getStringExtra("id");
    //int id = intent.getExtras().getInt("id");
    showpresenter1 = new Showpresenter();
    showpresenter1.onAttch(this);
    showpresenter1 .getSur(id1);
}
private void init() {
    xiangtext1 = findViewById(R.id.xiangtext1);
    xiangtext2 = findViewById(R.id.xiangtext2);
    xiangtext3 = findViewById(R.id.xiangtext3);
    page_view = findViewById(R.id.page_view);
    web_view = findViewById(R.id.web_view);
}
@Override
public void getRess(Object data) {
    JsonBean jsonBean = (JsonBean) data;
    String details = jsonBean.getResult().getDetails();
    web_view.loadData(details,"text/html","UTF-8");
    web_view.setWebChromeClient(new WebChromeClient());
    WebSettings settings = web_view.getSettings();
    settings.setJavaScriptEnabled(true);
    xiangtext1.setText(jsonBean.getResult().getCategoryName());
    xiangtext2.setText(jsonBean.getResult().getCommodityName());
    xiangtext3.setText(jsonBean.getResult().getPrice());
    String picture = jsonBean.getResult().getPicture();
    String[] split = picture.split(",");
    ArrayList<ImageView> imageViews=new ArrayList<>();

    for (int i=0;i<split.length;i++){

        String s=split[i];
        ImageView imageView = new ImageView(XiangActivity.this);
        Glide.with(XiangActivity.this).load(s).into(imageView);
        imageViews.add(imageView);
    }

    page_view.setAdapter(new PagerAdapter() {
        @Override
        public int getCount() {
            return imageViews.size();
        }

        @Override
        public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
            return view==o;
        }

        @NonNull
        @Override
        public Object instantiateItem(@NonNull ViewGroup container, int position) {
            ImageView imageView = imageViews.get(position);
            container.addView(imageView);
            return imageView;
        }

        @Override
        public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
            container.removeView((View) object);
        }
    });
}

@Override
protected void onDestroy() {
    super.onDestroy();
    showpresenter1.onDatch();
}

}

//搜索布局‘’

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="#fff"
    android:gravity="center"
    android:orientation="horizontal">
    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:src="@drawable/ic_launcher_background"/>
    <EditText
        android:id="@+id/edi_cha"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:hint="女士卫衣"
        android:text="手机"
        android:singleLine="true"
        android:layout_weight="7"/>
    <Button
        android:id="@+id/button_cha"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="2"
        android:gravity="center"
        android:textSize="20sp"
        android:text="搜索"/>
</LinearLayout>

//显示页面布局

<?xml version="1.0" encoding="utf-8"?>

<include
    android:id="@+id/sou"
    layout="@layout/sou_layout"
    />
<android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/Rec_list"/>

//详情页面布局

<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.view.ViewPager
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:id="@+id/page_view"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/xiangtext1"
    android:textColor="@color/colorAccent"
    android:text="12345t"/>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/xiangtext2"
    android:textColor="@color/colorPrimary"
    android:text="12345t"/>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/xiangtext3"
    android:textColor="@color/colorPrimaryDark"
    android:text="12345t"/>
<WebView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/web_view"
    />
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值