使用Rxjava和okhttp3、butterknife和greendao实现搜索、列表和详情跳转购物车

使用的依赖和权限

apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao' // apply plugin

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.bwie.test.mymoni_yuekao"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    implementation 'com.github.bumptech.glide:glide:4.5.0'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.5.1'
    implementation 'org.greenrobot:greendao:3.2.2'
    implementation 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
    implementation 'com.facebook.fresco:fresco:1.8.1'
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
    implementation 'io.reactivex.rxjava2:rxjava:2.1.12'
    implementation 'com.jakewharton.rxbinding2:rxbinding:2.1.1'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'
    implementation 'com.hyman:flowlayout-lib:1.1.2'
    implementation 'com.jcodecraeer:xrecyclerview:1.3.2'
    implementation 'org.greenrobot:eventbus:3.1.1'
}
greendao {
    schemaVersion 1//数据库版本号
    daoPackage 'com.bwie.test.mymoni_yuekao.dao'//设置DaoMaster、DaoSession、Dao包名
    targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录
    //targetGenDirTest:设置生成单元测试目录
    //generateTests:设置自动生成单元测试用例
}
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />

build.gradle

buildscript {
    repositories {
        google()
        jcenter()
        mavenCentral() // add repository
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2' // add plugin
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

activity_main

<?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:fitsSystemWindows="true"
    xmlns:zhy="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:windowSoftInputMode="stateHidden"
    tools:context=".MainActivity">

    <RelativeLayout
        android:id="@+id/search_main"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:background="@color/theme_lanse"
        android:orientation="horizontal"
        android:paddingTop="5dp"
        android:gravity="center_vertical"
        android:paddingBottom="5dp">

        <Button
            android:id="@+id/search_ok"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="搜索"
            android:layout_alignParentTop="true"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true" />

        <android.support.v7.widget.SearchView
            android:id="@+id/searchview"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:iconifiedByDefault="false"
            android:queryHint="请输入搜索内容"
            android:background="@drawable/shape_search"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true">
        </android.support.v7.widget.SearchView>
    </RelativeLayout>

    <com.bwie.test.custom.MyScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:focusable="true"
        android:scrollbars="none"
        android:fillViewport="true"
        android:focusableInTouchMode="true"
        android:descendantFocusability="beforeDescendants" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="15dp"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:text="热门搜索"
                android:textSize="18sp" />

            <View
                style="@style/gray_height_1dp"
                android:layout_marginTop="3dp" />

            <com.zhy.view.flowlayout.TagFlowLayout
                android:id="@+id/search_greendao_flowlayout"
                zhy:max_select="-1"
                android:layout_marginTop="15dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
            </com.zhy.view.flowlayout.TagFlowLayout>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:text="搜索历史"
                android:textSize="18dp" />

            <View
                style="@style/gray_height_1dp"
                android:layout_marginTop="3dp" />

            <RelativeLayout
                android:id="@+id/search_greendao_rl"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:background="#00000000"
                android:visibility="gone">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="20dp"
                    android:layout_centerHorizontal="true"
                    android:text="无搜索记录" />

            </RelativeLayout>

            <ListView
                android:id="@+id/search_greendao_lv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                android:layout_weight="1"
                android:scrollbars="none"
                android:divider="@null"
                android:dividerHeight="5dp"
                android:focusable="false" />

            <Button
                android:id="@+id/search_greendao_delete"
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:layout_gravity="center_horizontal"
                android:layout_marginBottom="5dp"
                android:background="@drawable/button_shape"
                android:text="清空搜索历史"
                android:textColor="@color/white" />
        </LinearLayout>
    </com.bwie.test.custom.MyScrollView>

</LinearLayout>

activity_cart

<?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=".CartActivity">

    <LinearLayout
        android:id="@+id/top_bar"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:orientation="vertical" >
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:orientation="vertical" >
            <!--android:src="@mipmap/fanhui1"-->
            <ImageView
                android:id="@+id/back"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_alignParentLeft="true"
                android:layout_gravity="center_vertical"
                android:layout_marginTop="10dp" />
            <TextView
                android:id="@+id/title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:minHeight="48dp"
                android:text="购物车"
                android:textColor="#1a1a1a"
                android:textSize="16sp" />

            <TextView
                android:id="@+id/subtitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginRight="20dp"
                android:gravity="center"
                android:minHeight="48dp"
                android:text="编辑"
                android:textColor="#1a1a1a"
                android:textSize="14sp"
                android:visibility="visible" />
        </RelativeLayout>
    </LinearLayout>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <LinearLayout
            android:id="@+id/ll_cart"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <ExpandableListView
                android:id="@+id/exListView"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:childIndicator="@null"
                android:groupIndicator="@null" >
            </ExpandableListView>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:gravity="center_vertical"
                android:orientation="horizontal" >

                <CheckBox
                    android:id="@+id/all_chekbox"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:layout_gravity="center_vertical"
                    android:layout_marginRight="4dp"
                    android:gravity="center"
                    android:focusable="false"
                    android:layout_marginLeft="10dp"
                    android:text="全选" />

                <LinearLayout
                    android:id="@+id/ll_info"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="4">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical"
                        android:layout_marginRight="20dp"
                        android:layout_weight="1">
                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:orientation="horizontal"
                            android:gravity="right">
                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginLeft="5dp"
                                android:text="合计:"
                                android:textSize="18sp"
                                android:textStyle="bold" />

                            <TextView
                                android:id="@+id/tv_total_price"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text="¥0.00"
                                android:textColor="#000"
                                android:textSize="16sp"
                                android:textStyle="bold" />
                        </LinearLayout>

                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="不含运费"
                            android:gravity="right"
                            android:textColor="#000"
                            android:textSize="16sp"
                            android:textStyle="bold" />
                    </LinearLayout>

                    <TextView
                        android:id="@+id/tv_go_to_pay"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="3"
                        android:background="#f00"
                        android:clickable="true"
                        android:gravity="center"
                        android:text="结算(0)"
                        android:textColor="#FAFAFA" />

                </LinearLayout>
                <LinearLayout
                    android:id="@+id/ll_shar"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="4"
                    android:orientation="horizontal"
                    android:visibility="gone">

                    <TextView
                        android:id="@+id/tv_share"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:gravity="center"
                        android:layout_weight="1"
                        android:layout_marginLeft="5dp"
                        android:text="分享宝贝"
                        android:background="#ef930a"
                        android:textColor="#fff"
                        android:textSize="16sp"
                        android:layout_marginRight="5dp"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/tv_save"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="移到收藏夹"
                        android:background="#ef930a"
                        android:textColor="#fff"
                        android:layout_marginRight="5dp"
                        android:textSize="16sp"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/tv_delete"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:background="#f00"
                        android:clickable="true"
                        android:gravity="center"
                        android:text="删除"
                        android:textColor="#FAFAFA" />
                </LinearLayout>

            </LinearLayout>
        </LinearLayout>
    </FrameLayout>

</LinearLayout>

activity_ding_dan

<?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=".DingDanActivity">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="订单列表"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true" />

        <!--android:src="@drawable/lv_icon"-->
        <ImageView
            android:id="@+id/img_duo"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />
    </RelativeLayout>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="#000"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/textview1"
            android:gravity="center"
            android:text="待支付"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_width="1dp"
            android:layout_height="wrap_content"
            android:background="#000"/>

        <TextView
            android:id="@+id/textview2"
            android:gravity="center"
            android:text="已支付"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_width="1dp"
            android:layout_height="wrap_content"
            android:background="#000"/>

        <TextView
            android:id="@+id/textview3"
            android:gravity="center"
            android:text="已取消"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="#000"/>

    <com.jcodecraeer.xrecyclerview.XRecyclerView
        android:id="@+id/rv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </com.jcodecraeer.xrecyclerview.XRecyclerView>

</LinearLayout>

activity_show

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    tools:context=".ShowActivity">

    <com.jcodecraeer.xrecyclerview.XRecyclerView
        android:id="@+id/xrecyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </com.jcodecraeer.xrecyclerview.XRecyclerView>

</RelativeLayout>

activity_shows

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fresco="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ShowsActivity">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:background="#cce68b13">
            <!--android:src="@mipmap/fanhui1"-->
            <ImageView
                android:id="@+id/regist_back"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_centerVertical="true" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="商品详情"
                android:textSize="20sp"
                android:textColor="#fff"
                android:layout_centerInParent="true" />
        </RelativeLayout>

        <com.facebook.drawee.view.SimpleDraweeView
            android:id="@+id/shows_img"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            fresco:placeholderImage="@mipmap/ic_launcher" />
        <TextView
            android:id="@+id/shows_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="20sp"
            android:text="标题" />

        <TextView
            android:id="@+id/shows_price"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="20sp"
            android:text="价格"
            android:layout_marginTop="10dp"
            android:textColor="#ddd67813" />
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true">
        <Button
            android:id="@+id/cart"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="购物车"
            android:background="#e59114" />
        <Button
            android:id="@+id/add_cart"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="加入购物车"
            android:background="#cd1b18" />

    </LinearLayout>
</RelativeLayout>

item_main

<?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">
    <RelativeLayout
        android:layout_marginTop="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <RelativeLayout
            android:id="@+id/rl1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/tv_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="dwqeeqwq" />

            <TextView
                android:id="@+id/tv_wen"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true"
                android:text="待支付" />
        </RelativeLayout>

        <TextView
            android:id="@+id/tv_price"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/rl1"
            android:textColor="#F00"
            android:text="dwqeeqwq" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/tv_price">

            <TextView
                android:id="@+id/tv_time"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="wdqdwqd"
                android:layout_centerVertical="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true"
                android:id="@+id/btn"
                android:text="查看订单" />
        </RelativeLayout>
    </RelativeLayout>
</LinearLayout>

item_shopcart_group

<?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">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/white" >

        <CheckBox
            android:id="@+id/determine_chekbox"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true" />

        <TextView
            android:id="@+id/tv_source_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginBottom="10dp"
            android:layout_marginTop="10dp"
            android:layout_toRightOf="@id/determine_chekbox"
            android:background="#ffffffff"
            android:drawablePadding="10dp"
            android:text="第八号当铺"
            android:textColor="#000"
            android:gravity="center"
            android:textSize="18dp" />

        <TextView
            android:id="@+id/tv_store_edtor"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="14dp"
            android:textSize="18dp"
            android:background="@null"
            android:text="编辑"/>
    </RelativeLayout>
</LinearLayout>

item_shopcart_product

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent"
    android:orientation="vertical"  >
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#CCCCCC" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <CheckBox
            android:id="@+id/check_box"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="4dp"
            android:checkMark="?android:attr/listChoiceIndicatorMultiple"
            android:gravity="center"
            android:minHeight="64dp"
            android:minWidth="32dp"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:visibility="visible" />

        <com.facebook.drawee.view.SimpleDraweeView
            android:id="@+id/iv_adapter_list_pic"
            android:layout_width="85dp"
            android:layout_height="85dp"
            android:layout_marginBottom="15dp"
            android:layout_marginTop="13dp"
            android:scaleType="centerCrop" />

        <RelativeLayout
            android:id="@+id/rl_no_edtor"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginLeft="13dp">

            <TextView
                android:id="@+id/tv_intro"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="10dp"
                android:layout_marginTop="20dp"
                android:ellipsize="end"
                android:maxLines="2"
                android:text="第八号店铺"
                android:textColor="#000"
                android:singleLine="true" />
            <TextView
                android:id="@+id/tv_color_size"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="颜色:黑色;尺码:29"
                android:layout_marginTop="5dp"
                android:textColor="#000"
                android:layout_centerVertical="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true" />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_marginBottom="20dp"
                android:layout_alignParentStart="true">

                <TextView
                    android:id="@+id/tv_price"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:singleLine="true"
                    android:text="¥ 308.00"
                    android:textColor="#000"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/tv_discount_price"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="10dp"
                    android:layout_toRightOf="@+id/tv_price"
                    android:text="" />
                <TextView
                    android:id="@+id/tv_buy_num"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginRight="20dp"
                    android:layout_alignParentRight="true"
                    android:text="X 1"
                    android:textColor="#000" />
            </RelativeLayout>
        </RelativeLayout>

        <LinearLayout
            android:id="@+id/ll_edtor"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginLeft="13dp"
            android:visibility="gone"
            android:orientation="horizontal">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical">

                <RelativeLayout
                    android:id="@+id/ll_change_num"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:layout_marginTop="20dp"
                    android:orientation="horizontal">
                    <com.bwie.test.custom.AddDeleteView
                        android:id="@+id/adv_main"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        app:left_text="-"
                        app:middle_text="3"
                        app:right_text="+">
                    </com.bwie.test.custom.AddDeleteView>

                </RelativeLayout>

                <TextView
                    android:id="@+id/tv_colorsize"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:gravity="center"
                    android:text="颜色:黑色;尺码:29"
                    android:layout_gravity="left"
                    android:textColor="#000"/>
            </LinearLayout>

            <TextView
                android:id="@+id/tv_goods_delete"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="3"
                android:text="删除"
                android:background="#ecb74c"
                android:gravity="center"
                android:layout_gravity="center"
                android:textColor="#fff"/>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

layout_add_delete

<?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">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">
        <Button
            android:id="@+id/but_delete"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="14dp"
            android:text="一" />
        <TextView
            android:id="@+id/et_number"
            android:layout_width="40dp"
            android:inputType="number"
            android:layout_height="wrap_content"
            android:gravity="center" />
        <Button
            android:id="@+id/but_add"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="14dp"
            android:text="+" />
    </LinearLayout>
</LinearLayout>

search_page

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:zhy="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="15dp"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:text="热门搜索"
            android:textSize="18sp"/>
        <View
            style="@style/gray_height_1dp"
            android:layout_marginTop="3dp"/>

        <com.zhy.view.flowlayout.TagFlowLayout
            android:layout_marginTop="15dp"
            android:id="@+id/search_page_flowlayout"
            zhy:max_select="-1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:text="搜索历史"
            android:textSize="18dp"/>
        <View
            style="@style/gray_height_1dp"
            android:layout_marginTop="3dp"/>
            <ListView
                android:id="@+id/search_page_lv"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_marginTop="15dp"
                android:layout_weight="1"
                android:divider="@null"
                android:dividerHeight="5dp"/>

        <RelativeLayout
            android:id="@+id/search_page_rl"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="#00000000"
            android:visibility="gone">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="20dp"
                android:layout_centerHorizontal="true"
                android:text="无搜索记录"/>
        </RelativeLayout>

        <Button
            android:id="@+id/search_page_delete"
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:text="清空搜索历史"
            android:textColor="@color/white"
            android:background="@drawable/button_shape"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="5dp"
            android:layout_gravity="center_horizontal" />
    </LinearLayout>
</LinearLayout>

search_page_flowlayout_tv

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/flowlayout_tv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    android:background="@drawable/flowlayout_shap"
    android:text="Helloworld"
    android:textColor="@color/black">
</TextView>

show_item

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    xmlns:fresco="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent"
    android:orientation="vertical"  >
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="120dp">

        <com.facebook.drawee.view.SimpleDraweeView
            android:id="@+id/item_img"
            android:layout_width="120dp"
            android:layout_height="120dp"
            fresco:placeholderImage="@mipmap/ic_launcher" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <TextView
                android:id="@+id/item_price"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="价格"
                android:textSize="20sp" />
            <TextView
                android:id="@+id/item_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="商品"
                android:textSize="20sp"
                android:layout_marginTop="5dp" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

drawable文件夹下bg_black_shape

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@color/gray"/>
    <corners
        android:topLeftRadius="90dp"
        android:topRightRadius="90dp"
        android:bottomRightRadius="90dp"
        android:bottomLeftRadius="90dp"/>

    <padding
        android:top="3dp"
        android:bottom="3dp"
        android:left="3dp"
        android:right="3dp"/>
</shape>

button_shape

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="@color/theme" />
    <corners
        android:topLeftRadius="100dp"
        android:topRightRadius="6dp"
        android:bottomRightRadius="6dp"
        android:bottomLeftRadius="6dp"/>

    <padding
        android:left="6dp"
        android:right="6dp"/>
</shape>

flowlayout_shap

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/theme"
        android:drawable="@drawable/button_shape"
        android:state_checked="true"/>
    <item android:drawable="@drawable/bg_black_shape"/>
</selector>

shape_search

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <!-- 表示shape的四个角的角度。只适用于矩形shape,这里的角度是指圆角的程度 -->
    <corners android:radius="50dp" />
    <!-- 这个标签表示纯色填充,通过android:color即可指定shape中填充的颜色 -->
    <solid android:color="#30000000" />
    <!-- Shape的描边,下面指定了描边的宽度和描边的颜色 -->
    <stroke
        android:width="1dp"
        android:color="#d9d9d9" />
</shape>

values文件夹下colors

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="theme">#feb806</color>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>
    <color name="white">#FFFFFF</color>
    <color name="black_transparent">#80000000</color>
    <color name="black">#000000</color>
    <color name="gray">#cccccc</color>
    <color name="red">#C91623</color>
    <color name="bigred">#C91623</color>
    <color name="hintcolor">#b6b6b6</color>
    <color name="loginline">#45bd73</color>
    <color name="blue">#00a0e9</color>
    <color name="oriange">#ff9a00</color>
    <color name="dark">#424242</color>
    <color name="grey">#8C8C8C</color>
    <color name="light_red">#fa4b4b</color>
    <color name="theme_lanse">#3F51B5</color>
    <color name="gray_meituan">#494042</color>
    <color name="gray_meituan2">#e6494042</color>
</resources>

styles

<style name="gray_height_1dp">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">0.5dp</item>
    <item name="android:background">@color/gray</item>
</style>
<declare-styleable name="AddDeleteViewStyle">
    <attr name="left_text" format="string"/>
    <attr name="right_text" format="string"/>
    <attr name="middle_text" format="string"/>
</declare-styleable>

MainActivity

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SearchView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bwie.test.adapter.SearchViewGreenDaoAdapter;
import com.bwie.test.app.MyApp;
import com.bwie.test.bean.DataBean;
import com.bwie.test.sqldao.DataBeanDao;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import org.greenrobot.greendao.query.QueryBuilder;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity {
    @BindView(R.id.search_ok)
    Button searchOk;
    @BindView(R.id.searchview)
    SearchView searchview;
    @BindView(R.id.search_main)
    RelativeLayout searchMain;
    @BindView(R.id.search_greendao_flowlayout)
    TagFlowLayout searchGreendaoFlowlayout;
    @BindView(R.id.search_greendao_rl)
    RelativeLayout searchGreendaoRl;
    @BindView(R.id.search_greendao_lv)
    ListView searchGreendaoLv;
    @BindView(R.id.search_greendao_delete)
    Button searchGreendaoDelete;
    int id = 0;
    String name = "";
    String[] names = {"android", "HTML", "java", "PHP", "C", "C++", "NodeJs", "Hexo", "Github"};
    QueryBuilder qb;
    Context mContext;
    private DataBeanDao dataBeanDao;
    private List<DataBean> list;
    DataBean dataBean;
    SearchViewGreenDaoAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        //隐藏原有标题
        getSupportActionBar().hide();
        mContext = MainActivity.this;
        searchview.setQueryHint("请输入");
        searchview.onActionViewExpanded();
        searchview.clearFocus();
        delectUnderline();
        //初始化数据库
        dataBeanDao = MyApp.getDaoSession().getDataBeanDao();
        initDate();
        searchGreendaoLv.setTextFilterEnabled(true);
    }

    private void initDate() {
        //搜索历史列表
        updateList();
        //热门搜索
        searchGreendaoFlowlayout.setAdapter(new TagAdapter<String>(names) {
            @Override
            public View getView(FlowLayout parent, int position, final String s) {
                final TextView tv = (TextView) LayoutInflater.from(mContext).inflate(
                        R.layout.search_page_flowlayout_tv, searchGreendaoFlowlayout, false);
                tv.setText(s);
                tv.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(mContext, "" + s, Toast.LENGTH_SHORT).show();
                    }
                });
                return tv;
            }
        });

        //搜索文本监听
        searchview.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            //点击搜索
            public boolean onQueryTextSubmit(String query) {
                name = query;
                Log.e("name--------", name + "");
                insertDB();
                return false;
            }

            @Override
            //当搜索内容改变
            public boolean onQueryTextChange(String newText) {
                name = newText;
                Log.e("newText---------", newText);
                if (name.equals("")) {
                } else {
                }
                return false;
            }
        });
    }

    private void updateList() {
        //查询所有
        list = dataBeanDao.queryBuilder().list();
        //这里用于判断是否有数据
        if (list.size() == 0) {
            searchGreendaoRl.setVisibility(View.VISIBLE);
            searchGreendaoDelete.setVisibility(View.GONE);
        } else {
            searchGreendaoRl.setVisibility(View.GONE);
            searchGreendaoDelete.setVisibility(View.VISIBLE);
        }
        //list倒序排列
        Collections.reverse(list);
        adapter = new SearchViewGreenDaoAdapter(mContext, list);
        searchGreendaoLv.setAdapter(adapter);
        adapter.notifyDataSetChanged();
    }

    //增
    private void insertDB() {
        try {
            if (list.size() < 8) {
                //删除已经存在重复的搜索历史
                List<DataBean> list2 = dataBeanDao.queryBuilder()
                        .where(DataBeanDao.Properties.Title.eq(name)).build().list();
                dataBeanDao.deleteInTx(list2);
                //添加
                if (!name.equals(""))
                    dataBeanDao.insert(new DataBean(null, name));
                Toast.makeText(mContext, "插入数据成功:" + name, Toast.LENGTH_SHORT).show();
            } else {
                //删除第一条数据,用于替换最后一条搜索
                dataBeanDao.delete(dataBeanDao.queryBuilder().list().get(0));
                //删除已经存在重复的搜索历史
                List<DataBean> list3 = dataBeanDao.queryBuilder()
                        .where(DataBeanDao.Properties.Title.eq(name)).build().list();
                dataBeanDao.deleteInTx(list3);
                //添加
                if (!name.equals(""))
                    dataBeanDao.insert(new DataBean(null, name));
            }
            updateList();
        } catch (Exception e) {
            Toast.makeText(mContext, "插入失败", Toast.LENGTH_SHORT).show();
        }
    }

    //清空数据库
    private void delectAllDB() {
        try {
            dataBeanDao.deleteAll();
            list.clear();
            adapter.notifyDataSetChanged();
            searchGreendaoRl.setVisibility(View.VISIBLE);
            searchGreendaoDelete.setVisibility(View.GONE);
            Toast.makeText(mContext, "清空数据库", Toast.LENGTH_SHORT).show();
        } catch (Exception e) {
            Log.e("exception-----delete", dataBean + "message:" + e.getMessage() + "");
        }
    }

    @OnClick({R.id.search_greendao_delete, R.id.search_ok})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.search_greendao_delete:
                delectAllDB();
                break;
            case R.id.search_ok:
                insertDB();
                Intent intent = new Intent(this, ShowActivity.class);
                intent.putExtra("uid","2797");
                startActivity(intent);
                break;
        }
    }

    /**
     * 去掉searchview下划线
     */
    public void delectUnderline() {
        if (searchview != null) {
            try {        //--拿到字节码
                Class<?> argClass = searchview.getClass();
                //--指定某个私有属性,mSearchPlate是搜索框父布局的名字
                Field ownField = argClass.getDeclaredField("mSearchMain");
                //--暴力反射,只有暴力反射才能拿到私有属性
                ownField.setAccessible(true);
                View mView = (View) ownField.get(searchview);
                //--设置背景
                mView.setBackgroundColor(R.drawable.shape_search);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

ShowActivity

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.util.Log;

import com.bwie.test.adapter.ShowAdapter;
import com.bwie.test.bean.ProductsBean;
import com.bwie.test.inter.IView;
import com.bwie.test.presenter.CartPresenter;
import com.jcodecraeer.xrecyclerview.ProgressStyle;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import java.util.HashMap;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;

public class ShowActivity extends AppCompatActivity implements IView {
    @BindView(R.id.xrecyclerView)
    XRecyclerView xRecyclerView;
    private int num = 1;
    private CartPresenter presenter;
    private HashMap<String, String> map;
    private ShowAdapter adapter;
    private String uid;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show);
        ButterKnife.bind(this);
        //隐藏原有标题
        getSupportActionBar().hide();
        uid = getIntent().getStringExtra("uid");
        getData(num);
        LinearLayoutManager manager = new LinearLayoutManager(this);
        xRecyclerView.setLayoutManager(manager);
        xRecyclerView.setPullRefreshEnabled(true);
        xRecyclerView.setLoadingMoreEnabled(true);
        xRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);
        xRecyclerView.setLoadingMoreProgressStyle(ProgressStyle.Pacman);

        xRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        num = 1;
                        getData(num);
                        adapter.notifyDataSetChanged();
                        xRecyclerView.refreshComplete();
                    }
                }, 2000);
            }

            @Override
            public void onLoadMore() {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        num++;
                        getData(num);
                        adapter.notifyDataSetChanged();
                        xRecyclerView.refreshComplete();
                    }
                },2000);
            }
        });
    }

    public void getData(int count){
        presenter = new CartPresenter();
        map = new HashMap<>();
        //pscid=39&page=1
        map.put("pscid", "39");
        map.put("page", count + "");
        presenter.getProductData(map);
        presenter.attachView(this);
    }

    @Override
    public void onSuccess(Object o) {
        if (o != null){
            ProductsBean bean = (ProductsBean) o;
            Log.i("zzz", "onSuccess: " + bean.getMsg());
            final List<ProductsBean.DataBean> data = bean.getData();
            adapter = new ShowAdapter(this, data);
            xRecyclerView.setAdapter(adapter);
            adapter.setOnItemClickListener(new ShowAdapter.OnItemClickListener() {
                @Override
                public void onClick(int position) {
                    Intent intent = new Intent(ShowActivity.this, ShowsActivity.class);
                    intent.putExtra("pid",data.get(position).getPid()+"");
                    intent.putExtra("uid",uid);
                    startActivity(intent);
                }

                @Override
                public void onLongClick(int position) {

                }
            });
        }
    }

    @Override
    public void onFailed(Exception e) {

    }
}

