Browse Source

添加优惠券

詹子聪 5 years ago
parent
commit
e2232a7d7f

+ 25 - 0
app/src/main/AndroidManifest.xml

@@ -26,6 +26,31 @@
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
+
+        <!--添加优惠券-->
+        <activity android:name=".ui.home.more.add.AddCouponActivity"
+            android:configChanges="orientation|screenSize|keyboardHidden"
+            android:screenOrientation="portrait"/>
+
+        <!--忘记密码-->
+        <activity android:name=".ui.home.more.forget.ForgetActivity"
+            android:configChanges="orientation|screenSize|keyboardHidden"
+            android:screenOrientation="portrait"/>
+
+        <!--登录-->
+        <activity android:name=".ui.home.more.login.LoginActivity"
+            android:configChanges="orientation|screenSize|keyboardHidden"
+            android:screenOrientation="portrait"/>
+
+        <!--完善资料-->
+        <activity android:name=".ui.home.more.register.fill.FillDataActivity"
+            android:configChanges="orientation|screenSize|keyboardHidden"
+            android:screenOrientation="portrait"/>
+
+        <!--注册-->
+        <activity android:name=".ui.home.more.register.RegisterActivity"
+            android:configChanges="orientation|screenSize|keyboardHidden"
+            android:screenOrientation="portrait"/>
     </application>
 
 </manifest>

+ 2 - 1
app/src/main/java/com/miekir/ym/ui/home/coupon/CouponPresenter.java

@@ -39,6 +39,8 @@ public class CouponPresenter extends BasePresenter<ICouponView<CouponBean>> {
             }
         };
 
+        mProgressDisposableList.add(disposable);
+
         RetrofitHelper.getInstance()
                 .getRequestApi(ApiService.class)
                 .getCouponList(pageNum, pageSize)
@@ -46,7 +48,6 @@ public class CouponPresenter extends BasePresenter<ICouponView<CouponBean>> {
                 .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(disposable);
 
-        mProgressDisposableList.add(disposable);
     }
 
 

+ 78 - 0
app/src/main/java/com/miekir/ym/ui/home/more/MineActivity.java

@@ -0,0 +1,78 @@
+package com.miekir.ym.ui.home.more;
+
+
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.view.View;
+
+import androidx.appcompat.app.AlertDialog;
+
+import com.miekir.common.utils.ViewTool;
+import com.miekir.ym.R;
+import com.miekir.ym.base.YangActivity;
+import com.miekir.ym.bean.BeiUser;
+import com.miekir.ym.manager.UserInfoManager;
+import com.miekir.ym.ui.home.more.add.AddCouponActivity;
+
+public class MineActivity extends YangActivity implements View.OnClickListener {
+    private BeiUser mUser;
+
+    @Override
+    public int getLayoutId() {
+        return R.layout.activity_mine;
+    }
+
+    @Override
+    public void initViews(Bundle savedInstanceState) {
+        mUser = UserInfoManager.getInstance().getBeiUser();
+        setTitle("个人中心");
+        ViewTool.setOnClickListener(this, this,
+                new int[]{R.id.tv_my_fav, R.id.btn_exit_login, R.id.tv_add_coupon});
+
+        // 只有我才能管理后台
+        View ll_admin = findViewById(R.id.ll_admin);
+        if (TextUtils.equals("[email protected]", mUser.email)) {
+            ll_admin.setVisibility(View.VISIBLE);
+        } else {
+            ll_admin.setVisibility(View.GONE);
+        }
+    }
+
+    @Override
+    public void onClick(View v) {
+        switch (v.getId()) {
+
+            case R.id.tv_my_fav:
+                // todo 我的收藏
+                break;
+
+            case R.id.tv_add_coupon:
+                // 上架优惠券
+                startActivity(new Intent(this, AddCouponActivity.class));
+                break;
+
+            case R.id.btn_exit_login:
+                sureToExit();
+                break;
+            default:
+                break;
+        }
+    }
+
+    /**
+     * 确认退出登录
+     */
+    private void sureToExit() {
+        AlertDialog alertDialog = new AlertDialog.Builder(this)
+               .setMessage("确定退出当前账号?")
+               .setNegativeButton("取消", (dialog, which) -> dialog.dismiss())
+               .setPositiveButton("确定", (DialogInterface dialog, int which) -> {
+            dialog.dismiss();
+            UserInfoManager.getInstance().setBeiUser(null);
+            finish();
+        }).create();
+        alertDialog.show();
+    }
+}

