导航菜单

页面标题

页面副标题

自健身 v3.3.4 - SuggestionActivity.java 源代码

正在查看: 自健身 v3.3.4 应用的 SuggestionActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.mu.gymtrain.Activity.PersonPackage;

import android.os.Build;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.OnClick;
import com.mu.gymtrain.Base.BaseActivity;
import com.mu.gymtrain.Base.BaseModel;
import com.mu.gymtrain.Http.HttpHelper;
import com.mu.gymtrain.R;
import com.mu.gymtrain.Utils.FinalTools;
import com.mu.gymtrain.Utils.MessageUtils;
import com.mu.gymtrain.Utils.PreferenceUtils;
import com.mu.gymtrain.Utils.UrlConfig;
import com.mu.gymtrain.Utils.ViewUtils;
import com.mu.gymtrain.Widget.PicChosePackage.TweetPicturesPreviewer.TweetPicturesPreviewer;
import java.io.File;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.MultipartBody$Builder;
import okhttp3.RequestBody;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class SuggestionActivity extends BaseActivity implements TweetPicturesPreviewer.permissonCallback {

    @BindView(R.id.et_suggestion)
    EditText etSuggestion;

    @BindView(R.id.title_left)
    ImageView titleLeft;

    @BindView(R.id.title_middle)
    TextView titleMiddle;

    @BindView(R.id.tv_submit)
    TextView tvSubmit;

    @BindView(R.id.twtpv)
    TweetPicturesPreviewer twtpv;

    public int getContentLayout() {
        return R.layout.activity_suggestion;
    }

    public void initData() {
    }

    public void initView() {
        this.titleMiddle.setText(getString(R.string.person_suggestion));
        this.twtpv.setPermissonCallback(this);
        this.twtpv.setPicCount(4);
    }

    @OnClick({R.id.title_left, R.id.tv_submit})
    public void onViewClicked(View view) {
        int id = view.getId();
        if (id == 2131297253) {
            finish();
        } else {
            if (id != 2131297650) {
                return;
            }
            postSuggestion();
        }
    }

    @Override
    public void getPermisson() {
        if (Build.VERSION.SDK_INT >= 23) {
            if (checkSelfPermission("android.permission.CAMERA") != 0 || checkSelfPermission("android.permission.READ_EXTERNAL_STORAGE") != 0 || checkSelfPermission("android.permission.WRITE_EXTERNAL_STORAGE") != 0) {
                requestPermission(3, new String[]{"android.permission.CAMERA", "android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE"}, new Runnable() {
                    @Override
                    public void run() {
                        SuggestionActivity.this.twtpv.toSelect();
                    }
                }, new Runnable() {
                    @Override
                    public void run() {
                        MessageUtils.alertLongMessageCENTER("没有权限, 你需要去设置中开启相应权限.");
                    }
                });
                return;
            } else {
                this.twtpv.toSelect();
                return;
            }
        }
        this.twtpv.toSelect();
    }

    private void postSuggestion() {
        ViewUtils.showLoading(this, "上传中,请稍等。。。");
        this.tvSubmit.setEnabled(false);
        String[] paths = this.twtpv.getPaths();
        MultipartBody$Builder multipartBody$Builder = new MultipartBody$Builder();
        multipartBody$Builder.setType(MultipartBody.FORM);
        multipartBody$Builder.addFormDataPart("contents", this.etSuggestion.getText().toString());
        multipartBody$Builder.addFormDataPart(UrlConfig.Params.TOKEN, PreferenceUtils.getInstance().getString(FinalTools.TOKEN, ""));
        if (paths != null) {
            for (String str : paths) {
                File file = new File(str);
                multipartBody$Builder.addFormDataPart("graph_files", file.getName(), RequestBody.create(MediaType.parse("image/*"), file));
            }
        }
        HttpHelper.getInstance().getRetrofitService(this).postAdvise(multipartBody$Builder.build()).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new Subscriber<BaseModel>() {
            public void onCompleted() {
                SuggestionActivity.this.tvSubmit.setEnabled(true);
                ViewUtils.hideLoading();
            }

            public void onError(Throwable throwable) {
                ViewUtils.hideLoading();
                MessageUtils.alertLongMessageCENTER("提交成功");
                SuggestionActivity.this.finish();
            }

            public void onNext(BaseModel adBeen) {
                MessageUtils.alertLongMessageCENTER("提交成功");
                SuggestionActivity.this.finish();
            }
        });
    }
}