ShowsActivity

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bwie.test.bean.AddBean;
import com.bwie.test.bean.ShowsBean;
import com.bwie.test.inter.IView;
import com.bwie.test.presenter.CartPresenter;
import com.facebook.drawee.view.SimpleDraweeView;
import java.util.HashMap;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ShowsActivity extends AppCompatActivity {
    @BindView(R.id.regist_back)
    ImageView registBack;
    @BindView(R.id.shows_img)
    SimpleDraweeView showsImg;
    @BindView(R.id.shows_title)
    TextView showsTitle;
    @BindView(R.id.shows_price)
    TextView showsPrice;
    @BindView(R.id.cart)
    Button cart;
    @BindView(R.id.add_cart)
    Button addCart;
    private CartPresenter presenter;
    private HashMap<String, String> map;
    private String pid;
    private CartPresenter presenter1;
    private String uid;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shows);
        ButterKnife.bind(this);
        //隐藏原有标题
        getSupportActionBar().hide();
        //查找控件
        pid = getIntent().getStringExtra("pid");
        uid = getIntent().getStringExtra("uid");
        Log.i("fff", "onCreate: "+ pid);
        presenter = new CartPresenter();
        map = new HashMap<>();
        map.put("pid", pid);
        map.put("source", "android");
        presenter.getShowsData(map);
        presenter.attachView(new IView() {
            @Override
            public void onSuccess(Object o) {
                if (o != null) {
                    ShowsBean bean = (ShowsBean) o;
                    Log.i("fff", "onSuccess: "+bean.getMsg());
                    String[] split = bean.getData().getImages().split("[|]");
                    showsImg.setImageURI(split[0]);
                    showsTitle.setText(bean.getData().getTitle());
                    showsPrice.setText("¥"+bean.getData().getPrice());
                }
            }

            @Override
            public void onFailed(Exception e) {

            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (presenter != null){
            presenter.dattachView();
        }
    }

    @OnClick({R.id.regist_back, R.id.cart, R.id.add_cart})
    public void onViewClicked(View view){
        switch (view.getId()){
            case R.id.regist_back:
                finish();
                break;
            case R.id.cart:
                Intent intent = new Intent(ShowsActivity.this, CartActivity.class);
                intent.putExtra("uid",uid);
                startActivity(intent);
                break;
            case R.id.add_cart:
                HashMap<String, String> map = new HashMap<>();
                map.put("uid",uid);
                map.put("pid",pid);
                map.put("source","android");
                presenter.getAddData(map);
                presenter.attachView(new IView() {
                    @Override
                    public void onSuccess(Object o) {
                        if (o!=null){
                            AddBean bean = (AddBean) o;
                            Toast.makeText(ShowsActivity.this, bean.getMsg(), Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    public void onFailed(Exception e) {

                    }
                });
                break;
        }
    }
}

CartActivity

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bwie.test.adapter.ShopCartExListAdapter;
import com.bwie.test.bean.CartsBean;
import com.bwie.test.bean.MessageEvent;
import com.bwie.test.bean.PriceAndCountEvent;
import com.bwie.test.inter.IView;
import com.bwie.test.presenter.CartPresenter;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class CartActivity extends AppCompatActivity implements IView {
    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.subtitle)
    TextView subtitle;
    @BindView(R.id.top_bar)
    LinearLayout topBar;
    @BindView(R.id.exListView)
    ExpandableListView exListView;
    @BindView(R.id.all_chekbox)
    CheckBox allChekbox;
    @BindView(R.id.tv_total_price)
    TextView tvTotalPrice;
    @BindView(R.id.tv_go_to_pay)
    TextView tvGoToPay;
    @BindView(R.id.ll_info)
    LinearLayout llInfo;
    @BindView(R.id.tv_share)
    TextView tvShare;
    @BindView(R.id.tv_save)
    TextView tvSave;
    @BindView(R.id.tv_delete)
    TextView tvDelete;
    @BindView(R.id.ll_shar)
    LinearLayout llShar;
    @BindView(R.id.ll_cart)
    LinearLayout llCart;
    private int count = 0;
    private List<CartsBean.DataBean> list = new ArrayList<>();
    private ShopCartExListAdapter adapter;
    private boolean flag = false;
    private int totalCount = 0;
    private double totalPrice = 0.00;
    private CartPresenter presenter;
    private String uid;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cart);
        ButterKnife.bind(this);
        //隐藏原有标题
        getSupportActionBar().hide();
        EventBus.getDefault().register(this);
        uid = getIntent().getStringExtra("uid");
        getData();
    }

    private void getData() {
        presenter = new CartPresenter();
        presenter.attachView(this);
        Map<String, String> map = new HashMap<>();
        map.put("uid", uid);
        map.put("source", "android");
        presenter.getCartsData(map);
        adapter = new ShopCartExListAdapter(this, list);
        exListView.setAdapter(adapter);
    }

    @Override
    public void onSuccess(Object o) {
        if (o !=null) {
            CartsBean cartsBean = (CartsBean) o;
            List<CartsBean.DataBean> dataBean = cartsBean.getData();
            list.addAll(dataBean);
            adapter.notifyDataSetChanged();
            for (int i = 0; i < adapter.getGroupCount(); i++) {
                exListView.expandGroup(i);
            }
        }
    }

    @Override
    public void onFailed(Exception e) {
    }

    public void delete() {
        for (int i = 0; i < list.size(); i++) {
            List<CartsBean.DataBean.ListBean> listbean = list.get(i).getList();
            for (int j = 0; j < listbean.size(); j++) {
                CartsBean.DataBean.ListBean listBean = listbean.get(j);
                if (listBean.isChecked()) {
                    listbean.remove(j);
                    j--;
                    if (listbean.size() == 0) {
                        list.remove(i);
                        i--;
                    }
                }
            }
        }
        adapter.notifyDataSetChanged();
    }

    @OnClick({R.id.all_chekbox, R.id.tv_share, R.id.tv_save, R.id.tv_delete, R.id.subtitle, 
                            R.id.tv_go_to_pay,R.id.back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.all_chekbox:
                adapter.changeAllListCbState(allChekbox.isChecked());
                break;
            case R.id.tv_share:
                Toast.makeText(this, "分享成功", Toast.LENGTH_SHORT).show();
                break;
            case R.id.tv_save:
                Toast.makeText(this, "加入成功", Toast.LENGTH_SHORT).show();
                break;
            case R.id.tv_delete:
                AlertDialog dialog;
                if (totalCount == 0) {
                    Toast.makeText(CartActivity.this, "请选择要删除的商品", Toast.LENGTH_SHORT).show();
                    return;
                }
                dialog = new AlertDialog.Builder(CartActivity.this).create();
                dialog.setTitle("操作提示");
                dialog.setMessage("您确定要将这些商品从购物车中移除吗?");
                dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "取消", 
                                             new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        return;
                    }
                });
                dialog.setButton(DialogInterface.BUTTON_POSITIVE, "确定",
                                            new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        delete();
                        Toast.makeText(CartActivity.this, "删除成功", Toast.LENGTH_SHORT).show();
                    }
                });
                dialog.show();
                break;
            case R.id.subtitle:
                flag = !flag;
                if (flag) {
                    subtitle.setText("完成");
                    llShar.setVisibility(View.VISIBLE);
                    llInfo.setVisibility(View.GONE);
                } else {
                    subtitle.setText("编辑");
                    llShar.setVisibility(View.GONE);
                    llInfo.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.tv_go_to_pay:
                AlertDialog alert;
                if (totalCount == 0) {
                    Toast.makeText(this, "请选择要支付的商品", Toast.LENGTH_LONG).show();
                    return;
                }
                alert = new AlertDialog.Builder(this).create();
                alert.setTitle("操作提示");
                alert.setMessage("总计:\n" + totalCount + "种商品\n" + totalPrice + "元");
                alert.setButton(DialogInterface.BUTTON_NEGATIVE, "取消",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                return;
                            }
                        });
                alert.setButton(DialogInterface.BUTTON_POSITIVE, "确定",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Intent intent = new Intent(CartActivity.this, DingDanActivity.class);
                                startActivity(intent);
                                Toast.makeText(CartActivity.this,"创建订单",Toast.LENGTH_SHORT).show();
                            }
                        });
                alert.show();
                break;
            case R.id.back:
                finish();
                break;
        }
    }

    @Subscribe
    public void onMessageEvent(MessageEvent event) {
        allChekbox.setChecked(event.isChecked());
    }

    @Subscribe
    public void onMessageEvent(PriceAndCountEvent event) {
        tvGoToPay.setText("结算(" + event.getCount() + ")");
        tvTotalPrice.setText("¥" + event.getPrice());
        totalCount = event.getCount();
        totalPrice = event.getPrice();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (presenter!=null){
            presenter.dattachView();
        }
    }
}