+ 104 - 0
app/src/main/java/com/miekir/ym/ui/home/more/add/AddCouponActivity.java

@@ -0,0 +1,104 @@
+package com.miekir.ym.ui.home.more.add;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
+import android.widget.CheckBox;
+
+import com.google.android.material.textfield.TextInputEditText;
+import com.miekir.common.utils.ToastTool;
+import com.miekir.common.utils.ViewTool;
+import com.miekir.mvp.presenter.InjectPresenter;
+import com.miekir.ym.R;
+import com.miekir.ym.base.YangActivity;
+import com.miekir.ym.ui.home.coupon.CouponBean;
+
+/**
+ * @author Miekir
+ * @date 2020/6/18 16:48
+ * Description: 添加优惠券界面
+ */
+public class AddCouponActivity extends YangActivity implements View.OnClickListener, IAddCouponView {
+    public static final String KEY_MODIFY_COUPON = "key_modify_coupon";
+
+    private TextInputEditText et_coupon_title;
+    private TextInputEditText et_cover_url;
+    private TextInputEditText et_jump_url;
+
+    private CheckBox cb_enable;
+
+    private CouponBean couponBean;
+
+    @InjectPresenter
+    AddCouponPresenter presenter;
+
+    @Override
+    public int getLayoutId() {
+        return R.layout.activity_coupon_add;
+    }
+
+    @Override
+    public void initViews(Bundle savedInstanceState) {
+
+        et_coupon_title = findViewById(R.id.et_coupon_title);
+        et_cover_url = findViewById(R.id.et_cover_url);
+        et_jump_url = findViewById(R.id.et_jump_url);
+        cb_enable = findViewById(R.id.cb_enable);
+        ViewTool.setOnClickListener(this, this, new int[]{R.id.btn_add_goods});
+        Button btn_add_goods = findViewById(R.id.btn_add_goods);
+
+        couponBean = (CouponBean) getIntent().getSerializableExtra(KEY_MODIFY_COUPON);
+        if (couponBean != null) {
+            initCoupon();
+            setTitle("更新优惠券");
+            btn_add_goods.setText("立即更新");
+        } else {
+            setTitle("上架新的优惠券");
+        }
+    }
+
+    private void initCoupon() {
+        et_coupon_title.setText(couponBean.couponName);
+        et_cover_url.setText(couponBean.coverUrl);
+        et_jump_url.setText(couponBean.jumpUrl);
+        cb_enable.setChecked(couponBean.actionEnable);
+    }
+
+    @Override
+    public void onClick(View v) {
+        switch (v.getId()) {
+            case R.id.btn_add_goods:
+                String title = et_coupon_title.getEditableText().toString();
+                String coverUrl = et_cover_url.getEditableText().toString();
+                String jumpUrl = et_jump_url.getEditableText().toString();
+                boolean isEnable = cb_enable.isChecked();
+
+                if (couponBean == null) {
+                    couponBean = new CouponBean();
+                }
+                couponBean.couponName = title;
+                couponBean.coverUrl = coverUrl;
+                couponBean.jumpUrl = jumpUrl;
+                couponBean.actionEnable = isEnable;
+
+                showLoading();
+                presenter.addCoupon(couponBean);
+                break;
+            default:
+                break;
+        }
+    }
+
+    @Override
+    public void onAddCouponResult(boolean success, String message) {
+        hideLoading();
+        ToastTool.showShort(message);
+        if (success) {
+            Intent intent = getIntent();
+            intent.putExtra(KEY_MODIFY_COUPON, couponBean);
+            setResult(RESULT_OK, intent);
+            finish();
+        }
+    }
+}

