package com.tejia.lijin.app.ui.mine;
|
|
import android.app.Activity;
|
import android.app.AlertDialog;
|
import android.content.Context;
|
import android.content.Intent;
|
import android.content.SharedPreferences;
|
import android.os.Bundle;
|
import android.os.Handler;
|
import android.os.Message;
|
import android.text.InputType;
|
import android.view.MotionEvent;
|
import android.view.View;
|
import android.view.WindowManager;
|
import android.view.inputmethod.InputMethodManager;
|
import android.widget.EditText;
|
import android.widget.FrameLayout;
|
import android.widget.ImageView;
|
import android.widget.LinearLayout;
|
import android.widget.ScrollView;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.alibaba.baichuan.trade.biz.login.AlibcLogin;
|
import com.alibaba.baichuan.trade.biz.login.AlibcLoginCallback;
|
import com.bumptech.glide.Glide;
|
import com.tejia.lijin.app.ShoppingApplication;
|
import com.wpc.library.RetainViewFragment;
|
import com.wpc.library.util.common.StringUtils;
|
import com.tejia.lijin.app.BasicTextHttpResponseHandler;
|
import com.tejia.lijin.app.R;
|
import com.tejia.lijin.app.ShoppingApi;
|
import com.tejia.lijin.app.ui.dialog.ShapeLoadingDialog;
|
import com.tejia.lijin.app.ui.invite.ShareBrowserActivity;
|
import com.tejia.lijin.app.util.OrderTransformationLink;
|
import com.tejia.lijin.app.util.user.UserUtil;
|
|
import org.apache.http.Header;
|
import org.json.JSONObject;
|
|
/**
|
* 订单找回 fragment
|
*/
|
public class FragmentOrderAppeal extends RetainViewFragment implements View.OnClickListener {
|
private TextView tv_refer_appeal, tv_order_appeal_doubt;
|
private EditText et_orderId;
|
private TextView tv_notice_content, iv_order_coursetxt;
|
private LinearLayout ll_notice;
|
private ImageView iv_close;
|
private ScrollView sv_content;
|
private TextView tv_order_appeal_aout;//自动找回
|
private ImageView iv_order_course;//图片教程
|
|
private int clickState = 0;
|
private Bundle mBundle;//传递过来的值
|
private String TYPE = "orderFind";//默认淘宝
|
|
@Override
|
public int getContentResource() {
|
return R.layout.fragment_order_appeal;
|
}
|
|
@Override
|
public void onCreateView(View contentView, Bundle savedInstanceState) {
|
tv_refer_appeal = contentView.findViewById(R.id.tv_refer_appeal);
|
tv_order_appeal_doubt = contentView.findViewById(R.id.tv_order_appeal_doubt);
|
et_orderId = contentView.findViewById(R.id.et_order_id);
|
tv_order_appeal_aout = contentView.findViewById(R.id.tv_order_appeal_aout);
|
tv_notice_content = contentView.findViewById(R.id.tv_notice_content);
|
ll_notice = contentView.findViewById(R.id.ll_notice);
|
iv_close = contentView.findViewById(R.id.iv_close);
|
sv_content = contentView.findViewById(R.id.sv_content);
|
iv_order_coursetxt = contentView.findViewById(R.id.iv_order_coursetxt);
|
iv_order_course = contentView.findViewById(R.id.iv_order_course);
|
|
et_orderId.setCursorVisible(true);
|
et_orderId.setOnClickListener(this);
|
tv_refer_appeal.setOnClickListener(this);
|
tv_order_appeal_doubt.setOnClickListener(this);
|
tv_order_appeal_aout.setOnClickListener(this);
|
mBundle = getArguments();//传递过来的 值 做淘宝-京东-拼多多判断
|
getOrderParseConfig();
|
et_orderId.setOnTouchListener(new View.OnTouchListener() {
|
@Override
|
public boolean onTouch(View v, MotionEvent event) {
|
showSoftInputFromWindow(getActivity(), et_orderId);
|
return false;
|
}
|
});
|
setcourse(mBundle.getInt("id"));
|
}
|
|
/**
|
* 设置图片教程
|
*
|
* @param id
|
*/
|
private void setcourse(int id) {
|
int uir;
|
if (id == 1) {//淘宝
|
uir = R.drawable.ic_order_appeal_buttom;
|
iv_order_coursetxt.setText("手机淘宝中复制订单号教程");
|
et_orderId.setHint("请输入或粘贴淘宝订单号");
|
TYPE = "orderFind";//默认淘宝
|
} else if (id == 2) {//京东
|
uir = R.drawable.ic_order_appeal_buttomjd;
|
iv_order_coursetxt.setText("京东中复制订单号教程");
|
et_orderId.setHint("请输入或粘贴京东订单号");
|
TYPE = "orderFindJD";
|
} else if (id == 4) {//唯品会
|
uir = R.drawable.ic_order_appeal_buttomvip;
|
iv_order_coursetxt.setText("唯品会中复制订单号教程");
|
et_orderId.setHint("请输入或粘贴唯品会订单号");
|
TYPE = "orderFindVIP";
|
} else if (id == 5) {//苏宁
|
uir = R.drawable.ic_order_appeal_buttomsuning;
|
iv_order_coursetxt.setText("苏宁中复制订单号教程");
|
et_orderId.setHint("请输入或粘贴苏宁订单号");
|
TYPE = "orderFindSuning";
|
} else {//拼多多
|
uir = R.drawable.ic_order_appeal_buttompdd;
|
iv_order_coursetxt.setText("拼多多中复制订单号教程");
|
et_orderId.setHint("请输入或粘贴拼多多订单号");
|
TYPE = "orderFindPDD";
|
}
|
Glide.with(this)
|
.load(uir)
|
.into(iv_order_course);
|
getAppPageNotification();//小黄条
|
}
|
|
@Override
|
public void setUserVisibleHint(boolean isVisibleToUser) {
|
super.setUserVisibleHint(isVisibleToUser);
|
if (isVisibleToUser && (getActivity()) != null) {
|
//TODO now it's visible to user对用户可见
|
} else {
|
//TODO now it's invisible to user对用户不可见
|
if ((getActivity()) != null) {
|
et_orderId.setFocusable(false);
|
et_orderId.setFocusableInTouchMode(false);
|
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
imm.hideSoftInputFromWindow(et_orderId.getWindowToken(), 0);// s强制隐藏键盘
|
}
|
}
|
}
|
|
/**
|
* EditText获取焦点并显示软键盘
|
*/
|
public void showSoftInputFromWindow(Activity activity, EditText editText) {
|
editText.setFocusable(true);
|
editText.setFocusableInTouchMode(true);
|
editText.requestFocus();
|
//显示软键盘
|
activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
//如果上面的代码没有弹出软键盘 可以使用下面另一种方式
|
//InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
// imm.showSoftInput(editText, 0);
|
sv_content.fullScroll(ScrollView.FOCUS_DOWN);
|
}
|
|
private int showCount = 0;
|
|
@Override
|
public void onResume() {
|
super.onResume();
|
if (clickState == 1) {
|
clickState = 0;
|
Intent intent = new Intent(getActivity(), OrderAppealHistoryActivity.class);
|
startActivity(intent);
|
}
|
// final View activityRootView = getActivity().getWindow().getDecorView().findViewById(android.R.id.content);
|
// if (getActivity() != null) {
|
// getActivity().getWindow().getDecorView().addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
// @Override
|
// public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
// if (showCount > 1) {
|
// //获取View可见区域的bottom
|
// if (getActivity() != null) {
|
// int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
|
// if (heightDiff > 100) { // 99% of the time the height diff will be due to a keyboard.
|
// if (isOpened == false) {
|
// //Do two things, make the view top visible and the editText smaller
|
// isOpened = true;
|
// }
|
// sv_content.fullScroll(ScrollView.FOCUS_DOWN);
|
// Toast.makeText(getContext(), "Gotcha!!! softKeyboardup", Toast.LENGTH_SHORT).show();
|
// } else if (isOpened == true) {
|
// isOpened = false;
|
// sv_content.fullScroll(ScrollView.FOCUS_UP);
|
// Toast.makeText(getContext(), "softkeyborad Down!!!", Toast.LENGTH_SHORT).show();
|
// } else {
|
// isOpened = true;
|
// }
|
// }
|
// }
|
// showCount++;
|
// }
|
// });
|
// }
|
}
|
|
boolean isOpened = false;
|
|
/**
|
* 小黄条
|
*/
|
private void getAppPageNotification() {
|
ShoppingApi.getAppPageNotification(getContext(), TYPE, new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
if (jsonObject.optInt("code") == 0) {
|
boolean isClose = jsonObject.optJSONObject("data").optBoolean("canClose");
|
String content = jsonObject.optJSONObject("data").optString("content");
|
final String contentUrl = jsonObject.optJSONObject("data").optString("contentUrl");
|
final String md5 = jsonObject.optJSONObject("data").optString("md5");
|
|
tv_notice_content.setText(content);
|
final SharedPreferences sp = getContext().getSharedPreferences("notice", Context.MODE_PRIVATE);
|
if (!sp.getBoolean(md5, false)) {//false 展示,true不展示
|
ll_notice.setVisibility(View.VISIBLE);
|
} else {
|
ll_notice.setVisibility(View.GONE);
|
}
|
|
if (isClose) {
|
iv_close.setImageDrawable(getResources().getDrawable(R.drawable.ic_notice_close));
|
iv_close.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
ll_notice.setVisibility(View.GONE);
|
SharedPreferences.Editor editor = sp.edit();
|
editor.putBoolean(md5, true);
|
editor.commit();
|
}
|
});
|
} else {
|
iv_close.setImageDrawable(getResources().getDrawable(R.drawable.ic_notice_input));
|
}
|
ll_notice.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
if (StringUtils.isEmpty(contentUrl))
|
return;
|
Intent intent = new Intent(getContext(), ShareBrowserActivity.class);
|
intent.putExtra("url", contentUrl);
|
startActivity(intent);
|
}
|
});
|
}
|
}
|
});
|
}
|
|
@Override
|
public void onClick(View view) {
|
switch (view.getId()) {
|
|
|
case R.id.tv_refer_appeal:
|
if (StringUtils.isEmpty(et_orderId.getText().toString())) {
|
// SingleToast.showToast(OrderAppealActivity.this, "订单号不能为空");
|
Toast.makeText(getContext(), "订单号不能为空", Toast.LENGTH_SHORT).show();
|
break;
|
}
|
referAppeal();
|
break;
|
case R.id.tv_order_appeal_doubt://进入订单申诉的网页解释界面
|
{
|
SharedPreferences sp = getContext().getSharedPreferences("lostOrder", Context.MODE_PRIVATE);
|
String what = sp.getString("what", "");
|
Intent intent = new Intent(getContext(), ShareBrowserActivity.class);
|
intent.putExtra("url", what);
|
startActivity(intent);
|
}
|
case R.id.et_order_id: {
|
// et_orderId.setCursorVisible(true);
|
// <!--android:focusable = "true"-- >
|
// <!--android:focusableInTouchMode = "true"-- >
|
et_orderId.setFocusable(true);
|
et_orderId.setFocusableInTouchMode(true);
|
et_orderId.setInputType(InputType.TYPE_CLASS_PHONE);
|
}
|
break;
|
case R.id.tv_order_appeal_aout://自动找回
|
SharedPreferences sp = getContext().getSharedPreferences("user", Context.MODE_PRIVATE);
|
boolean isLogin = UserUtil.isLogin(getContext());
|
if (isLogin) {
|
if (!btimer) {
|
if (AlibcLogin.getInstance().isLogin()) {
|
bindInfo();
|
} else {
|
tbLogin();
|
}
|
}
|
} else {
|
UserUtil.jumpLogin(getContext());
|
}
|
|
break;
|
}
|
}
|
|
String title = "找回提示";
|
|
/**
|
* 解密 淘宝找回订单
|
*/
|
private void bindInfo() {
|
waitinquire();//缓冲
|
OrderTransformationLink order = new OrderTransformationLink(getActivity(), orderJS, orderUrl, "findOrder");
|
btimer = true;
|
timer();//开启线程
|
|
order.setOnOrderListener(new OrderTransformationLink.onListener() {
|
@Override
|
public void onOrder(String reruen) {//找回成功
|
if (btimer) {
|
btimer = false;
|
String content2;
|
if (reruen != null && reruen.equals("成功")) {
|
content2 = "订单找回成功, 请到“我的-订单”中查看";
|
} else {
|
content2 = reruen;
|
}
|
Dialog_explain(title, content2);
|
}
|
btimer = false;
|
if (thread != null) {
|
thread.interrupt();
|
}
|
}
|
|
@Override
|
public void onIOrderError(String reruen) {//找回失败
|
if (btimer) {
|
btimer = false;
|
String content1;
|
if (reruen != null && reruen.equals("失败")) {
|
content1 = "系统没有找到丢失订单,请确认是否满足找回条件或手动输入订单号找回";
|
} else {
|
content1 = reruen;
|
}
|
Dialog_explain(title, content1);
|
}
|
btimer = false;
|
if (thread != null) {
|
thread.interrupt();
|
}
|
}
|
});
|
order.showOrder();
|
}
|
|
private Thread thread;//线程
|
private boolean btimer = false;//开启线程
|
|
/**
|
* 主要是用于 点击自动找回 10秒超时
|
*/
|
private void timer() {
|
thread = new Thread(new Runnable() {
|
@Override
|
public void run() {
|
int timer = 10;
|
while (btimer && timer >= 1) {
|
//暂停一秒
|
try {
|
Thread.sleep(1000);
|
} catch (InterruptedException e) {
|
e.printStackTrace();
|
btimer = false;
|
}
|
timer--;
|
if (timer <= 1) {//结束线程
|
btimer = false;
|
Message message = new Message();
|
message.what = 1;
|
//发送信息给handler
|
handler.sendMessage(message);
|
}
|
}
|
}
|
});
|
thread.start();
|
}
|
|
Handler handler = new Handler() {
|
@Override
|
public void handleMessage(Message msg) {
|
super.handleMessage(msg);
|
switch (msg.what) {
|
case 1:
|
btimer = false;
|
if (thread != null) {
|
thread.interrupt();//线程中断
|
}
|
String content1 = "系统没有找到丢失订单,请确认是否满足找回条件或手动输入订单号找回";
|
Dialog_explain(title, content1);
|
break;
|
}
|
}
|
};
|
|
/**
|
* 登陆淘宝
|
*/
|
private void tbLogin() {
|
final AlibcLogin alibcLogin = AlibcLogin.getInstance();
|
alibcLogin.showLogin(new AlibcLoginCallback() {
|
|
@Override
|
public void onSuccess(int i, String s, String s1) {
|
bindInfo();
|
}
|
|
@Override
|
public void onFailure(int code, String msg) {
|
Toast.makeText(getContext(), "登录失败,请稍候再试",
|
Toast.LENGTH_LONG).show();
|
}
|
});
|
|
}
|
|
ShapeLoadingDialog pd = null;
|
|
public void waitinquire() {
|
if (pd == null) {
|
pd = new ShapeLoadingDialog.Builder(getContext()).build();
|
}
|
pd.show();
|
}
|
|
|
AlertDialog.Builder alterDiaglog;
|
AlertDialog dialog;
|
|
/**
|
* dialog 弹窗说明
|
*
|
* @param title
|
* @param str1
|
*/
|
private void Dialog_explain(String title, String str1) {
|
if (pd != null && pd.isShowing())
|
pd.dismiss();
|
alterDiaglog = new AlertDialog.Builder(getContext(), R.style.dialog_activationinvitecode2);
|
View view = View.inflate(getContext(), R.layout.dialog_activationinvite3, null);
|
alterDiaglog.setView(view);//加载进去
|
if (dialog != null && dialog.isShowing()) {
|
dialog.dismiss();
|
}
|
dialog = alterDiaglog.create();
|
//显示
|
dialog.show();
|
//设置宽高
|
WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
|
params.width = getActivity().getWindowManager().getDefaultDisplay().getWidth();
|
params.height = com.app.hubert.guide.util.ScreenUtils.dp2px(getContext(), 290);
|
params.width = com.app.hubert.guide.util.ScreenUtils.dp2px(getContext(), 260);
|
dialog.getWindow().setAttributes(params);
|
TextView textitle = dialog.findViewById(R.id.dialog_activationinvitetxt_title);
|
TextView textcontent1 = dialog.findViewById(R.id.dialog_activationinvitetxt_content1);
|
FrameLayout fl_close = dialog.findViewById(R.id.dialog_activationinvitetxt_close);
|
textitle.setText(title);
|
textcontent1.setText(str1);
|
fl_close.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
if (dialog != null && dialog.isShowing()) {
|
dialog.dismiss();
|
dialog.cancel();
|
}
|
}
|
});
|
}
|
|
private void referAppeal() {
|
Long uid = UserUtil.getUid(ShoppingApplication.application);
|
// String uid = "323922";
|
if (uid == null) {
|
// SingleToast.showToast(OrderAppealActivity.this, "登录后才能申诉");
|
Toast.makeText(getContext(), "登录后才能找回", Toast.LENGTH_SHORT).show();
|
return;
|
}
|
|
ShoppingApi.setOrderAppeal(getContext(), et_orderId.getText().toString(), uid, mBundle.getInt("id") + "", new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
if (jsonObject.optString("code").equalsIgnoreCase("0")) {
|
et_orderId.setText("");
|
// SingleToast.showToast(OrderAppealActivity.this, jsonObject.optJSONObject("data").optString("info"));
|
Toast.makeText(getContext(), jsonObject.optJSONObject("data").optString("info"), Toast.LENGTH_SHORT).show();
|
} else {
|
Toast.makeText(getContext(), "找回失败", Toast.LENGTH_SHORT).show();
|
// SingleToast.showToast(OrderAppealActivity.this, "申诉失败!");
|
}
|
}
|
|
@Override
|
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
|
super.onFailure(statusCode, headers, responseString, throwable);
|
// SingleToast.showToast(OrderAppealActivity.this, "提交失败!");
|
Toast.makeText(getContext(), "提交失败", Toast.LENGTH_SHORT).show();
|
}
|
});
|
}
|
|
|
/**
|
* 淘宝订单配置
|
*
|
* @param source
|
*/
|
String orderJS;
|
String orderUrl;
|
|
/**
|
* 淘宝订单解析配置
|
*/
|
private void getOrderParseConfig() {
|
//只有淘宝 才做自动找回
|
if (mBundle.getInt("id") != 1) {
|
return;
|
}
|
ShoppingApi.getOrderParseConfig(getContext(), new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
if (jsonObject.optInt("code") == 0) {
|
tv_order_appeal_aout.setVisibility(View.VISIBLE);
|
orderJS = jsonObject.optJSONObject("data").getString("orderJS");
|
orderUrl = jsonObject.optJSONObject("data").getString("orderUrl");
|
} else {//隐藏订单找回
|
tv_order_appeal_aout.setVisibility(View.GONE);
|
}
|
}
|
});
|
}
|
|
@Override
|
public void onPause() {
|
super.onPause();
|
btimer = false;
|
if (thread != null) {
|
thread.interrupt();
|
}
|
if (dialog != null && dialog.isShowing()) {
|
dialog.dismiss();
|
dialog.cancel();
|
}
|
if (pd != null && pd.isShowing())
|
pd.dismiss();
|
et_orderId.setFocusable(false);
|
et_orderId.setFocusableInTouchMode(false);
|
// et_orderId.requestFocus();
|
}
|
|
|
@Override
|
public void onDestroy() {
|
super.onDestroy();
|
btimer = false;
|
if (thread != null) {
|
thread.interrupt();
|
}
|
if (dialog != null && dialog.isShowing()) {
|
dialog.dismiss();
|
dialog.cancel();
|
}
|
if (pd != null && pd.isShowing())
|
pd.dismiss();
|
}
|
}
|