890 lines
38 KiB
Java
890 lines
38 KiB
Java
package com.gh.gamecenter;
|
||
|
||
import android.app.Dialog;
|
||
import android.content.Context;
|
||
import android.content.Intent;
|
||
import android.content.SharedPreferences;
|
||
import android.database.Cursor;
|
||
import android.graphics.Color;
|
||
import android.net.Uri;
|
||
import android.os.Build;
|
||
import android.os.Bundle;
|
||
import android.os.Environment;
|
||
import android.preference.PreferenceManager;
|
||
import android.provider.MediaStore;
|
||
import android.text.Html;
|
||
import android.text.TextUtils;
|
||
import android.view.View;
|
||
import android.view.Window;
|
||
import android.widget.CheckedTextView;
|
||
import android.widget.EditText;
|
||
import android.widget.LinearLayout;
|
||
import android.widget.ProgressBar;
|
||
import android.widget.ScrollView;
|
||
import android.widget.TextView;
|
||
|
||
import androidx.annotation.NonNull;
|
||
import androidx.core.content.ContextCompat;
|
||
import androidx.recyclerview.widget.GridLayoutManager;
|
||
import androidx.recyclerview.widget.RecyclerView;
|
||
|
||
import com.gh.base.BaseActivity;
|
||
import com.gh.base.OnListClickListener;
|
||
import com.gh.base.OnRequestCallBackListener;
|
||
import com.gh.base.fragment.WaitingDialogFragment;
|
||
import com.gh.common.im.ImManager;
|
||
import com.gh.common.util.AdHelper;
|
||
import com.gh.common.util.CheckLoginUtils;
|
||
import com.gh.common.util.DialogUtils;
|
||
import com.gh.common.util.DirectUtils;
|
||
import com.gh.common.util.DisplayUtils;
|
||
import com.gh.common.util.EntranceUtils;
|
||
import com.gh.common.util.GsonUtils;
|
||
import com.gh.common.util.ImageUtils;
|
||
import com.gh.common.util.MtaHelper;
|
||
import com.gh.common.util.NetworkUtils;
|
||
import com.gh.common.util.PackageUtils;
|
||
import com.gh.common.util.ShareUtils;
|
||
import com.gh.common.util.UploadImageUtils;
|
||
import com.gh.gamecenter.entity.ErrorEntity;
|
||
import com.gh.gamecenter.entity.InstallGameEntity;
|
||
import com.gh.gamecenter.entity.SettingsEntity;
|
||
import com.gh.gamecenter.entity.SuggestionTypeEntity;
|
||
import com.gh.gamecenter.entity.UserInfoEntity;
|
||
import com.gh.gamecenter.manager.UserManager;
|
||
import com.gh.gamecenter.retrofit.Response;
|
||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||
import com.gh.gamecenter.suggest.SuggestPicAdapter;
|
||
import com.gh.gamecenter.suggest.SuggestSelectGameAdapter;
|
||
import com.gh.gamecenter.suggest.SuggestType;
|
||
import com.google.gson.Gson;
|
||
import com.halo.assistant.HaloApp;
|
||
import com.lightgame.utils.Util_System_Keyboard;
|
||
import com.lightgame.utils.Util_System_Phone_State;
|
||
import com.lightgame.utils.Utils;
|
||
import com.walkud.rom.checker.RomIdentifier;
|
||
|
||
import org.jetbrains.annotations.NotNull;
|
||
import org.json.JSONArray;
|
||
import org.json.JSONException;
|
||
import org.json.JSONObject;
|
||
|
||
import java.io.BufferedInputStream;
|
||
import java.io.BufferedReader;
|
||
import java.io.File;
|
||
import java.io.FileInputStream;
|
||
import java.io.InputStream;
|
||
import java.io.InputStreamReader;
|
||
import java.util.HashMap;
|
||
import java.util.LinkedHashMap;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
|
||
import butterknife.BindView;
|
||
import butterknife.OnClick;
|
||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||
import io.reactivex.schedulers.Schedulers;
|
||
import okhttp3.MediaType;
|
||
import okhttp3.RequestBody;
|
||
import okhttp3.ResponseBody;
|
||
import retrofit2.HttpException;
|
||
|
||
import static com.gh.gamecenter.SuggestSelectActivity.SUGGEST_TYPE_REQUEST;
|
||
|
||
/**
|
||
* Created by khy on 2017/3/31.
|
||
*/
|
||
public class SuggestionActivity extends BaseActivity implements OnRequestCallBackListener<Object>, OnListClickListener {
|
||
|
||
@BindView(R.id.suggest_content_et)
|
||
EditText mSuggestContentEt;
|
||
@BindView(R.id.suggest_pic_rv)
|
||
RecyclerView mSuggestPicRv;
|
||
@BindView(R.id.suggest_email_et)
|
||
EditText mSuggestEmailEt;
|
||
@BindView(R.id.suggest_post_btn)
|
||
TextView mSuggestPostBtn;
|
||
@BindView(R.id.suggest_post_ll)
|
||
View suggestPostLl;
|
||
@BindView(R.id.suggest_game_select)
|
||
TextView mSuggestSelectGame;
|
||
@BindView(R.id.suggest_game_name)
|
||
TextView mSuggestGameName;
|
||
@BindView(R.id.suggest_game_container)
|
||
View mSuggestGameLl;
|
||
@BindView(R.id.suggest_scrollview)
|
||
ScrollView mScrollView;
|
||
@BindView(R.id.type_accelerate)
|
||
CheckedTextView mTypeAccelerate;
|
||
@BindView(R.id.type_standalone)
|
||
CheckedTextView mTypeStandalone;
|
||
@BindView(R.id.type_material)
|
||
CheckedTextView mTypeMaterial;
|
||
@BindView(R.id.type_other)
|
||
CheckedTextView mTypeOther;
|
||
@BindView(R.id.suggest_type_container)
|
||
LinearLayout mSuggestTypeContainer;
|
||
@BindView(R.id.type_other_name)
|
||
EditText mTypeOtherName;
|
||
@BindView(R.id.suggest_game_name_title)
|
||
TextView mGameNameTitle;
|
||
@BindView(R.id.suggest_type_name)
|
||
TextView mTypeName;
|
||
@BindView(R.id.suggest_email_name)
|
||
TextView mEmailName;
|
||
@BindView(R.id.tv_ad)
|
||
TextView mAdTv;
|
||
@BindView(R.id.suggest_platform_container)
|
||
View mPlatformContainer;
|
||
@BindView(R.id.suggest_platform_et)
|
||
TextView mPlatformEt;
|
||
@BindView(R.id.suggest_platform_title)
|
||
TextView mPlatformTitle;
|
||
@BindView(R.id.suggest_link_et)
|
||
TextView mLinkEt;
|
||
@BindView(R.id.suggest_link_container)
|
||
View mLinkContainer;
|
||
|
||
public static final int MEDIA_STORE_REQUEST = 1;
|
||
public static final String SUGGESTION_HINT_TYPE = "SUGGESTION_HINT_TYPE";
|
||
|
||
private SuggestPicAdapter mAdapter;
|
||
|
||
private Dialog selectGameDialog;
|
||
private WaitingDialogFragment postDialog;
|
||
|
||
private SharedPreferences sp;
|
||
|
||
private String[] mFunctionTypeName;
|
||
|
||
private SuggestType mSuggestType;
|
||
|
||
private String mGameInfo;
|
||
private String mHideHint;
|
||
private String mSuggestContent;
|
||
private String mSuggestHintType;
|
||
|
||
private boolean mAgreePostPic;
|
||
|
||
private int mFunctionType = -1;
|
||
|
||
@NonNull
|
||
public static Intent getIntent(Context context, SuggestType suggestType) {
|
||
Intent intent = new Intent(context, SuggestionActivity.class);
|
||
intent.putExtra(EntranceUtils.KEY_SUGGESTTYPE, suggestType);
|
||
return intent;
|
||
}
|
||
|
||
public static void startSuggestionActivity(Context context, SuggestType suggestType, String suggestHintType, String content) {
|
||
Intent intent = new Intent(context, SuggestionActivity.class);
|
||
intent.putExtra(EntranceUtils.KEY_SUGGESTTYPE, suggestType);
|
||
intent.putExtra(EntranceUtils.KEY_SUGGEST_HINT_TYPE, suggestHintType);
|
||
intent.putExtra(EntranceUtils.KEY_CONTENT, content);
|
||
context.startActivity(intent);
|
||
}
|
||
|
||
public static void startSuggestionActivity(Context context, SuggestType suggestType, String hint) {
|
||
Intent intent = new Intent(context, SuggestionActivity.class);
|
||
intent.putExtra(EntranceUtils.KEY_SUGGESTTYPE, suggestType);
|
||
intent.putExtra(EntranceUtils.KEY_HIDE_SUGGEST_HINT, hint);
|
||
context.startActivity(intent);
|
||
}
|
||
|
||
@Override
|
||
protected int getLayoutId() {
|
||
return R.layout.activity_suggest;
|
||
}
|
||
|
||
@Override
|
||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||
super.onActivityResult(requestCode, resultCode, data);
|
||
if (data != null && requestCode == MEDIA_STORE_REQUEST) {
|
||
Uri selectedImage = data.getData();
|
||
if (selectedImage == null) {
|
||
return;
|
||
}
|
||
String[] filePathColumn = {MediaStore.Images.Media.DATA};
|
||
|
||
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
|
||
if (cursor == null) {
|
||
return;
|
||
}
|
||
cursor.moveToFirst();
|
||
|
||
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
|
||
String picturePath = cursor.getString(columnIndex);
|
||
cursor.close();
|
||
|
||
Utils.log("picturePath = " + picturePath);
|
||
|
||
try {
|
||
File file = new File(picturePath);
|
||
if (file.length() > ImageUtils.getUploadFileMaxSize()) {
|
||
long count = ImageUtils.getUploadFileMaxSize() / 1024 / 1024;
|
||
Utils.toast(this, getString(R.string.pic_max_hint, count));
|
||
} else {
|
||
mAdapter.addFileList(picturePath);
|
||
}
|
||
} catch (Exception e) {
|
||
Utils.toast(this, e.getMessage());
|
||
}
|
||
}
|
||
}
|
||
|
||
@Override
|
||
protected void onCreate(Bundle savedInstanceState) {
|
||
super.onCreate(savedInstanceState);
|
||
Bundle extras = getIntent().getExtras();
|
||
Object suggestType = extras.get(EntranceUtils.KEY_SUGGESTTYPE);
|
||
if (suggestType instanceof SuggestType) {
|
||
mSuggestType = (SuggestType) suggestType;
|
||
} else {
|
||
mSuggestType = SuggestType.normal;
|
||
}
|
||
mSuggestContent = extras.getString(EntranceUtils.KEY_CONTENT);
|
||
mSuggestHintType = extras.getString(EntranceUtils.KEY_SUGGEST_HINT_TYPE);
|
||
mHideHint = extras.getString(EntranceUtils.KEY_HIDE_SUGGEST_HINT, "");
|
||
mFunctionTypeName = getResources().getStringArray(R.array.suggest_function_type);
|
||
|
||
setNavigationTitle("意见反馈-" + mSuggestType.getType());
|
||
|
||
SettingsEntity.AD ad = AdHelper.INSTANCE.getAd(AdHelper.LOCATION_SUGGESTION_FUNCTION);
|
||
if (mSuggestType == SuggestType.functionSuggest
|
||
&& ad != null) {
|
||
mAdTv.setVisibility(View.VISIBLE);
|
||
mAdTv.setText(ad.getTitle());
|
||
mAdTv.setOnClickListener(v -> {
|
||
MtaHelper.onEvent("广告位统计", "意见反馈_功能收录", ad.getTitle());
|
||
DirectUtils.directToLinkPage(this,
|
||
ad.toLinkEntity(),
|
||
"(意见反馈-功能收录-广告位)",
|
||
"");
|
||
});
|
||
}
|
||
|
||
sp = PreferenceManager.getDefaultSharedPreferences(this);
|
||
|
||
// 意见反馈上传图片列表
|
||
mSuggestPicRv.setLayoutManager(new GridLayoutManager(this, 5) {
|
||
@Override
|
||
public boolean canScrollVertically() {
|
||
return false;
|
||
}
|
||
});
|
||
mAdapter = new SuggestPicAdapter(this, this);
|
||
mSuggestPicRv.setAdapter(mAdapter);
|
||
|
||
if (!TextUtils.isEmpty(mSuggestContent)) {
|
||
if (mSuggestType == SuggestType.gameQuestion && "game".equals(mSuggestHintType)) {
|
||
mSuggestContentEt.setText("问题反馈:");
|
||
mSuggestSelectGame.setVisibility(View.GONE);
|
||
mSuggestGameName.setVisibility(View.VISIBLE);
|
||
mSuggestGameName.setText(mSuggestContent);
|
||
} else {
|
||
mSuggestContentEt.setText(mSuggestContent);
|
||
}
|
||
mSuggestContentEt.setSelection(mSuggestContentEt.getText().length());
|
||
}
|
||
|
||
initSuggest(mSuggestType);
|
||
|
||
String suggestionType = sp.getString(SUGGESTION_HINT_TYPE, null);
|
||
if (!TextUtils.isEmpty(mSuggestHintType) && !TextUtils.isEmpty(suggestionType)) {
|
||
Gson gson = new Gson();
|
||
SuggestionTypeEntity typeEntity = gson.fromJson(suggestionType, SuggestionTypeEntity.class);
|
||
if (typeEntity != null) {
|
||
switch (mSuggestHintType) {
|
||
case EntranceUtils.KEY_PLUGIN:
|
||
List<String> plugin = typeEntity.getPlugin();
|
||
if (plugin != null && plugin.size() > 0) {
|
||
showHintDialog(plugin);
|
||
}
|
||
break;
|
||
case "game":
|
||
List<String> game = typeEntity.getGame();
|
||
if (game != null && game.size() > 0) {
|
||
showHintDialog(game);
|
||
}
|
||
break;
|
||
case "libao":
|
||
List<String> libao = typeEntity.getLibao();
|
||
if (libao != null && libao.size() > 0) {
|
||
showHintDialog(libao);
|
||
}
|
||
break;
|
||
case "service":
|
||
List<String> service = typeEntity.getService();
|
||
if (service != null && service.size() > 0) {
|
||
showHintDialog(service);
|
||
}
|
||
break;
|
||
case "report":
|
||
List<String> report = typeEntity.getReport();
|
||
if (report != null && report.size() > 0) {
|
||
showHintDialog(report);
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
UserInfoEntity userInfo = UserManager.getInstance().getUserInfoEntity();
|
||
if (userInfo != null && !TextUtils.isEmpty(userInfo.getQq())) {
|
||
mSuggestEmailEt.setText(userInfo.getQq());
|
||
}
|
||
|
||
mTypeOtherName.setOnFocusChangeListener((v, hasFocus) -> {
|
||
if (hasFocus) {
|
||
mTypeAccelerate.setChecked(false);
|
||
mTypeMaterial.setChecked(false);
|
||
mTypeOther.setChecked(true);
|
||
mTypeStandalone.setChecked(false);
|
||
mFunctionType = 3;
|
||
}
|
||
});
|
||
|
||
mSuggestContentEt.setFocusable(true);
|
||
mSuggestContentEt.setFocusableInTouchMode(true);
|
||
mSuggestContentEt.requestFocus();
|
||
Util_System_Keyboard.showSoftKeyboard(this, mSuggestContentEt);
|
||
}
|
||
|
||
private void initSuggest(SuggestType type) {
|
||
if (type == SuggestType.normal) {
|
||
mSuggestContentEt.setHint("请详细描述你遇到的问题... \n ↓↓你还可以上传截图");
|
||
mSuggestTypeContainer.setVisibility(View.GONE);
|
||
mSuggestGameLl.setVisibility(View.GONE);
|
||
} else if (type == SuggestType.crash) {
|
||
mSuggestContentEt.setHint("请详细描述闪退之前你所进行的操作... \n ↓↓你还可以上传截图");
|
||
mSuggestTypeContainer.setVisibility(View.GONE);
|
||
mSuggestGameLl.setVisibility(View.GONE);
|
||
} else if (type == SuggestType.gameQuestion) {
|
||
mSuggestTypeContainer.setVisibility(View.GONE);
|
||
if (!EntranceUtils.KEY_PLUGIN.equals(mSuggestHintType)) {
|
||
mSuggestContentEt.setHint("请描述具体遇到的问题... \n ↓↓你还可以上传截图");
|
||
mSuggestGameLl.setVisibility(View.VISIBLE);
|
||
mPlatformContainer.setVisibility(View.VISIBLE);
|
||
mGameNameTitle.setText(Html.fromHtml(getString(R.string.suggestion_game_name)));
|
||
mPlatformTitle.setText(Html.fromHtml(getString(R.string.suggestion_platform_name)));
|
||
} else {
|
||
mSuggestContentEt.setHint("请写上游戏名字,以及具体遇到的问题... \n ↓↓你还可以上传截图");
|
||
mSuggestGameLl.setVisibility(View.GONE);
|
||
mPlatformContainer.setVisibility(View.GONE);
|
||
}
|
||
} else if (type == SuggestType.gameCollect) {
|
||
mLinkContainer.setVisibility(View.VISIBLE);
|
||
mSuggestGameLl.setVisibility(View.VISIBLE);
|
||
mGameNameTitle.setText(Html.fromHtml(getString(R.string.suggestion_game_name)));
|
||
mSuggestTypeContainer.setVisibility(View.GONE);
|
||
mSuggestContentEt.setHint("请在上方选择或填写游戏名↑↑ \n 在此处可输入补充信息(例如游戏的平台版本等)");
|
||
mEmailName.setText(Html.fromHtml(getString(R.string.suggestion_contact)));
|
||
} else if (type == SuggestType.functionSuggest) {
|
||
mSuggestContentEt.setHint("请详细描述你的建议... \n ↓↓你还可以上传截图");
|
||
mSuggestTypeContainer.setVisibility(View.VISIBLE);
|
||
mSuggestGameLl.setVisibility(View.VISIBLE);
|
||
mGameNameTitle.setText(Html.fromHtml(getString(R.string.suggestion_game_name)));
|
||
mTypeName.setText(Html.fromHtml(getString(R.string.suggestion_function)));
|
||
mEmailName.setText(Html.fromHtml(getString(R.string.suggestion_contact)));
|
||
} else if (type == SuggestType.articleCollect) {
|
||
mSuggestContentEt.setHint("简单介绍文章内容,别忘了填写文章链接哦 \n ↓↓你还可以上传截图");
|
||
mSuggestTypeContainer.setVisibility(View.GONE);
|
||
mSuggestGameLl.setVisibility(View.GONE);
|
||
}
|
||
}
|
||
|
||
private void showHintDialog(List<String> dialogType) {
|
||
final Dialog dialog = new Dialog(SuggestionActivity.this);
|
||
|
||
LinearLayout container = new LinearLayout(SuggestionActivity.this);
|
||
container.setOrientation(LinearLayout.VERTICAL);
|
||
container.setBackgroundColor(Color.WHITE);
|
||
container.setPadding(0, DisplayUtils.dip2px(SuggestionActivity.this, 12), 0, DisplayUtils.dip2px(SuggestionActivity.this, 12));
|
||
|
||
for (String s : dialogType) {
|
||
final TextView reportTv = new TextView(SuggestionActivity.this);
|
||
reportTv.setText(s);
|
||
reportTv.setTextSize(17);
|
||
reportTv.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.title));
|
||
reportTv.setBackgroundResource(R.drawable.textview_white_style);
|
||
int widthPixels = getResources().getDisplayMetrics().widthPixels;
|
||
reportTv.setLayoutParams(new LinearLayout.LayoutParams((widthPixels * 9) / 10,
|
||
LinearLayout.LayoutParams.WRAP_CONTENT));
|
||
reportTv.setPadding(DisplayUtils.dip2px(SuggestionActivity.this, 20), DisplayUtils.dip2px(SuggestionActivity.this, 12),
|
||
0, DisplayUtils.dip2px(SuggestionActivity.this, 12));
|
||
container.addView(reportTv);
|
||
|
||
reportTv.setOnClickListener(v -> {
|
||
dialog.cancel();
|
||
mSuggestContentEt.setText((mSuggestContentEt.getText().toString() + reportTv.getText().toString()));
|
||
mSuggestContentEt.setSelection(mSuggestContentEt.getText().length());
|
||
});
|
||
}
|
||
|
||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||
dialog.setContentView(container);
|
||
dialog.show();
|
||
}
|
||
|
||
@Override
|
||
public void loadDone() {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void loadDone(Object obj) {
|
||
if (selectGameDialog != null) {
|
||
selectGameDialog.cancel();
|
||
}
|
||
|
||
mSuggestSelectGame.setVisibility(View.GONE);
|
||
mSuggestGameName.setVisibility(View.VISIBLE);
|
||
if (obj instanceof InstallGameEntity) {
|
||
InstallGameEntity entity = (InstallGameEntity) obj;
|
||
mGameInfo = entity.getGameName() + "(" + entity.getPackageName() + ", " + entity.getGameVersion() + ")";
|
||
mSuggestGameName.setText(entity.getGameName());
|
||
} else {
|
||
String name = obj.toString().replace(" ", "");
|
||
mGameInfo = name;
|
||
mSuggestGameName.setText(name);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public void loadError() {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void loadEmpty() {
|
||
|
||
}
|
||
|
||
@OnClick({R.id.suggest_post_btn, R.id.suggest_game_container, R.id.type_accelerate, R.id.type_material,
|
||
R.id.type_other, R.id.type_standalone})
|
||
public void onViewClicked(View view) {
|
||
switch (view.getId()) {
|
||
case R.id.suggest_post_btn:
|
||
String email = mSuggestEmailEt.getText().toString().trim();
|
||
|
||
if (TextUtils.isEmpty(mSuggestContentEt.getText().toString()) &&
|
||
mSuggestType != SuggestType.functionSuggest &&
|
||
mSuggestType != SuggestType.gameCollect) {
|
||
toast("请输入反馈内容");
|
||
return;
|
||
}
|
||
|
||
if (mSuggestGameLl.getVisibility() == View.VISIBLE &&
|
||
TextUtils.isEmpty(mSuggestGameName.getText().toString())) {
|
||
toast("请选择游戏");
|
||
return;
|
||
}
|
||
|
||
if (mSuggestTypeContainer.getVisibility() == View.VISIBLE) {
|
||
if (mFunctionType == 3 && TextUtils.isEmpty(mTypeOtherName.getText().toString().trim())) {
|
||
toast("请选择功能需求");
|
||
return;
|
||
}
|
||
if (mFunctionType == -1) {
|
||
toast("请选择功能需求");
|
||
return;
|
||
}
|
||
}
|
||
|
||
if (mPlatformContainer.getVisibility() == View.VISIBLE &&
|
||
TextUtils.isEmpty(mPlatformEt.getText().toString())) {
|
||
toast("请填写版本");
|
||
return;
|
||
}
|
||
|
||
String entrance = "我的光环-反馈-[提交]";
|
||
if (!TextUtils.isEmpty(mSuggestContent)) {
|
||
switch (mSuggestContent) {
|
||
case "问题投诉":
|
||
entrance = "问题详情-投诉-提交反馈";
|
||
break;
|
||
case "回答投诉":
|
||
entrance = "回答详情-投诉-提交反馈";
|
||
break;
|
||
case "文章投诉":
|
||
entrance = "社区文章详情-投诉-提交反馈";
|
||
break;
|
||
}
|
||
}
|
||
// 闪退反馈不需要反馈(由闪退提示框跳转)
|
||
if (mSuggestType == SuggestType.crash && !mHideHint.isEmpty()) {
|
||
postSuggestion(email);
|
||
} else {
|
||
CheckLoginUtils.checkLogin(this, entrance, () -> {
|
||
postSuggestion(email);
|
||
});
|
||
}
|
||
break;
|
||
case R.id.suggest_game_container:
|
||
showSelectDialog();
|
||
break;
|
||
case R.id.type_accelerate:
|
||
mTypeAccelerate.setChecked(true);
|
||
mTypeMaterial.setChecked(false);
|
||
mTypeOther.setChecked(false);
|
||
mTypeStandalone.setChecked(false);
|
||
mFunctionType = 0;
|
||
mSuggestContentEt.requestFocus();
|
||
break;
|
||
case R.id.type_standalone:
|
||
mTypeAccelerate.setChecked(false);
|
||
mTypeMaterial.setChecked(false);
|
||
mTypeOther.setChecked(false);
|
||
mTypeStandalone.setChecked(true);
|
||
mFunctionType = 1;
|
||
mSuggestContentEt.requestFocus();
|
||
break;
|
||
case R.id.type_material:
|
||
mTypeAccelerate.setChecked(false);
|
||
mTypeMaterial.setChecked(true);
|
||
mTypeOther.setChecked(false);
|
||
mTypeStandalone.setChecked(false);
|
||
mFunctionType = 2;
|
||
mSuggestContentEt.requestFocus();
|
||
break;
|
||
case R.id.type_other:
|
||
mTypeAccelerate.setChecked(false);
|
||
mTypeMaterial.setChecked(false);
|
||
mTypeOther.setChecked(true);
|
||
mTypeStandalone.setChecked(false);
|
||
mFunctionType = 3;
|
||
mTypeOtherName.requestFocus();
|
||
break;
|
||
}
|
||
}
|
||
|
||
private void postSuggestion(String email) {
|
||
if (TextUtils.isEmpty(email)) {
|
||
if (mSuggestType == SuggestType.functionSuggest || mSuggestType == SuggestType.gameCollect) {
|
||
toast("请填写联系方式");
|
||
} else {
|
||
showConfirmDialog(email);
|
||
}
|
||
} else {
|
||
postDialog = WaitingDialogFragment.newInstance(getString(R.string.dialog_feedback_doing));
|
||
postDialog.show(getSupportFragmentManager(), null);
|
||
|
||
List<String> fileList = mAdapter.getFileList();
|
||
if (fileList != null && fileList.size() > 0) {
|
||
postPic(email);
|
||
} else {
|
||
initPostData(email, null);
|
||
}
|
||
}
|
||
}
|
||
|
||
// 弹出确认对话框
|
||
private void showConfirmDialog(final String email) {
|
||
|
||
DialogUtils.showWarningDialog(this, "温馨提示", "填写联系方式有助于我们更好地一对一解决您的问题,确定不填写吗?",
|
||
"直接提交", "我要填写",
|
||
() -> {
|
||
mSuggestEmailEt.requestFocus();
|
||
mSuggestEmailEt.postDelayed(() -> Util_System_Keyboard.showSoftKeyboard(getApplicationContext(), mSuggestEmailEt), 300);
|
||
},
|
||
() -> {
|
||
postDialog = WaitingDialogFragment.newInstance(getString(R.string.dialog_feedback_doing));
|
||
postDialog.show(getSupportFragmentManager(), null);
|
||
|
||
List<String> fileList = mAdapter.getFileList();
|
||
if (fileList != null && fileList.size() > 0) {
|
||
postPic(email);
|
||
} else {
|
||
initPostData(email, null);
|
||
}
|
||
});
|
||
}
|
||
|
||
private void postPic(final String email) {
|
||
UploadImageUtils.INSTANCE.compressAndUploadImageList(UploadImageUtils.UploadType.suggestion
|
||
, mAdapter.getFileList(), false, new UploadImageUtils.OnUploadImageListListener() {
|
||
@Override
|
||
public void onProgress(long total, long progress) {
|
||
int percent = (int) (100 * (progress / (float) total));
|
||
if (percent >= 100) percent = 99;
|
||
if (postDialog != null) {
|
||
postDialog.uploadWaitingHint("图片上传中 " + percent + "%");
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public void onSuccess(@NotNull LinkedHashMap<String, String> imageUrl) {
|
||
Utils.log("意见反馈:图片上传完成");
|
||
final JSONArray picArray = new JSONArray();
|
||
for (String s : imageUrl.keySet()) {
|
||
picArray.put(imageUrl.get(s));
|
||
}
|
||
initPostData(email, picArray);
|
||
}
|
||
|
||
@Override
|
||
public void onError() {
|
||
if (postDialog != null) {
|
||
postDialog.dismissAllowingStateLoss();
|
||
}
|
||
Utils.toast(SuggestionActivity.this, "上传失败");
|
||
Utils.log("意见反馈:图片上传失败");
|
||
}
|
||
});
|
||
}
|
||
|
||
private void initPostData(String email, JSONArray picArray) {
|
||
Map<String, String> params = new HashMap<>();
|
||
|
||
params.put("from", email);
|
||
params.put("ghversion", PackageUtils.getVersionName());
|
||
params.put("channel", HaloApp.getInstance().getChannel());
|
||
params.put("type", android.os.Build.MODEL);
|
||
params.put("sdk", String.valueOf(android.os.Build.VERSION.SDK_INT));
|
||
params.put("version", android.os.Build.VERSION.RELEASE);
|
||
params.put("source", getString(R.string.app_name));
|
||
params.put("imei", Util_System_Phone_State.getDeviceId(this));
|
||
params.put("manufacturer", Build.MANUFACTURER);
|
||
params.put("rom", RomIdentifier.getRom().name() + " " + RomIdentifier.getRom().getVersionName());
|
||
params.put("link", mLinkEt.getText().toString());
|
||
|
||
params.put("suggestion_type", mSuggestType.getType());
|
||
String message;
|
||
String content = mSuggestContentEt.getText().toString().trim();
|
||
if (mSuggestType == SuggestType.gameCollect) {
|
||
message = mGameInfo + "," + content;
|
||
} else if (mSuggestType == SuggestType.functionSuggest) {
|
||
String typeName;
|
||
if (mFunctionType == 3) {
|
||
typeName = "其他(" + mTypeOtherName.getText().toString().trim() + ")";
|
||
} else {
|
||
typeName = mFunctionTypeName[mFunctionType];
|
||
}
|
||
message = mGameInfo + "," + typeName + "," + content;
|
||
} else if (mSuggestType == SuggestType.gameQuestion) {
|
||
if (EntranceUtils.KEY_PLUGIN.equals(mSuggestHintType)) {
|
||
message = "【插件问题】" + content;
|
||
} else {
|
||
message = mSuggestGameName.getText() + "-" + mPlatformEt.getText() + "," + content;
|
||
}
|
||
} else {
|
||
message = content;
|
||
if (mSuggestType == SuggestType.crash) {
|
||
params.put("log", readFromFile());
|
||
}
|
||
}
|
||
message = mHideHint + message;
|
||
params.put("message", message);
|
||
|
||
JSONObject jsonObject = new JSONObject(params);
|
||
|
||
if (picArray != null && picArray.length() > 0) {
|
||
try {
|
||
jsonObject.put("pic", picArray);
|
||
} catch (JSONException e) {
|
||
e.printStackTrace();
|
||
}
|
||
}
|
||
|
||
sendSuggestion(jsonObject);
|
||
|
||
if (CheckLoginUtils.isLogin()) {
|
||
// 创建一条信息至七陌客服
|
||
String feedbackType = "意见反馈-" + mSuggestType.getType();
|
||
ImManager.sendFeedbackMessage(feedbackType + ": " + message);
|
||
}
|
||
}
|
||
|
||
private void sendSuggestion(JSONObject jsonObject) {
|
||
|
||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||
jsonObject.toString());
|
||
RetrofitManager.getInstance(this).getApi().postSuggestion(body)
|
||
.subscribeOn(Schedulers.io())
|
||
.observeOn(AndroidSchedulers.mainThread())
|
||
.subscribe(new Response<ResponseBody>() {
|
||
@Override
|
||
public void onResponse(ResponseBody response) {
|
||
if (postDialog != null) {
|
||
postDialog.dismissAllowingStateLoss();
|
||
}
|
||
setResult(SUGGEST_TYPE_REQUEST);
|
||
if (mHideHint.equals("APP闪退:")) {
|
||
showKefuReportDialog();
|
||
} else {
|
||
toast("感谢您的反馈!");
|
||
finish();
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public void onFailure(HttpException e) {
|
||
|
||
if (postDialog != null) {
|
||
postDialog.dismissAllowingStateLoss();
|
||
}
|
||
|
||
try {
|
||
if (e != null && e.code() == 403) {
|
||
String string = e.response().errorBody().string();
|
||
ErrorEntity error = GsonUtils.fromJson(string, ErrorEntity.class);
|
||
if (error.getCode() == 403052) {
|
||
DialogUtils.showAlertDialog(SuggestionActivity.this, "提醒", "你已经提交过相同的反馈了"
|
||
, "关闭提交", "返回修改", () -> {
|
||
setResult(SUGGEST_TYPE_REQUEST);
|
||
finish();
|
||
}, null);
|
||
return;
|
||
} else if (error.getCode() == 403062) {
|
||
DialogUtils.showAlertDialog(SuggestionActivity.this,
|
||
"提示", "光环助手已收录游戏:" + error.getData().getGameName(),
|
||
"退出并查看游戏", "仍然提交", () -> {
|
||
GameDetailActivity.startGameDetailActivity(SuggestionActivity.this,
|
||
error.getData().getGameId(), "(意见反馈-游戏收录-存在相同游戏)");
|
||
finish();
|
||
}, () -> {
|
||
try {
|
||
jsonObject.put("again", true);
|
||
} catch (Exception e1) {
|
||
e1.printStackTrace();
|
||
}
|
||
postDialog = WaitingDialogFragment.newInstance(getString(R.string.dialog_feedback_doing));
|
||
postDialog.show(getSupportFragmentManager(), null);
|
||
sendSuggestion(jsonObject);
|
||
});
|
||
return;
|
||
}
|
||
}
|
||
} catch (Exception e1) {
|
||
e1.printStackTrace();
|
||
}
|
||
|
||
toast("提交失败,请检查网络状态");
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
private void showSelectDialog() {
|
||
View view = View.inflate(this, R.layout.dialog_suggest_game, null);
|
||
RecyclerView recyclerView = view.findViewById(R.id.dialog_suggest_game_rv);
|
||
View back = view.findViewById(R.id.dialog_suggest_game_back);
|
||
ProgressBar pb = view.findViewById(R.id.dialog_suggest_game_load);
|
||
View manualBtn = view.findViewById(R.id.dialog_suggest_manual);
|
||
View manualContainer = view.findViewById(R.id.dialog_suggest_manual_container);
|
||
View manualConfirm = view.findViewById(R.id.dialog_suggest_confirm);
|
||
EditText manualEdit = view.findViewById(R.id.dialog_suggest_edit);
|
||
recyclerView.setLayoutManager(new GridLayoutManager(this, 4));
|
||
recyclerView.setAdapter(new SuggestSelectGameAdapter(this, pb));
|
||
|
||
selectGameDialog = new Dialog(this);
|
||
selectGameDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||
selectGameDialog.setCanceledOnTouchOutside(false);
|
||
selectGameDialog.setContentView(view);
|
||
selectGameDialog.show();
|
||
|
||
back.setOnClickListener(v -> selectGameDialog.cancel());
|
||
manualBtn.setOnClickListener(v -> {
|
||
manualContainer.setVisibility(View.VISIBLE);
|
||
manualBtn.setVisibility(View.GONE);
|
||
});
|
||
manualConfirm.setOnClickListener(v -> {
|
||
String gameName = manualEdit.getText().toString();
|
||
if (!TextUtils.isEmpty(gameName)) {
|
||
loadDone(gameName);
|
||
} else {
|
||
toast("请输入游戏名字");
|
||
}
|
||
});
|
||
}
|
||
|
||
public String readFromFile() {
|
||
|
||
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
||
|
||
File file = new File(getExternalFilesDir(null).getPath() + "/log");
|
||
if (file.isFile()) return "检测log文件夹是文件";
|
||
|
||
File[] files = file.listFiles();
|
||
if (files == null || files.length == 0) return "log文件夹为空" + file.getPath();
|
||
File targetFile = files[files.length - 1];
|
||
|
||
try {
|
||
if (!targetFile.exists()) {
|
||
targetFile.createNewFile();
|
||
return "No File error ";
|
||
} else {
|
||
InputStream in = new BufferedInputStream(new FileInputStream(targetFile));
|
||
BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8"));
|
||
String tmp;
|
||
StringBuffer string = new StringBuffer();
|
||
while ((tmp = br.readLine()) != null) {
|
||
string.append(tmp);
|
||
}
|
||
br.close();
|
||
in.close();
|
||
return string.toString();
|
||
}
|
||
} catch (Exception e) {
|
||
return e.toString();
|
||
}
|
||
} else {
|
||
return "SD Card error";
|
||
}
|
||
}
|
||
|
||
|
||
@Override
|
||
public <T> void onListClick(View view, int position, T data) {
|
||
if (!mAgreePostPic && !NetworkUtils.isWifiConnected(this)) {
|
||
mAgreePostPic = true;
|
||
DialogUtils.showAlertDialog(this,
|
||
"警告",
|
||
"当前使用移动网络,上传图片会消耗手机流量",
|
||
"我知道了", "", () -> {
|
||
List<String> picList = (List<String>) data;
|
||
if (position == mAdapter.getItemCount() - 1 && picList.size() < 5) {
|
||
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||
startActivityForResult(intent, MEDIA_STORE_REQUEST);
|
||
}
|
||
}, null);
|
||
return;
|
||
}
|
||
List<String> picList = (List<String>) data;
|
||
if (position == mAdapter.getItemCount() - 1 && picList.size() < 5) {
|
||
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||
startActivityForResult(intent, MEDIA_STORE_REQUEST);
|
||
}
|
||
}
|
||
|
||
private void showKefuReportDialog() {
|
||
// 只有是APP闪退反馈成功后弹出联系客服的弹窗
|
||
String str = "您也可以联系客服进一步描述闪退的情况,如果您反馈的是新问题,即有机会获得红包奖励";
|
||
DialogUtils.showWarningDialog(SuggestionActivity.this, "反馈成功", Html.fromHtml(str.substring(0, str.indexOf("红包奖励")) + "<font color='#FF0000'>红包奖励</font>"), "暂不", "联系客服",
|
||
() -> {
|
||
if (ShareUtils.isQQClientAvailable(this)) {
|
||
finish();
|
||
DirectUtils.directToQqConversation(this, "2586716223");
|
||
} else {
|
||
toast("本机未安装QQ应用");
|
||
}
|
||
},
|
||
this::finish);
|
||
}
|
||
|
||
@Override
|
||
protected boolean handleBackPressed() {
|
||
if (!TextUtils.isEmpty(mSuggestContentEt.getText().toString()) ||
|
||
!TextUtils.isEmpty(mSuggestGameName.getText().toString()) ||
|
||
!TextUtils.isEmpty(mLinkEt.getText().toString()) ||
|
||
!TextUtils.isEmpty(mPlatformEt.getText().toString()) ||
|
||
mAdapter.getFileList().size() > 0 ||
|
||
mFunctionType != -1) {
|
||
DialogUtils.showAlertDialog(this, "提示",
|
||
"确定放弃反馈吗?", "继续反馈", "放弃",
|
||
null, this::finish);
|
||
return true;
|
||
}
|
||
return super.handleBackPressed();
|
||
}
|
||
}
|