+ 49 - 0
app/src/main/java/com/miekir/ym/ui/home/more/add/AddCouponPresenter.java

@@ -0,0 +1,49 @@
+package com.miekir.ym.ui.home.more.add;
+
+import android.text.TextUtils;
+
+import com.miekir.mvp.presenter.BasePresenter;
+import com.miekir.network.RetrofitHelper;
+import com.miekir.network.widget.observe.NetMvpObserver;
+import com.miekir.ym.base.ApiService;
+import com.miekir.ym.ui.home.coupon.CouponBean;
+
+import io.reactivex.android.schedulers.AndroidSchedulers;
+import io.reactivex.schedulers.Schedulers;
+
+/**
+ * @author Miekir
+ * @date 2020/7/9 20:54
+ * Description: 商品的相关数据接口处理
+ */
+public class AddCouponPresenter extends BasePresenter<IAddCouponView> {
+
+    public void addCoupon(CouponBean couponBean) {
+        NetMvpObserver<String> observer = new NetMvpObserver<String>() {
+            @Override
+            public void onSuccess(int code, String result) {
+                post(view -> view.onAddCouponResult(true, result));
+            }
+
+            @Override
+            public void onFailure(int code, Throwable e, String errMsg) {
+                post(view -> view.onAddCouponResult(false, TextUtils.isEmpty(errMsg) ? "操作失败"+e.getMessage() : errMsg));
+            }
+        };
+
+        mProgressDisposableList.add(observer);
+
+        RetrofitHelper.getInstance()
+                .getRequestApi(ApiService.class)
+                .addCoupon(couponBean)
+                .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
+                .subscribe(observer);
+
+    }
+
+    @Override
+    public void onInit() {
+
+    }
+}

+ 18 - 0
app/src/main/java/com/miekir/ym/ui/home/more/add/IAddCouponView.java

@@ -0,0 +1,18 @@
+package com.miekir.ym.ui.home.more.add;
+
+import com.miekir.mvp.view.IView;
+
+/**
+ * Copyright (C), 2019-2020, Miekir
+ *
+ * @author Miekir
+ * @date 2020/8/2 10:29
+ */
+public interface IAddCouponView extends IView {
+    /**
+     * 增加优惠券的结果
+     * @param success
+     * @param message
+     */
+    void onAddCouponResult(boolean success, String message);
+}

+ 2 - 1
app/src/main/java/com/miekir/ym/ui/home/more/forget/ForgetPresenter.java

@@ -34,6 +34,8 @@ public class ForgetPresenter extends BasePresenter<IForgetView> {
             }
         };
 
+        mProgressDisposableList.add(observer);
+
         Map<String, Object> map = new HashMap<>();
         map.put("email", email);
         map.put("code", code);
@@ -45,7 +47,6 @@ public class ForgetPresenter extends BasePresenter<IForgetView> {
                 .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(observer);
 
-        mProgressDisposableList.add(observer);
     }
 
     @Override

+ 2 - 2
app/src/main/java/com/miekir/ym/ui/home/more/login/LoginPresenter.java

@@ -31,14 +31,14 @@ public class LoginPresenter extends BasePresenter<ILoginView> {
             }
         };
 
+        mProgressDisposableList.add(observer);
+
         RetrofitHelper.getInstance()
                 .getRequestApi(ApiService.class)
                 .submitLogin(email, password)
                 .subscribeOn(Schedulers.io())
                 .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(observer);
-
-        mProgressDisposableList.add(observer);
     }
 
     @Override

+ 2 - 2
app/src/main/java/com/miekir/ym/ui/home/more/register/CodePresenter.java

@@ -28,14 +28,14 @@ public class CodePresenter extends BasePresenter<ICodeView> {
             }
         };
 
+        mProgressDisposableList.add(observer);
+
         RetrofitHelper.getInstance()
                 .getRequestApi(ApiService.class)
                 .getCode(email)
                 .subscribeOn(Schedulers.io())
                 .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(observer);