DingDanActivity

import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bwie.test.adapter.DingdanAdapter;
import com.bwie.test.bean.DinganBean;
import com.bwie.test.inter.IView;
import com.bwie.test.presenter.CartPresenter;
import com.jcodecraeer.xrecyclerview.ProgressStyle;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import java.util.HashMap;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class DingDanActivity extends AppCompatActivity implements IView {
    @BindView(R.id.img_duo)
    ImageView imgDuo;
    @BindView(R.id.textview1)
    TextView textview1;
    @BindView(R.id.textview2)
    TextView textview2;
    @BindView(R.id.textview3)
    TextView textview3;
    @BindView(R.id.rv)
    XRecyclerView mRv;
    private int num = 1;
    private DingdanAdapter dingdanAdapter;
    private CartPresenter presenter;
    private HashMap<String, String> map;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ding_dan);
        ButterKnife.bind(this);
        //隐藏原有标题
        getSupportActionBar().hide();
        getData(1);
        LinearLayoutManager manager = new LinearLayoutManager(this);
        mRv.setLayoutManager(manager);
        mRv.setPullRefreshEnabled(true);
        mRv.setLoadingMoreEnabled(true);
        mRv.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);
        mRv.setLoadingMoreProgressStyle(ProgressStyle.Pacman);

        mRv.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                new Handler().postDelayed(new Runnable() {
                    public void run() {
                        num = 1;
                        getData(num);
                        dingdanAdapter.notifyDataSetChanged();
                        mRv.refreshComplete();
                    }
                }, 2000);
            }

            @Override
            public void onLoadMore() {
                new Handler().postDelayed(new Runnable() {
                    public void run() {
                        num++;
                        getData(num);
                        dingdanAdapter.notifyDataSetChanged();
                        mRv.refreshComplete();
                    }
                }, 2000);
            }
        });
    }

    @OnClick({R.id.img_duo, R.id.rv, R.id.textview1, R.id.textview2, R.id.textview3})
    public void onClick(View v){
        switch (v.getId()) {
            default:
                break;
            case R.id.img_duo:
                break;
            case R.id.rv:
                break;
            case R.id.textview1:
                break;
            case R.id.textview2:
                break;
            case R.id.textview3:
                break;
        }
    }

    public void getData(int count) {
        presenter = new CartPresenter();
        map = new HashMap<>();
        //pscid=39&page=1
        map.put("uid", "71");
        map.put("page", count + "");
        presenter.getDingdanData(map);
        presenter.attachView(this);
    }

    @Override
    public void onSuccess(Object o) {
        if (o != null) {
            DinganBean bean = (DinganBean) o;
            Log.i("zzz", "onSuccess: " + bean.getMsg());
            final List<DinganBean.DataBean> data = bean.getData();
            dingdanAdapter = new DingdanAdapter(this, data);
            mRv.setAdapter(dingdanAdapter);
        }
    }

    @Override
    public void onFailed(Exception e) {

    }
}

app文件夹下MyApp

import android.app.Application;
import com.bwie.test.sqldao.DaoMaster;
import com.bwie.test.sqldao.DaoSession;
import com.facebook.drawee.backends.pipeline.Fresco;

public class MyApp extends Application{
    private static DaoSession daoSession;

    @Override
    public void onCreate() {
        super.onCreate();
        //初始化fresco
        Fresco.initialize(this);
        DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(this, "baway1.db");
        DaoMaster daoMaster = new DaoMaster(devOpenHelper.getWritableDb());
        daoSession = daoMaster.newSession();
    }

    public static DaoSession getDaoSession(){
        return daoSession;
    }
}

inter文件夹下BasePresenter

import java.util.Map;

public interface BasePresenter {
    void getProductData(Map<String, String> map);
    void getShowsData(Map<String, String> map);
    void getAddData(Map<String, String> map);
    void getCartsData(Map<String, String> map);
    void getDeleteData(Map<String, String> map);
    void getDingdanData(Map<String, String> map);
}

IModel

import java.util.Map;
public interface IModel {
    void getProductData(Map<String, String> map);
    void getShowsData(Map<String, String> map);
    void getAddData(Map<String, String> map);
    void getCartsData(Map<String, String> map);
    void getDeleteData(Map<String, String> map);
    void getDingdanData(Map<String, String> map);
}

IView

public interface IView {
    void onSuccess(Object o);
    void onFailed(Exception e);
}

custom文件夹下AddDeleteView

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.bwie.test.mymoni_yuekao.R;

public class AddDeleteView extends LinearLayout {
    private OnAddDelClickListener listener;
    private TextView et_number;

    public void setOnAddDelClickListener(OnAddDelClickListener listener) {
        if (listener != null) {
            this.listener = listener;
        }
    }

    public interface OnAddDelClickListener {
        void onAddClick(View v);
        void onDelClick(View v);
    }

    public AddDeleteView(Context context) {
        this(context, null);
    }

    public AddDeleteView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public AddDeleteView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context, attrs, defStyleAttr);
    }

    private void initView(Context context, AttributeSet attrs, int defStyleAttr) {
        View.inflate(context, R.layout.layout_add_delete, this);
        Button but_add = findViewById(R.id.but_add);
        Button but_delete = findViewById(R.id.but_delete);
        et_number = findViewById(R.id.et_number);

        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.AddDeleteViewStyle);
        String left_text = typedArray.getString(R.styleable.AddDeleteViewStyle_left_text);
        String middle_text = typedArray.getString(R.styleable.AddDeleteViewStyle_middle_text);
        String right_text = typedArray.getString(R.styleable.AddDeleteViewStyle_right_text);

        et_number.setText(middle_text);
        //释放资源
        typedArray.recycle();

        but_add.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.onAddClick(view);
            }
        });
        but_delete.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.onDelClick(view);
            }
        });
    }

    /**
     * 对外提供设置EditText值的方法
     */
    public void setNumber(int number) {
        if (number > 0) {
            et_number.setText(number + "");
        }
    }

    /**
     * 得到控件原来的值
     */
    public int getNumber() {
        int number = 0;
        try {
            String numberStr = et_number.getText().toString().trim();
            number = Integer.valueOf(numberStr);
        } catch (Exception e) {
            number = 0;
        }
        return number;
    }
}

MyScrollView

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ScrollView;

@SuppressLint("ViewConstructor")
public class MyScrollView extends ScrollView {
    private OnScrollListener listener;

    public void setOnScrollListener(OnScrollListener listener) {
        this.listener = listener;
    }

    public MyScrollView(Context context) {
        super(context);
    }

    public MyScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public interface OnScrollListener{
        void onScroll(int scrollY);
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);
        if(listener != null){
            listener.onScroll(t);
        }
    }
}

model文件夹下CartModel

import com.bwie.test.bean.AddBean;
import com.bwie.test.bean.CartsBean;
import com.bwie.test.bean.DeleteBean;
import com.bwie.test.bean.DinganBean;
import com.bwie.test.bean.ProductsBean;
import com.bwie.test.bean.ShowsBean;
import com.bwie.test.inter.IModel;
import com.bwie.test.presenter.CartPresenter;
import com.bwie.test.utils.RetrofitUtils;
import java.util.Map;
import io.reactivex.Flowable;

public class CartModel implements IModel {
    private CartPresenter presenter;

    public CartModel(CartPresenter presenter) {
        this.presenter = presenter;
    }

    @Override
    public void getProductData(Map<String, String> map) {
        Flowable<ProductsBean> flowable = RetrofitUtils.getInstance("https://www.zhaoapi.cn/")
                                .getApiService().getProduct(map);
        presenter.getProductNews(flowable);
    }

    @Override
    public void getShowsData(Map<String, String> map) {
        Flowable<ShowsBean> flowable = RetrofitUtils.getInstance("https://www.zhaoapi.cn/")
                              .getApiService().getShows(map);
        presenter.getShowsNews(flowable);
    }

    @Override
    public void getAddData(Map<String, String> map) {
        Flowable<AddBean> flowable = RetrofitUtils.getInstance("http://120.27.23.105/")
                             .getApiService().getAdd(map);
        presenter.getAddNews(flowable);
    }