-
-        mProgressDisposableList.add(observer);
     }
 
     @Override

+ 2 - 2
app/src/main/java/com/miekir/ym/ui/home/more/register/fill/RegisterPresenter.java

@@ -34,6 +34,8 @@ public class RegisterPresenter extends BasePresenter<IRegisterView> {
             }
         };
 
+        mProgressDisposableList.add(observer);
+
         Map<String, Object> map = new HashMap<>();
         map.put("email", user.email);
         map.put("code", code);
@@ -46,8 +48,6 @@ public class RegisterPresenter extends BasePresenter<IRegisterView> {
                 .subscribeOn(Schedulers.io())
                 .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(observer);
-
-        mProgressDisposableList.add(observer);
     }
 
     @Override

+ 22 - 0
app/src/main/res/drawable/selector_btn_exit.xml

@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:state_pressed="true">
+        <shape android:shape="rectangle">
+            <corners android:radius="@dimen/margin_ss"/>
+            <solid android:color="@color/red"/>
+        </shape>
+    </item>
+
+    <!--<item android:state_enabled="false">
+        <shape android:shape="rectangle">
+            <corners android:radius="@dimen/margin_ss"/>
+            <solid android:color="@color/green_logo"/>
+        </shape>
+    </item>-->
+    <item>
+        <shape android:shape="rectangle">
+            <corners android:radius="@dimen/margin_ss"/>
+            <solid android:color="@color/red_text"/>
+        </shape>
+    </item>
+</selector>

+ 119 - 0
app/src/main/res/layout/activity_coupon_add.xml

@@ -0,0 +1,119 @@
+<?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"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:background="@color/colorPrimary"
+    android:fitsSystemWindows="true"
+    android:focusable="true"
+    android:focusableInTouchMode="true"
+    android:orientation="vertical">
+    <!--启用深色模式之后,需要使用fitsSystemWindows来不让布局上滑-->
+
+    <include layout="@layout/view_toolbar" />
+    <!--阴影效果android:background="?android:attr/listDivider"-->
+
+    <ScrollView
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content">
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="vertical">
+
+            <com.google.android.material.textfield.TextInputLayout
+                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginStart="@dimen/margin_default"
+                android:layout_marginTop="@dimen/margin_default"
+                android:layout_marginEnd="@dimen/margin_default"
+                android:hint="优惠券标题"
+                app:boxBackgroundMode="outline"
+                app:boxCornerRadiusBottomEnd="4dp"
+                app:boxCornerRadiusBottomStart="4dp"
+                app:boxCornerRadiusTopEnd="4dp"
+                app:boxCornerRadiusTopStart="4dp"
+                app:boxStrokeWidth="@dimen/width_stroke"
+                app:boxStrokeWidthFocused="@dimen/width_stroke">
+
+                <com.google.android.material.textfield.TextInputEditText
+                    android:id="@+id/et_coupon_title"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:textSize="@dimen/text_normal_s" />
+            </com.google.android.material.textfield.TextInputLayout>
+
+
+            <com.google.android.material.textfield.TextInputLayout
+                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginStart="@dimen/margin_default"
+                android:layout_marginTop="@dimen/margin_default"
+                android:layout_marginEnd="@dimen/margin_default"
+                android:hint="封面URL"
+                app:boxBackgroundMode="outline"
+                app:boxCornerRadiusBottomEnd="4dp"
+                app:boxCornerRadiusBottomStart="4dp"
+                app:boxCornerRadiusTopEnd="4dp"
+                app:boxCornerRadiusTopStart="4dp"
+                app:boxStrokeWidth="@dimen/width_stroke"
+                app:boxStrokeWidthFocused="@dimen/width_stroke">
+
+                <com.google.android.material.textfield.TextInputEditText
+                    android:id="@+id/et_cover_url"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:textSize="@dimen/text_normal_s" />
+            </com.google.android.material.textfield.TextInputLayout>
+
+            <com.google.android.material.textfield.TextInputLayout
+                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginStart="@dimen/margin_default"
+                android:layout_marginTop="@dimen/margin_default"
+                android:layout_marginEnd="@dimen/margin_default"
+                android:hint="跳转URL"
+                app:boxBackgroundMode="outline"
+                app:boxCornerRadiusBottomEnd="4dp"
+                app:boxCornerRadiusBottomStart="4dp"
+                app:boxCornerRadiusTopEnd="4dp"
+                app:boxCornerRadiusTopStart="4dp"
+                app:boxStrokeWidth="@dimen/width_stroke"
+                app:boxStrokeWidthFocused="@dimen/width_stroke">
+
+                <com.google.android.material.textfield.TextInputEditText
+                    android:id="@+id/et_jump_url"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:textSize="@dimen/text_normal_s" />
+            </com.google.android.material.textfield.TextInputLayout>
+
+
+            <CheckBox
+                android:id="@+id/cb_enable"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginStart="@dimen/margin_default"
+                android:text="是否生效"
+                android:checked="true"/>
+
+            <android.widget.Button
+                android:id="@+id/btn_add_goods"
+                style="?android:attr/borderlessButtonStyle"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_margin="@dimen/margin_default"
+                android:background="@drawable/selector_btn"
+                android:minHeight="0dp"
+                android:paddingTop="@dimen/padding_full_width"
+                android:paddingBottom="@dimen/padding_full_width"
+                android:text="立即添加"
+                android:textColor="@color/white"
+                android:textStyle="bold" />
+        </LinearLayout>
+    </ScrollView>
+</LinearLayout>