    @Override
    public void getCartsData(Map<String, String> map) {
        Flowable<CartsBean> flowable = RetrofitUtils.getInstance("http://120.27.23.105/")
                        .getApiService().getCarts(map);
        presenter.getCartsNews(flowable);
    }

    @Override
    public void getDeleteData(Map<String, String> map) {
        Flowable<DeleteBean> flowable = RetrofitUtils.getInstance("http://120.27.23.105/")
                         .getApiService().getDelete(map);
        presenter.getDeleteNews(flowable);
    }

    @Override
    public void getDingdanData(Map<String, String> map) {
        Flowable<DinganBean> flowable = RetrofitUtils.getInstance("http://120.27.23.105/")
                        .getApiService().getDingdan(map);
        presenter.getDingdanNews(flowable);
    }
}

presenter文件夹下CartPresenter

import android.util.Log;
import com.bwie.test.bean.AddBean;
import com.bwie.test.bean.CartsBean;
import com.bwie.test.bean.DeleteBean;
import com.bwie.test.bean.DinganBean;
import com.bwie.test.bean.ProductsBean;
import com.bwie.test.bean.ShowsBean;
import com.bwie.test.inter.BasePresenter;
import com.bwie.test.inter.IView;
import com.bwie.test.model.CartModel;

import java.util.Map;
import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subscribers.DisposableSubscriber;

public class CartPresenter implements BasePresenter {
    private IView iv;
    private DisposableSubscriber subscriber2;
    private DisposableSubscriber subscriber3;
    private DisposableSubscriber subscriber4;
    private DisposableSubscriber subscriber5;
    private DisposableSubscriber subscriber6;
    private DisposableSubscriber subscriber7;

    public void attachView(IView iv) {
        this.iv = iv;
    }

    public void dattachView() {
        if (iv != null) {
            iv = null;
        }
        if (subscriber2!=null){
            if (subscriber2.isDisposed()){
                subscriber2.dispose();
            }
        }
        if (subscriber3!=null){
            if (subscriber3.isDisposed()){
                subscriber3.dispose();
            }
        }
        if (subscriber4!=null){
            if (subscriber4.isDisposed()){
                subscriber4.dispose();
            }
        }
        if (subscriber5!=null){
            if (subscriber5.isDisposed()){
                subscriber5.dispose();
            }
        }
        if (subscriber6!=null){
            if (subscriber6.isDisposed()){
                subscriber6.dispose();
            }
        }
        if (subscriber7!=null){
            if (subscriber7.isDisposed()){
                subscriber7.dispose();
            }
        }
    }

    @Override
    public void getProductData(Map<String, String> map) {
        CartModel model = new CartModel(this);
        model.getProductData(map);
    }

    @Override
    public void getShowsData(Map<String, String> map) {
        CartModel model = new CartModel(this);
        model.getShowsData(map);
    }

    @Override
    public void getAddData(Map<String, String> map) {
        CartModel model = new CartModel(this);
        model.getAddData(map);
    }

    @Override
    public void getCartsData(Map<String, String> map) {
        CartModel model = new CartModel(this);
        model.getCartsData(map);
    }

    @Override
    public void getDeleteData(Map<String, String> map) {
        CartModel model = new CartModel(this);
        model.getDeleteData(map);
    }

    @Override
    public void getDingdanData(Map<String, String> map) {
        CartModel model = new CartModel(this);
        model.getDingdanData(map);
    }

    public void getDingdanNews(Flowable<DinganBean> flowable){
        subscriber7 = flowable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new DisposableSubscriber<DinganBean>() {
                    @Override
                    public void onNext(DinganBean dinganBean) {
                        if (dinganBean != null) {
                            iv.onSuccess(dinganBean);
                        }
                    }

                    @Override
                    public void onError(Throwable t) {
                        iv.onFailed((Exception) t);
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void getDeleteNews(Flowable<DeleteBean> flowable) {
        subscriber6 = flowable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new DisposableSubscriber<DeleteBean>() {
                    @Override
                    public void onNext(DeleteBean deleteBean) {
                        if (deleteBean != null) {
                            iv.onSuccess(deleteBean);
                        }
                    }

                    @Override
                    public void onError(Throwable t) {
                        iv.onFailed((Exception) t);
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void getCartsNews(Flowable<CartsBean> flowable) {
        subscriber5 = flowable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new DisposableSubscriber<CartsBean>() {
                    @Override
                    public void onNext(CartsBean cartsBean) {
                        if (cartsBean != null) {
                            iv.onSuccess(cartsBean);
                        }
                    }

                    @Override
                    public void onError(Throwable t) {
                        iv.onFailed((Exception) t);
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void getProductNews(Flowable<ProductsBean> flowable) {
        subscriber2 = flowable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new DisposableSubscriber<ProductsBean>() {
                    @Override
                    public void onNext(ProductsBean productsBean) {
                        if (productsBean != null) {
                            iv.onSuccess(productsBean);
                        }
                    }

                    @Override
                    public void onError(Throwable t) {
                        iv.onFailed((Exception) t);
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void getShowsNews(Flowable<ShowsBean> flowable) {
        subscriber3 = flowable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new DisposableSubscriber<ShowsBean>() {
                    @Override
                    public void onNext(ShowsBean showsBean) {
                        if (showsBean != null) {
                            iv.onSuccess(showsBean);
                            Log.i("fff", "onSuccess: "+showsBean.getMsg());
                        }
                    }

                    @Override
                    public void onError(Throwable t) {
                        iv.onFailed((Exception) t);
                        Log.i("fff", "onSuccess: "+t.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void getAddNews(Flowable<AddBean> flowable) {
        subscriber4 = flowable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new DisposableSubscriber<AddBean>() {
                    @Override
                    public void onNext(AddBean addBean) {
                        if (addBean != null) {
                            iv.onSuccess(addBean);
                        }
                    }

                    @Override
                    public void onError(Throwable t) {
                        iv.onFailed((Exception) t);
                        Log.i("fff", "onSuccess: " + t.getMessage());
                    }

                    @Override
                    public void onComplete() {
                    }
                });
    }
}

adapter文件夹下DingdanAdapter

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.bwie.test.bean.DinganBean;
import com.bwie.test.mymoni_yuekao.R;
import java.util.List;

public class DingdanAdapter extends RecyclerView.Adapter<DingdanAdapter.ViewHolder> {
    private Context context;
    private List<DinganBean.DataBean> list;
    private View v;

    public DingdanAdapter(Context context, List<DinganBean.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    private OnItemClickListener mOnItemClickListener;

    public interface OnItemClickListener{
        void onClick(int position);
        void onLongClick(int position);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener ){
        this. mOnItemClickListener=onItemClickListener;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        v = View.inflate(context, R.layout.item_main, null);
        ViewHolder holder = new ViewHolder(v);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.title.setText(list.get(position).getTitle());
        holder.price.setText("价格: "+list.get(position).getPrice());
        holder.time.setText("创建时间: "+list.get(position).getCreatetime());
        final DinganBean.DataBean dataBean = list.get(position);
        int status = list.get(position).getStatus();
        if(status==2){
            holder.wen.setText("已取消");
            holder.wen.setTextColor(Color.BLACK);
        }else if(status == 1){
            holder.wen.setText("已支付");
            holder.wen.setTextColor(Color.BLACK);
        }else{
            holder.wen.setTextColor(Color.RED);
            holder.wen.setText("待支付");
            holder.btn.setText("取消支付");
        }

        final DialogInterface.OnClickListener click1 = new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface arg0, int arg1) {
                //  Toast.makeText(context,"否",Toast.LENGTH_LONG).show();;
            }
        };

        final DialogInterface.OnClickListener click2 = new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface arg0, int arg1) {
                Toast.makeText(context,"订单已取消",Toast.LENGTH_LONG).show();
                // xiuCartPersenter.getNews();
                dataBean.setStatus(0);
                notifyDataSetChanged();
            }
        };

        holder.btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(context,"查看订单",Toast.LENGTH_LONG).show();
                new AlertDialog.Builder(context).setTitle("提示").setMessage("确定取消订单吗?")
                        .setPositiveButton("否", click1)
                        .setNegativeButton("是", click2).show();
            }
        });
    }

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

    public class ViewHolder extends RecyclerView.ViewHolder {
        private final TextView title;
        private final TextView price;
        private final TextView time;
        private final TextView wen;
        private final Button btn;
        public ViewHolder(View itemView) {
            super(itemView);
            title = v.findViewById(R.id.tv_title);
            price = v.findViewById(R.id.tv_price);
            time = v.findViewById(R.id.tv_time);
            wen = v.findViewById(R.id.tv_wen);
            btn= v.findViewById(R.id.btn);
        }
    }
}

SearchViewGreenDaoAdapter

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.bwie.test.bean.DataBean;
import com.bwie.test.mymoni_yuekao.R;
import java.util.List;

public class SearchViewGreenDaoAdapter extends BaseAdapter {
    private Context context;
    private List<DataBean> list;

    public SearchViewGreenDaoAdapter(Context context, List<DataBean> list) {
        this.context = context;
        this.list=list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final DataBean tv = (DataBean) getItem(position);
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.search_page_flowlayout_tv, null);
            viewHolder = new ViewHolder();
            viewHolder.flowlayout_tv = (TextView) convertView.findViewById(R.id.flowlayout_tv);
            viewHolder.flowlayout_tv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(context,tv.getTitle()+"", Toast.LENGTH_SHORT).show();
                }
            });
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.flowlayout_tv.setText(tv.getTitle());
        return convertView;
    }

    //创建ViewHolder类
    class ViewHolder {
        TextView flowlayout_tv;
    }
}

ShopCartExListAdapter

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.net.Uri;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bwie.test.bean.CartsBean;
import com.bwie.test.bean.MessageEvent;
import com.bwie.test.bean.PriceAndCountEvent;
import com.bwie.test.custom.AddDeleteView;
import com.bwie.test.mymoni_yuekao.R;
import com.facebook.drawee.view.SimpleDraweeView;
import org.greenrobot.eventbus.EventBus;
import java.util.ArrayList;
import java.util.List;

public class ShopCartExListAdapter extends BaseExpandableListAdapter {
    private Context context;
    private List<CartsBean.DataBean> list = new ArrayList<>();
    private boolean isShow = true;
    private boolean flag = true;
    private int totalCount=0;

    public ShopCartExListAdapter(Context context, List<CartsBean.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getGroupCount() {
        return list.size();
    }

    @Override
    public int getChildrenCount(int i) {
        return list.get(i).getList().size();
    }

    @Override
    public Object getGroup(int i) {
        return list.get(i);
    }

    @Override
    public Object getChild(int i, int i1) {
        return list.get(i).getList().get(i1);
    }

    @Override
    public long getGroupId(int i) {
        return i;
    }

    @Override
    public long getChildId(int i, int i1) {
        return i1;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(final int groupPosition, boolean isExpanded, View convertView, 
                                ViewGroup parent) {
        View view;
        final GroupViewHolder holder;
        if (convertView == null) {
            holder = new GroupViewHolder();
            view = View.inflate(context, R.layout.item_shopcart_group, null);
            holder.determine_chekbox = (CheckBox) view.findViewById(R.id.determine_chekbox);
            holder.tv_source_name = (TextView) view.findViewById(R.id.tv_source_name);
            holder.tv_store_edtor = (TextView) view.findViewById(R.id.tv_store_edtor);
            view.setTag(holder);
        } else {
            view = convertView;
            holder = (GroupViewHolder) view.getTag();
        }
        final CartsBean.DataBean dataBean = list.get(groupPosition);
        holder.determine_chekbox.setChecked(dataBean.isChecked());
        holder.tv_source_name.setText(dataBean.getSellerName());
        //一级checkbox
        holder.determine_chekbox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                totalCount++;
                dataBean.setChecked(holder.determine_chekbox.isChecked());
                changeChildCbState(groupPosition, holder.determine_chekbox.isChecked());
                EventBus.getDefault().post(compute());
                changeAllCbState(isAllGroupCbSelected());
                notifyDataSetChanged();
            }
        });

        if (dataBean.isEdtor()) {
            holder.tv_store_edtor.setText("完成");
        } else {
            holder.tv_store_edtor.setText("编辑");
        }
        holder.tv_store_edtor.setOnClickListener(new GroupViewClick(groupPosition,
                           holder.tv_store_edtor, dataBean));
        notifyDataSetChanged();
        return view;
    }

    @Override
    public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild,
                           View convertView, ViewGroup parent) {
        View view;
        final ChildViewHolder holder;
        if (convertView == null) {
            holder = new ChildViewHolder();
            view = View.inflate(context,R.layout.item_shopcart_product, null);
            holder.cbChild = (CheckBox) view.findViewById(R.id.check_box);
            holder.tv_intro = (TextView) view.findViewById(R.id.tv_intro);
            holder.imgIcon = (SimpleDraweeView) view.findViewById(R.id.iv_adapter_list_pic);
            holder.tv_price = (TextView) view.findViewById(R.id.tv_price);
            holder.tv_del = (TextView) view.findViewById(R.id.tv_goods_delete);
            //            holder.bt_add = (ImageView) view.findViewById(R.id.bt_add);
            //            holder.bt_del = (ImageView) view.findViewById(R.id.bt_reduce);
            //            holder.et_num = (EditText) view.findViewById(R.id.et_num);
            holder.tv_num = (TextView) view.findViewById(R.id.tv_buy_num);
            holder.ll_edtor = (LinearLayout) view.findViewById(R.id.ll_edtor);
            holder.rl_no_edtor = (RelativeLayout) view.findViewById(R.id.rl_no_edtor);
            holder.adv = view.findViewById(R.id.adv_main);
            view.setTag(holder);
        } else {
            view = convertView;
            holder = (ChildViewHolder) view.getTag();
        }
        final CartsBean.DataBean.ListBean datasBean = list.get(groupPosition).getList().get(childPosition);
        holder.cbChild.setChecked(datasBean.isChecked());
        holder.tv_intro.setText(datasBean.getTitle());
        holder.tv_price.setText("¥"+datasBean.getPrice() );
        holder.tv_num.setText(datasBean.getNum() + "");
        //        holder.et_num.setText(datasBean.getNum() + "");
        holder.adv.setNumber(datasBean.getNum());
        String[] split = datasBean.getImages().split("[|]");
        holder.imgIcon.setImageURI(Uri.parse(split[0]));

        //二级checkbox
        holder.cbChild.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //设置该条目对象里的checked属性值
                datasBean.setChecked(holder.cbChild.isChecked());
                PriceAndCountEvent priceAndCountEvent = compute();
                EventBus.getDefault().post(priceAndCountEvent);
                if (holder.cbChild.isChecked()) {
                    //当前checkbox是选中状态
                    if (isAllChildCbSelected(groupPosition)) {
                        changGroupCbState(groupPosition, true);
                        changeAllCbState(isAllGroupCbSelected());
                    }
                    totalCount++;
                } else {
                    changGroupCbState(groupPosition, false);
                    changeAllCbState(isAllGroupCbSelected());
                }
                notifyDataSetChanged();
            }
        });

        holder.adv.setOnAddDelClickListener(new AddDeleteView.OnAddDelClickListener() {
            @Override
            public void onAddClick(View v) {
                Log.i("zxz", "onAddClick: 执行");
                int origin = holder.adv.getNumber();
                origin++;
                //holder.adv.setNumber(origin);
                int num = datasBean.getNum();
                num++;
                holder.adv.setNumber(num);
                datasBean.setNum(num);
                if (holder.cbChild.isChecked()) {
                    EventBus.getDefault().post(compute());
                }
            }

            @Override
            public void onDelClick(View v) {
                int origin = holder.adv.getNumber();
                //                int num = datasBean.getNum();
                origin--;
                if (origin == 0) {
                    Toast.makeText(context,"最小数量为1", Toast.LENGTH_SHORT).show();
                    return ;
                }
                holder.adv.setNumber(origin);
                datasBean.setNum(origin);
                if (holder.cbChild.isChecked()) {
                    EventBus.getDefault().post(compute());
                }
            }
        });
        //删除
        holder.tv_del.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog alert;
                alert = new AlertDialog.Builder(context).create();
                alert.setTitle("操作提示");
                alert.setMessage("您确定要将这些商品从购物车中移除吗?");
                alert.setButton(DialogInterface.BUTTON_NEGATIVE, "取消",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                return;
                            }
                        });
                alert.setButton(DialogInterface.BUTTON_POSITIVE, "确定",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                List<CartsBean.DataBean.ListBean> datasBeen = list.get(groupPosition)
                                            .getList();
                                CartsBean.DataBean.ListBean remove = datasBeen.remove(childPosition);
                                if (datasBeen.size() == 0) {
                                    list.remove(groupPosition);
                                }
                                EventBus.getDefault().post(compute());
                                notifyDataSetChanged();
                            }
                        });
                alert.show();
            }
        });

        //编辑
        //判断是否在编辑状态下(标题中的编辑)
        if (list.get(groupPosition).isEdtor() == true) {
            holder.ll_edtor.setVisibility(View.VISIBLE);
            holder.rl_no_edtor.setVisibility(View.GONE);
        } else {
            holder.ll_edtor.setVisibility(View.GONE);
            holder.rl_no_edtor.setVisibility(View.VISIBLE);
        }
        return view;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }

    class GroupViewHolder {
        CheckBox determine_chekbox;
        TextView tv_source_name,tv_store_edtor;
    }
    //使某个组处于编辑状态
    class GroupViewClick implements View.OnClickListener {
        private int groupPosition;
        private TextView edtor;
        private CartsBean.DataBean group;

        public GroupViewClick(int groupPosition, TextView edtor, CartsBean.DataBean group) {
            this.groupPosition = groupPosition;
            this.edtor = edtor;
            this.group = group;
        }

        @Override
        public void onClick(View v) {
            int groupId = v.getId();
            if (groupId == edtor.getId()) {
                if (group.isEdtor()) {
                    group.setEdtor(false);
                } else {
                    group.setEdtor(true);
                }
                notifyDataSetChanged();
            }
        }
    }

    /**
     * 监听编辑状态
     */
    public interface GroupEdtorListener {
        void groupEdit(int groupPosition);
    }

    class ChildViewHolder {
        CheckBox cbChild;
        TextView tv_intro;
        SimpleDraweeView imgIcon;
        TextView tv_price;
        TextView tv_del;
        ImageView bt_del,bt_add;
        EditText et_num;
        //        TextView tv_num;
        LinearLayout ll_edtor;
        RelativeLayout rl_no_edtor;
        AddDeleteView adv;
        ImageView iv_del;
        ImageView iv_add;
        TextView tv_num;
    }

    /**
     * 改变全选的状态
     * @param flag
     */
    private void changeAllCbState(boolean flag) {
        MessageEvent messageEvent = new MessageEvent();
        messageEvent.setChecked(flag);
        EventBus.getDefault().post(messageEvent);
    }

    /**
     * 改变一级列表checkbox状态
     * @param groupPosition
     */
    private void changGroupCbState(int groupPosition, boolean flag) {
        CartsBean.DataBean dataBean = list.get(groupPosition);
        dataBean.setChecked(flag);
    }

    /**
     * 改变二级列表checkbox状态
     * @param groupPosition
     * @param flag
     */
    private void changeChildCbState(int groupPosition, boolean flag) {
        List<CartsBean.DataBean.ListBean> datasBeen = list.get(groupPosition).getList();
        for (int i = 0; i < datasBeen.size(); i++) {
            CartsBean.DataBean.ListBean datasBean = datasBeen.get(i);
            datasBean.setChecked(flag);
        }
    }

    /**
     * 判断一级列表是否全部选中
     * @return
     */
    private boolean isAllGroupCbSelected() {
        for (int i = 0; i < list.size(); i++) {
            CartsBean.DataBean dataBean = list.get(i);
            if (!dataBean.isChecked()) {
                return false;
            }
        }
        return true;
    }

    /**
     * 判断二级列表是否全部选中
     * @param groupPosition
     * @return
     */
    private boolean isAllChildCbSelected(int groupPosition) {
        List<CartsBean.DataBean.ListBean> datasBeen = list.get(groupPosition).getList();
        for (int i = 0; i < datasBeen.size(); i++) {
            CartsBean.DataBean.ListBean datasBean = datasBeen.get(i);
            if (!datasBean.isChecked()) {
                return false;
            }
        }
        return true;
    }

    /**
     * 计算列表中,选中的钱和数量
     */
    private PriceAndCountEvent compute() {
        int count = 0;
        int price = 0;
        for (int i = 0; i < list.size(); i++) {
            List<CartsBean.DataBean.ListBean> datasBeen = list.get(i).getList();
            for (int j = 0; j < datasBeen.size(); j++) {
                CartsBean.DataBean.ListBean datasBean = datasBeen.get(j);
                if (datasBean.isChecked()) {
                    price += datasBean.getNum() * datasBean.getPrice();
                    count += datasBean.getNum();
                }
            }
        }
        PriceAndCountEvent priceAndCountEvent = new PriceAndCountEvent();
        priceAndCountEvent.setCount(count);
        priceAndCountEvent.setPrice(price);
        return priceAndCountEvent;
    }

    /**
     * 设置全选、反选
     * @param flag
     */
    public void changeAllListCbState(boolean flag) {
        for (int i = 0; i < list.size(); i++) {
            changGroupCbState(i, flag);
            changeChildCbState(i, flag);
        }
        EventBus.getDefault().post(compute());
        notifyDataSetChanged();
    }

    /**
     * 是否显示可编辑
     * @param flag
     */
    public void isShow(boolean flag) {
        isShow = flag;
        notifyDataSetChanged();
    }
}