+ 71 - 0
app/src/main/res/layout/activity_mine.xml

@@ -0,0 +1,71 @@
+<?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:fillViewport="true"
+    android:fitsSystemWindows="true"
+    android:orientation="vertical"
+    android:background="@color/white">
+
+    <include layout="@layout/view_toolbar"/>
+
+    <!--我的收藏-->
+    <TextView
+        android:id="@+id/tv_my_fav"
+        android:layout_width="match_parent"
+        android:layout_height="@dimen/height_tab_bar"
+        android:background="?attr/selectableItemBackground"
+        android:gravity="center_vertical"
+        android:paddingStart="@dimen/activity_horizontal_margin"
+        android:paddingEnd="@dimen/activity_horizontal_margin"
+        android:text="我的收藏"
+        android:textColor="@color/black_text" />
+
+    <include layout="@layout/view_divider" />
+
+    <!--管理员才能看到此界面-->
+    <LinearLayout
+        android:id="@+id/ll_admin"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="vertical">
+
+
+
+
+        <TextView
+            android:id="@+id/tv_add_coupon"
+            android:layout_width="match_parent"
+            android:layout_height="@dimen/height_tab_bar"
+            android:background="?attr/selectableItemBackground"
+            android:gravity="center_vertical"
+            android:paddingStart="@dimen/activity_horizontal_margin"
+            android:paddingEnd="@dimen/activity_horizontal_margin"
+            android:text="新增优惠"
+            android:textColor="@color/black_text" />
+
+        <include layout="@layout/view_divider" />
+    </LinearLayout>
+
+    <View
+        android:layout_width="wrap_content"
+        android:layout_height="0dp"
+        android:layout_weight="1"
+        android:background="@color/colorPrimary"/>
+
+    <android.widget.Button
+        android:id="@+id/btn_exit_login"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:minHeight="0dp"
+        android:layout_marginBottom="@dimen/margin_default"
+        android:layout_marginStart="@dimen/margin_default"
+        android:layout_marginEnd="@dimen/margin_default"
+        android:paddingTop="@dimen/padding_full_width"
+        android:paddingBottom="@dimen/padding_full_width"
+        android:text="退出当前账号"
+        android:textColor="@color/white"
+        android:textStyle="bold"
+        android:background="@drawable/selector_btn_exit"
+        style="?android:attr/borderlessButtonStyle"/>
+</LinearLayout>