ShowAdapter

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bwie.test.bean.ProductsBean;
import com.bwie.test.mymoni_yuekao.R;
import com.facebook.drawee.view.SimpleDraweeView;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;

public class ShowAdapter extends RecyclerView.Adapter<ShowAdapter.ViewHolder> {
    private Context context;
    private List<ProductsBean.DataBean> list;

    public ShowAdapter(Context context, List<ProductsBean.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    private OnItemClickListener mOnItemClickListener;

    public interface OnItemClickListener{
        void onClick(int position);
        void onLongClick(int position);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener ){
        this. mOnItemClickListener=onItemClickListener;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.show_item, null);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        String[] split = list.get(position).getImages().split("[|]");
        holder.itemImg.setImageURI(split[0]);
        holder.itemPrice.setText("¥"+list.get(position).getPrice());
        holder.itemTitle.setText(list.get(position).getTitle());
        if( mOnItemClickListener!= null){
            holder.itemView.setOnClickListener( new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mOnItemClickListener.onClick(position);
                }
            });
            holder. itemView.setOnLongClickListener( new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    mOnItemClickListener.onLongClick(position);
                    return false;
                }
            });
        }
    }

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

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.item_img)
        SimpleDraweeView itemImg;
        @BindView(R.id.item_price)
        TextView itemPrice;
        @BindView(R.id.item_title)
        TextView itemTitle;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}

sqldao文件夹下DaoMaster

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.util.Log;
import org.greenrobot.greendao.AbstractDaoMaster;
import org.greenrobot.greendao.database.StandardDatabase;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseOpenHelper;
import org.greenrobot.greendao.identityscope.IdentityScopeType;

public class DaoMaster extends AbstractDaoMaster {
    public static final int SCHEMA_VERSION = 1;

    public static void createAllTables(Database db, boolean ifNotExists) {
        DataBeanDao.createTable(db, ifNotExists);
    }

    public static void dropAllTables(Database db, boolean ifExists) {
        DataBeanDao.dropTable(db, ifExists);
    }

    public static DaoSession newDevSession(Context context, String name) {
        Database db = new DevOpenHelper(context, name).getWritableDb();
        DaoMaster daoMaster = new DaoMaster(db);
        return daoMaster.newSession();
    }

    public DaoMaster(SQLiteDatabase db) {
        this(new StandardDatabase(db));
    }

    public DaoMaster(Database db) {
        super(db, SCHEMA_VERSION);
        registerDaoClass(DataBeanDao.class);
    }

    public DaoSession newSession() {
        return new DaoSession(db, IdentityScopeType.Session, daoConfigMap);
    }

    public DaoSession newSession(IdentityScopeType type) {
        return new DaoSession(db, type, daoConfigMap);
    }

    public static abstract class OpenHelper extends DatabaseOpenHelper {
        public OpenHelper(Context context, String name) {
            super(context, name, SCHEMA_VERSION);
        }

        public OpenHelper(Context context, String name, CursorFactory factory) {
            super(context, name, factory, SCHEMA_VERSION);
        }

        @Override
        public void onCreate(Database db) {
            Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION);
            createAllTables(db, false);
        }
    }

    public static class DevOpenHelper extends OpenHelper {
        public DevOpenHelper(Context context, String name) {
            super(context, name);
        }

        public DevOpenHelper(Context context, String name, CursorFactory factory) {
            super(context, name, factory);
        }

        @Override
        public void onUpgrade(Database db, int oldVersion, int newVersion) {
            Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion 
                                    + " by dropping all tables");
            dropAllTables(db, true);
            onCreate(db);
        }
    }
}

DaoSession

import com.bwie.test.bean.DataBean;
import java.util.Map;
import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.AbstractDaoSession;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.identityscope.IdentityScopeType;
import org.greenrobot.greendao.internal.DaoConfig;

public class DaoSession extends AbstractDaoSession {
    private final DaoConfig dataBeanDaoConfig;
    private final DataBeanDao dataBeanDao;

    public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>,
                          DaoConfig> daoConfigMap) {
        super(db);
        dataBeanDaoConfig = daoConfigMap.get(DataBeanDao.class).clone();
        dataBeanDaoConfig.initIdentityScope(type);
        dataBeanDao = new DataBeanDao(dataBeanDaoConfig, this);
        registerDao(DataBean.class, dataBeanDao);
    }
    
    public void clear() {
        dataBeanDaoConfig.clearIdentityScope();
    }

    public DataBeanDao getDataBeanDao() {
        return dataBeanDao;
    }
}

DataBeanDao

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;
import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import com.bwie.test.bean.DataBean;

public class DataBeanDao extends AbstractDao<DataBean, Long> {
    public static final String TABLENAME = "DATA_BEAN";

    public static class Properties {
        public final static Property Cid = new Property(0, Long.class, "cid", true, "_id");
        public final static Property Title = new Property(1, String.class, "title", false, "TITLE");
    }

    public DataBeanDao(DaoConfig config) {
        super(config);
    }
    
    public DataBeanDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"DATA_BEAN\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: cid
                "\"TITLE\" TEXT);"); // 1: title
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"DATA_BEAN\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, DataBean entity) {
        stmt.clearBindings();
        Long cid = entity.getCid();
        if (cid != null) {
            stmt.bindLong(1, cid);
        }
 
        String title = entity.getTitle();
        if (title != null) {
            stmt.bindString(2, title);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, DataBean entity) {
        stmt.clearBindings();
        Long cid = entity.getCid();
        if (cid != null) {
            stmt.bindLong(1, cid);
        }
 
        String title = entity.getTitle();
        if (title != null) {
            stmt.bindString(2, title);
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public DataBean readEntity(Cursor cursor, int offset) {
        DataBean entity = new DataBean( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // cid
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1) // title
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, DataBean entity, int offset) {
        entity.setCid(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setTitle(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(DataBean entity, long rowId) {
        entity.setCid(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(DataBean entity) {
        if(entity != null) {
            return entity.getCid();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(DataBean entity) {
        return entity.getCid() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
}

utils文件夹下ApiService

import com.bwie.test.bean.AddBean;
import com.bwie.test.bean.CartsBean;
import com.bwie.test.bean.DeleteBean;
import com.bwie.test.bean.DinganBean;
import com.bwie.test.bean.ProductsBean;
import com.bwie.test.bean.ShowsBean;

import java.util.Map;
import io.reactivex.Flowable;
import retrofit2.http.GET;
import retrofit2.http.QueryMap;

public interface ApiService {
    //https://www.zhaoapi.cn/product/getProducts?pscid=39&page=1
    @GET("product/getProducts")
    Flowable<ProductsBean> getProduct(@QueryMap Map<String, String> map);

    //https://www.zhaoapi.cn/product/getProductDetail?pid=45&source=android
    @GET("product/getProductDetail")
    Flowable<ShowsBean> getShows(@QueryMap Map<String, String> map);

    //http://120.27.23.105/product/addCart?uid=101&pid=45&source=android
    @GET("product/addCart")
    Flowable<AddBean> getAdd(@QueryMap Map<String, String> map);

    // http://120.27.23.105/product/getCarts?uid=75&source=android
    @GET("product/getCarts")
    Flowable<CartsBean> getCarts(@QueryMap Map<String, String> map);

    //http://120.27.23.105/product/deleteCart?uid=101&pid=45&source=android
    @GET("product/deleteCart")
    Flowable<DeleteBean> getDelete(@QueryMap Map<String, String> map);

    //http://120.27.23.105/product/getOrders?uid=71
    @GET("product/getOrders")
    Flowable<DinganBean> getDingdan(@QueryMap Map<String, String> map);
}

RetrofitUtils

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class RetrofitUtils {
    private static volatile RetrofitUtils instance;
    private final ApiService apiService;

    private RetrofitUtils(String baseUrl){
        OkHttpClient client = new OkHttpClient();
        Retrofit retrofit = new Retrofit.Builder()
                .client(client)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .baseUrl(baseUrl)
                .build();
        apiService = retrofit.create(ApiService.class);
    }

    public static RetrofitUtils getInstance(String baseUrl){
        if (instance==null){
            synchronized (RetrofitUtils.class){
                if (null == instance){
                    instance = new RetrofitUtils(baseUrl);
                }
            }
        }
        return instance;
    }

    public ApiService getApiService(){
        return apiService;
    }
}

bean文件夹下AddBean

public class AddBean {

    private String msg;
    private String code;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }
}
CartBean

import java.io.Serializable;
import java.util.List;

public class CartBean {

    private String code;
    private String msg;
    private List<DataBean> data;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public List<DataBean> getData() {
        return data;
    }

    public void setData(List<DataBean> data) {
        this.data = data;
    }

    public static class DataBean {

        //自己手动创建一个变量 生成set get方法....记录组的checkBox是否选中
        private boolean isGroupChecked;

        public boolean isGroupChecked() {
            return isGroupChecked;
        }

        public void setGroupChecked(boolean groupChecked) {
            isGroupChecked = groupChecked;
        }

        private String sellerName;
        private String sellerid;
        private List<ListBean> list;

        public String getSellerName() {
            return sellerName;
        }

        public void setSellerName(String sellerName) {
            this.sellerName = sellerName;
        }

        public String getSellerid() {
            return sellerid;
        }

        public void setSellerid(String sellerid) {
            this.sellerid = sellerid;
        }

        public List<ListBean> getList() {
            return list;
        }

        public void setList(List<ListBean> list) {
            this.list = list;
        }

        public static class ListBean implements Serializable {

            private double bargainPrice;
            private String createtime;
            private String detailUrl;
            private String images;
            private int num;
            private int pid;
            private double price;
            private int pscid;
            private int selected;
            private int sellerid;
            private String subhead;
            private String title;

            public double getBargainPrice() {
                return bargainPrice;
            }

            public void setBargainPrice(double bargainPrice) {
                this.bargainPrice = bargainPrice;
            }

            public String getCreatetime() {
                return createtime;
            }

            public void setCreatetime(String createtime) {
                this.createtime = createtime;
            }

            public String getDetailUrl() {
                return detailUrl;
            }

            public void setDetailUrl(String detailUrl) {
                this.detailUrl = detailUrl;
            }

            public String getImages() {
                return images;
            }

            public void setImages(String images) {
                this.images = images;
            }

            public int getNum() {
                return num;
            }

            public void setNum(int num) {
                this.num = num;
            }

            public int getPid() {
                return pid;
            }

            public void setPid(int pid) {
                this.pid = pid;
            }

            public double getPrice() {
                return price;
            }

            public void setPrice(double price) {
                this.price = price;
            }

            public int getPscid() {
                return pscid;
            }

            public void setPscid(int pscid) {
                this.pscid = pscid;
            }

            public int getSelected() {
                return selected;
            }

            public void setSelected(int selected) {
                this.selected = selected;
            }

            public int getSellerid() {
                return sellerid;
            }

            public void setSellerid(int sellerid) {
                this.sellerid = sellerid;
            }

            public String getSubhead() {
                return subhead;
            }

            public void setSubhead(String subhead) {
                this.subhead = subhead;
            }

            public String getTitle() {
                return title;
            }

            public void setTitle(String title) {
                this.title = title;
            }
        }
    }
}

CartsBean

import java.util.List;

public class CartsBean {

    private String msg;
    private String code;
    private List<DataBean> data;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public List<DataBean> getData() {
        return data;
    }

    public void setData(List<DataBean> data) {
        this.data = data;
    }

    public static class DataBean {

        private boolean checked;
        private boolean edtor;
        private String sellerName;
        private String sellerid;
        private List<ListBean> list;

        public boolean isChecked() {
            return checked;
        }

        public void setChecked(boolean checked) {
            this.checked = checked;
        }

        public boolean isEdtor() {
            return edtor;
        }

        public void setEdtor(boolean edtor) {
            this.edtor = edtor;
        }

        public String getSellerName() {
            return sellerName;
        }

        public void setSellerName(String sellerName) {
            this.sellerName = sellerName;
        }

        public String getSellerid() {
            return sellerid;
        }

        public void setSellerid(String sellerid) {
            this.sellerid = sellerid;
        }

        public List<ListBean> getList() {
            return list;
        }

        public void setList(List<ListBean> list) {
            this.list = list;
        }

        public static class ListBean {

            private boolean checked;
            private boolean edtor;
            private double bargainPrice;
            private String createtime;
            private String detailUrl;
            private String images;
            private int num;
            private int pid;
            private double price;
            private int pscid;
            private int selected;
            private int sellerid;
            private String subhead;
            private String title;

            public boolean isChecked() {
                return checked;
            }

            public void setChecked(boolean checked) {
                this.checked = checked;
            }

            public boolean isEdtor() {
                return edtor;
            }

            public void setEdtor(boolean edtor) {
                this.edtor = edtor;
            }

            public double getBargainPrice() {
                return bargainPrice;
            }

            public void setBargainPrice(double bargainPrice) {
                this.bargainPrice = bargainPrice;
            }

            public String getCreatetime() {
                return createtime;
            }

            public void setCreatetime(String createtime) {
                this.createtime = createtime;
            }

            public String getDetailUrl() {
                return detailUrl;
            }

            public void setDetailUrl(String detailUrl) {
                this.detailUrl = detailUrl;
            }

            public String getImages() {
                return images;
            }

            public void setImages(String images) {
                this.images = images;
            }

            public int getNum() {
                return num;
            }

            public void setNum(int num) {
                this.num = num;
            }

            public int getPid() {
                return pid;
            }

            public void setPid(int pid) {
                this.pid = pid;
            }

            public double getPrice() {
                return price;
            }

            public void setPrice(double price) {
                this.price = price;
            }

            public int getPscid() {
                return pscid;
            }

            public void setPscid(int pscid) {
                this.pscid = pscid;
            }

            public int getSelected() {
                return selected;
            }

            public void setSelected(int selected) {
                this.selected = selected;
            }

            public int getSellerid() {
                return sellerid;
            }

            public void setSellerid(int sellerid) {
                this.sellerid = sellerid;
            }

            public String getSubhead() {
                return subhead;
            }

            public void setSubhead(String subhead) {
                this.subhead = subhead;
            }

            public String getTitle() {
                return title;
            }

            public void setTitle(String title) {
                this.title = title;
            }
        }
    }
}

CountPriceBean

public class CountPriceBean {
    private String priceString;
    private int count;

    public CountPriceBean(String priceString, int count) {
        this.priceString = priceString;
        this.count = count;
    }

    public String getPriceString() {
        return priceString;
    }

    public void setPriceString(String priceString) {
        this.priceString = priceString;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }
}

DataBean

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;

@Entity
public class DataBean {
    @Id(autoincrement = true)
    private Long cid;
    private String title;

    @Generated(hash = 1136319213)
    public DataBean(Long cid, String title) {
        this.cid = cid;
        this.title = title;
    }

    @Generated(hash = 908697775)
    public DataBean() {
    }

    public Long getCid() {
        return this.cid;
    }

    public void setCid(Long cid) {
        this.cid = cid;
    }

    public String getTitle() {
        return this.title;
    }

    public void setTitle(String title) {
        this.title = title;
    }
}

DeleteBean

public class DeleteBean {

    private String msg;
    private String code;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }
}

DinganBean

import java.util.List;

public class DinganBean {

    private String msg;
    private String code;
    private String page;
    private List<DataBean> data;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getPage() {
        return page;
    }

    public void setPage(String page) {
        this.page = page;
    }

    public List<DataBean> getData() {
        return data;
    }

    public void setData(List<DataBean> data) {
        this.data = data;
    }

    public static class DataBean {

        private String createtime;
        private int orderid;
        private double price;
        private int status;
        private String title;
        private int uid;

        public String getCreatetime() {
            return createtime;
        }

        public void setCreatetime(String createtime) {
            this.createtime = createtime;
        }

        public int getOrderid() {
            return orderid;
        }

        public void setOrderid(int orderid) {
            this.orderid = orderid;
        }

        public double getPrice() {
            return price;
        }

        public void setPrice(double price) {
            this.price = price;
        }

        public int getStatus() {
            return status;
        }

        public void setStatus(int status) {
            this.status = status;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public int getUid() {
            return uid;
        }

        public void setUid(int uid) {
            this.uid = uid;
        }
    }
}

MessageBean

public class MessageBean<T> {

    private String msg;
    private String code;
    private String page;
    private T data;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getPage() {
        return page;
    }

    public void setPage(String page) {
        this.page = page;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public MessageBean(String msg, String code, String page, T data) {

        this.msg = msg;
        this.code = code;
        this.page = page;
        this.data = data;
    }
}

MessageEvent

public class MessageEvent {
    private boolean checked;

    public boolean isChecked() {
        return checked;
    }

    public void setChecked(boolean checked) {
        this.checked = checked;
    }
}

PriceAndCountEvent

public class PriceAndCountEvent {
    private int price;
    private int count;

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }
}

ProductsBean

import java.util.List;

public class ProductsBean {

    private String msg;
    private String code;
    private String page;
    private List<DataBean> data;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getPage() {
        return page;
    }

    public void setPage(String page) {
        this.page = page;
    }

    public List<DataBean> getData() {
        return data;
    }

    public void setData(List<DataBean> data) {
        this.data = data;
    }

    public static class DataBean {

        private double bargainPrice;
        private String createtime;
        private String detailUrl;
        private String images;
        private int itemtype;
        private int pid;
        private double price;
        private int pscid;
        private int salenum;
        private int sellerid;
        private String subhead;
        private String title;

        public double getBargainPrice() {
            return bargainPrice;
        }

        public void setBargainPrice(double bargainPrice) {
            this.bargainPrice = bargainPrice;
        }

        public String getCreatetime() {
            return createtime;
        }

        public void setCreatetime(String createtime) {
            this.createtime = createtime;
        }

        public String getDetailUrl() {
            return detailUrl;
        }

        public void setDetailUrl(String detailUrl) {
            this.detailUrl = detailUrl;
        }

        public String getImages() {
            return images;
        }

        public void setImages(String images) {
            this.images = images;
        }

        public int getItemtype() {
            return itemtype;
        }

        public void setItemtype(int itemtype) {
            this.itemtype = itemtype;
        }

        public int getPid() {
            return pid;
        }

        public void setPid(int pid) {
            this.pid = pid;
        }

        public double getPrice() {
            return price;
        }

        public void setPrice(double price) {
            this.price = price;
        }

        public int getPscid() {
            return pscid;
        }

        public void setPscid(int pscid) {
            this.pscid = pscid;
        }

        public int getSalenum() {
            return salenum;
        }

        public void setSalenum(int salenum) {
            this.salenum = salenum;
        }

        public int getSellerid() {
            return sellerid;
        }

        public void setSellerid(int sellerid) {
            this.sellerid = sellerid;
        }

        public String getSubhead() {
            return subhead;
        }

        public void setSubhead(String subhead) {
            this.subhead = subhead;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }
    }
}

ShowsBean

public class ShowsBean {

    private String msg;
    private SellerBean seller;
    private String code;
    private DataBean data;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public SellerBean getSeller() {
        return seller;
    }

    public void setSeller(SellerBean seller) {
        this.seller = seller;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public DataBean getData() {
        return data;
    }

    public void setData(DataBean data) {
        this.data = data;
    }

    public static class SellerBean {

        private String description;
        private String icon;
        private String name;
        private int productNums;
        private double score;
        private int sellerid;

        public String getDescription() {
            return description;
        }

        public void setDescription(String description) {
            this.description = description;
        }

        public String getIcon() {
            return icon;
        }

        public void setIcon(String icon) {
            this.icon = icon;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getProductNums() {
            return productNums;
        }

        public void setProductNums(int productNums) {
            this.productNums = productNums;
        }

        public double getScore() {
            return score;
        }

        public void setScore(double score) {
            this.score = score;
        }

        public int getSellerid() {
            return sellerid;
        }

        public void setSellerid(int sellerid) {
            this.sellerid = sellerid;
        }
    }

    public static class DataBean {

        private double bargainPrice;
        private String createtime;
        private String detailUrl;
        private String images;
        private int itemtype;
        private int pid;
        private double price;
        private int pscid;
        private int salenum;
        private int sellerid;
        private String subhead;
        private String title;

        public double getBargainPrice() {
            return bargainPrice;
        }

        public void setBargainPrice(double bargainPrice) {
            this.bargainPrice = bargainPrice;
        }

        public String getCreatetime() {
            return createtime;
        }

        public void setCreatetime(String createtime) {
            this.createtime = createtime;
        }

        public String getDetailUrl() {
            return detailUrl;
        }

        public void setDetailUrl(String detailUrl) {
            this.detailUrl = detailUrl;
        }

        public String getImages() {
            return images;
        }

        public void setImages(String images) {
            this.images = images;
        }

        public int getItemtype() {
            return itemtype;
        }

        public void setItemtype(int itemtype) {
            this.itemtype = itemtype;
        }

        public int getPid() {
            return pid;
        }

        public void setPid(int pid) {
            this.pid = pid;
        }

        public double getPrice() {
            return price;
        }

        public void setPrice(double price) {
            this.price = price;
        }

        public int getPscid() {
            return pscid;
        }

        public void setPscid(int pscid) {
            this.pscid = pscid;
        }

        public int getSalenum() {
            return salenum;
        }

        public void setSalenum(int salenum) {
            this.salenum = salenum;
        }

        public int getSellerid() {
            return sellerid;
        }

        public void setSellerid(int sellerid) {
            this.sellerid = sellerid;
        }

        public String getSubhead() {
            return subhead;
        }

        public void setSubhead(String subhead) {
            this.subhead = subhead;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值