提问页面流程优化(还差接口调试)
This commit is contained in:
@ -26,6 +26,16 @@ public class WaitingDialogFragment extends BaseDialogFragment {
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public static WaitingDialogFragment newInstance(String message, boolean isCancelable) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(KEY_MSG, message);
|
||||
WaitingDialogFragment fragment = new WaitingDialogFragment();
|
||||
fragment.setArguments(args);
|
||||
fragment.setCancelable(isCancelable);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
||||
@ -1,25 +1,31 @@
|
||||
package com.gh.gamecenter.ask;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Html;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
@ -32,6 +38,7 @@ 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.NetworkUtils;
|
||||
import com.gh.gamecenter.NormalActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.ask.entity.QuestionsDetailEntity;
|
||||
@ -52,7 +59,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
@ -68,27 +74,30 @@ import static com.gh.gamecenter.SuggestionActivity.MEDIA_STORE_REQUEST;
|
||||
|
||||
public class QuestionsEditFragment extends NormalFragment {
|
||||
|
||||
@BindView(R.id.questionsedit_tag)
|
||||
FlexboxLayout mTagFl;
|
||||
@BindView(R.id.questionsedit_title)
|
||||
EditText mTitle;
|
||||
@BindView(R.id.questionsedit_content)
|
||||
EditText mContent;
|
||||
@BindView(R.id.suggest_pic_rv)
|
||||
RecyclerView mPicRv;
|
||||
@BindView(R.id.questionsedit_tag_add)
|
||||
TextView mTagAdd;
|
||||
@BindView(R.id.questionsedit_tips)
|
||||
TextView mTips;
|
||||
@BindView(R.id.questionsedit_index_cv)
|
||||
View mIndexView;
|
||||
|
||||
private FlexboxLayout mTagFl;
|
||||
|
||||
private static final int QUESTION_TITLE_MAX_LENGTH = 50;
|
||||
private static final int QUESTION_TAG_MAX_COUNT = 5;
|
||||
|
||||
private QuestionsEditPicAdapter mAdapter;
|
||||
|
||||
private WaitingDialogFragment mPostDialog;
|
||||
|
||||
private List<String> mNetWordTagList = new ArrayList<>();
|
||||
private List<String> mTagList = new ArrayList<>();
|
||||
private List<String> mAllTagList = new ArrayList<>();
|
||||
|
||||
private String mSearchKey;
|
||||
private Boolean mAgreePostPic;
|
||||
|
||||
|
||||
@Override
|
||||
@ -132,6 +141,23 @@ public class QuestionsEditFragment extends NormalFragment {
|
||||
return R.layout.fragment_questions_edit;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onMenuItemClick(MenuItem menuItem) {
|
||||
if (menuItem.getItemId() == R.id.menu_question_post) {
|
||||
for (int i = mNetWordTagList.size() - 1; i >= 0; i--) {
|
||||
addTag(mNetWordTagList.get(i), false);
|
||||
}
|
||||
CheckLoginUtils.checkLogin(getContext(), this::showTagDialog);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
initMenu(R.menu.menu_question_post);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -140,6 +166,7 @@ public class QuestionsEditFragment extends NormalFragment {
|
||||
mSearchKey = arguments.getString(EntranceUtils.KEY_SEARCHKEY);
|
||||
}
|
||||
getCommunitiesTags();
|
||||
mAgreePostPic = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -152,8 +179,6 @@ public class QuestionsEditFragment extends NormalFragment {
|
||||
mTitle.setSelection(mTitle.getText().toString().length());
|
||||
}
|
||||
|
||||
mTips.setText(Html.fromHtml(getString(R.string.question_edit_hint)));
|
||||
|
||||
// 意见反馈上传图片列表
|
||||
mPicRv.setLayoutManager(new GridLayoutManager(getContext(), 5) {
|
||||
@Override
|
||||
@ -165,30 +190,57 @@ public class QuestionsEditFragment extends NormalFragment {
|
||||
mPicRv.setAdapter(mAdapter);
|
||||
|
||||
mTitle.setOnEditorActionListener((v, actionId, event) -> (event.getKeyCode() == KeyEvent.KEYCODE_ENTER));
|
||||
|
||||
mTitle.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
if (s.toString().length() == 0) {
|
||||
addQuestionsIndexFragment(false, null);
|
||||
} else {
|
||||
addQuestionsIndexFragment(true, s.toString());
|
||||
}
|
||||
|
||||
if (s.length() > QUESTION_TITLE_MAX_LENGTH) {
|
||||
mTitle.setText("");
|
||||
String newText = s.toString().substring(0, QUESTION_TITLE_MAX_LENGTH);
|
||||
mTitle.setText(newText);
|
||||
mTitle.setSelection(mTitle.getText().length());
|
||||
Utils.toast(getContext(), "标题字数已超过50个字");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@OnClick({R.id.questionsedit_tag_add, R.id.questionsedit_post, R.id.questionsedit_tips})
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.questionsedit_tag_add:
|
||||
if (mTagList.size() < 3) {
|
||||
showAddTagDialog();
|
||||
} else {
|
||||
toast(R.string.questionsdetail_max_tag_hint);
|
||||
}
|
||||
break;
|
||||
case R.id.questionsedit_post:
|
||||
mPostDialog = WaitingDialogFragment.newInstance(getString(R.string.vote_post));
|
||||
mPostDialog.show(getChildFragmentManager(), null);
|
||||
|
||||
CheckLoginUtils.checkLogin(getContext(), () -> {
|
||||
postQuestions(mAdapter.getFileList());
|
||||
});
|
||||
break;
|
||||
// case R.id.questionsedit_tips:
|
||||
// startActivity(WebActivity.getIntentByUrl(getContext(), getString(R.string.questionsedit_tips_url)));
|
||||
// break;
|
||||
private void addQuestionsIndexFragment(boolean isShow, String searchKey) {
|
||||
if (isShow) {
|
||||
mIndexView.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mIndexView.setVisibility(View.GONE);
|
||||
return;
|
||||
}
|
||||
|
||||
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
|
||||
Fragment fragment = getChildFragmentManager().findFragmentByTag(QuestionsEditIndexFragment.class.getSimpleName());
|
||||
if (fragment != null && fragment instanceof QuestionsEditIndexFragment) {
|
||||
((QuestionsEditIndexFragment) fragment).search(""); // TODO: 23/03/18
|
||||
} else {
|
||||
QuestionsEditIndexFragment indexFragment = new QuestionsEditIndexFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(EntranceUtils.KEY_ENTRANCE, mEntrance);
|
||||
indexFragment.setArguments(args);
|
||||
transaction.add(R.id.questionsedit_index, indexFragment, QuestionsEditIndexFragment.class.getSimpleName());
|
||||
}
|
||||
transaction.commitAllowingStateLoss();
|
||||
}
|
||||
|
||||
private void postImg(String picturePath) {
|
||||
@ -235,9 +287,7 @@ public class QuestionsEditFragment extends NormalFragment {
|
||||
.subscribe(new Response<List<String>>() {
|
||||
@Override
|
||||
public void onResponse(List<String> response) {
|
||||
for (int i = response.size() - 1; i >= 0; i--) {
|
||||
addTag(response.get(i), false);
|
||||
}
|
||||
mNetWordTagList = response;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -249,6 +299,9 @@ public class QuestionsEditFragment extends NormalFragment {
|
||||
}
|
||||
|
||||
private void postQuestions(List<String> imgs) {
|
||||
mPostDialog = WaitingDialogFragment.newInstance(getString(R.string.vote_post), true);
|
||||
mPostDialog.show(getChildFragmentManager(), null);
|
||||
|
||||
String title = mTitle.getText().toString().trim();
|
||||
if (TextUtils.isEmpty(title)) {
|
||||
toast("标题不能为空");
|
||||
@ -262,7 +315,7 @@ public class QuestionsEditFragment extends NormalFragment {
|
||||
return;
|
||||
}
|
||||
|
||||
if (title.length() < 50) {
|
||||
if (title.length() <= 50) {
|
||||
String endString = title.substring(title.length() - 1, title.length());
|
||||
if (!"?".equals(endString) && !"?".equals(endString))
|
||||
title += "?";
|
||||
@ -291,8 +344,8 @@ public class QuestionsEditFragment extends NormalFragment {
|
||||
JSONObject object = new JSONObject(response.string());
|
||||
if (getActivity() != null) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(EntranceUtils.KEY_QUESTIONS_ID, object.getString("_id"));
|
||||
bundle.putString(EntranceUtils.KEY_ENTRANCE, "(回答编辑)");
|
||||
bundle.putString(EntranceUtils.KEY_QUESTIONS_ID, object.getString("_id"));
|
||||
bundle.putString(EntranceUtils.KEY_ENTRANCE, "(回答编辑)");
|
||||
NormalActivity.startFragment(getContext(), QuestionsDetailFragment.class, bundle);
|
||||
getActivity().finish();
|
||||
}
|
||||
@ -311,6 +364,138 @@ public class QuestionsEditFragment extends NormalFragment {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListClick(View view, int position, Object data) {
|
||||
super.onListClick(view, position, data);
|
||||
List<String> picList = (List<String>) data;
|
||||
if (position == mAdapter.getItemCount() - 1) {
|
||||
if (picList.size() < 3) {
|
||||
if (NetworkUtils.isWifiConnected(getContext()) || mAgreePostPic != null && mAgreePostPic) {
|
||||
addPic();
|
||||
} else {
|
||||
if (mAgreePostPic == null)
|
||||
DialogUtils.showAlertDialog(getContext(),
|
||||
"警告",
|
||||
"当前使用移动网络,上传图片会消耗流量,确定上传吗?",
|
||||
"继续上传", "取消",
|
||||
() -> {
|
||||
mAgreePostPic = true;
|
||||
addPic();
|
||||
}, () -> {
|
||||
mAgreePostPic = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void addPic() {
|
||||
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||
startActivityForResult(intent, MEDIA_STORE_REQUEST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBackPressed() {
|
||||
List<String> imgList = mAdapter.getFileList();
|
||||
String title = mTitle.getText().toString().trim();
|
||||
String content = mContent.getText().toString().trim();
|
||||
if (imgList.size() > 0 || title.length() > 0 || content.length() > 0) {
|
||||
showEditBackDialog();
|
||||
return true;
|
||||
}
|
||||
return super.onBackPressed();
|
||||
}
|
||||
|
||||
private void showEditBackDialog() {
|
||||
DialogUtils.showCancelAlertDialog(getActivity(), "提示", "确定放弃提问吗?"
|
||||
, "再想想", " 放弃", null, () -> {
|
||||
if (getActivity() != null) getActivity().finish();
|
||||
});
|
||||
}
|
||||
|
||||
private void showTagDialog() {
|
||||
View view = LayoutInflater.from(getContext()).inflate(R.layout.questions_edit_tag, null);
|
||||
Dialog dialog = new Dialog(getActivity());
|
||||
dialog.setContentView(view);
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
dialog.setCancelable(false);
|
||||
Window window = dialog.getWindow();
|
||||
if (window != null) {
|
||||
window.setGravity(Gravity.BOTTOM);
|
||||
window.setBackgroundDrawable(new ColorDrawable(0));
|
||||
window.setDimAmount(0.2f);
|
||||
WindowManager.LayoutParams lp = window.getAttributes();
|
||||
lp.width = getActivity().getWindowManager().getDefaultDisplay().getWidth();
|
||||
window.setAttributes(lp);
|
||||
|
||||
mTagFl = view.findViewById(R.id.questions_edit_tag);
|
||||
View add = view.findViewById(R.id.questions_edit_tag_add);
|
||||
view.findViewById(R.id.questions_edit_tag_cancel).setOnClickListener(v -> dialog.dismiss());
|
||||
view.findViewById(R.id.questions_edit_tag_positive).setOnClickListener(v -> postQuestions(mAdapter.getFileList()));
|
||||
add.setOnClickListener(v -> {
|
||||
if (mTagList.size() < QUESTION_TAG_MAX_COUNT) {
|
||||
showAddTagDialog();
|
||||
} else {
|
||||
toast(R.string.questionsdetail_max_tag_hint);
|
||||
}
|
||||
});
|
||||
}
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
|
||||
private void showAddTagDialog() {
|
||||
final Dialog dialog = new Dialog(getContext());
|
||||
|
||||
View view = View.inflate(getContext(), R.layout.dialog_modify_nickname, null);
|
||||
|
||||
TextView title = view.findViewById(R.id.dialog_nickname_title);
|
||||
title.setText(R.string.vote_input_hint);
|
||||
|
||||
final EditText input = view.findViewById(R.id.dialog_nickname_input);
|
||||
input.setHint("");
|
||||
input.setSelection(input.getText().length());
|
||||
|
||||
input.setOnEditorActionListener((v, actionId, event) -> {
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
String nickname = input.getText().toString().trim();
|
||||
if (TextUtils.isEmpty(nickname)) {
|
||||
toast(R.string.vote_empty_hint);
|
||||
return true;
|
||||
}
|
||||
addTag(nickname, true);
|
||||
dialog.dismiss();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
// 取消按钮
|
||||
TextView cancel = view.findViewById(R.id.dialog_nickname_cancel);
|
||||
cancel.setOnClickListener(v -> dialog.dismiss());
|
||||
|
||||
// 确定按钮
|
||||
TextView confirm = view.findViewById(R.id.dialog_nickname_confirm);
|
||||
confirm.setOnClickListener(v -> {
|
||||
String nickname = input.getText().toString().trim();
|
||||
if (TextUtils.isEmpty(nickname)) {
|
||||
toast(R.string.vote_empty_hint);
|
||||
return;
|
||||
}
|
||||
addTag(nickname, true);
|
||||
dialog.dismiss();
|
||||
});
|
||||
|
||||
dialog.setOnDismissListener(dialog1 -> Util_System_Keyboard.hideSoftKeyboard(getActivity()));
|
||||
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
|
||||
mBaseHandler.postDelayed(() -> Util_System_Keyboard.showSoftKeyboard(getContext(), input), 300);
|
||||
}
|
||||
|
||||
private void addTag(String tag, boolean isAdd) {
|
||||
if (mAllTagList.contains(tag)) {
|
||||
toast("标签已经存在");
|
||||
@ -328,7 +513,7 @@ public class QuestionsEditFragment extends NormalFragment {
|
||||
mTagList.remove(text);
|
||||
tagTv.setBackgroundResource(R.drawable.border_suggest_bg);
|
||||
tagTv.setTextColor(ContextCompat.getColor(getContext(), R.color.content));
|
||||
} else if (mTagList.size() < 3) {
|
||||
} else if (mTagList.size() < QUESTION_TAG_MAX_COUNT) {
|
||||
mTagList.add(text);
|
||||
tagTv.setBackgroundResource(R.drawable.comment_border_bg);
|
||||
tagTv.setTextColor(ContextCompat.getColor(getContext(), R.color.theme));
|
||||
@ -337,7 +522,7 @@ public class QuestionsEditFragment extends NormalFragment {
|
||||
}
|
||||
});
|
||||
if (isAdd) {
|
||||
if (mTagList.size() < 3) {
|
||||
if (mTagList.size() < QUESTION_TAG_MAX_COUNT) {
|
||||
mTagList.add(tag);
|
||||
tagTv.setBackgroundResource(R.drawable.comment_border_bg);
|
||||
tagTv.setTextColor(ContextCompat.getColor(getContext(), R.color.theme));
|
||||
@ -348,117 +533,7 @@ public class QuestionsEditFragment extends NormalFragment {
|
||||
FlexboxLayout.LayoutParams params = new FlexboxLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
params.setMargins(0, DisplayUtils.dip2px(getContext(), 5), DisplayUtils.dip2px(getContext(), 15), DisplayUtils.dip2px(getContext(), 5));
|
||||
tagTv.setLayoutParams(params);
|
||||
mTagFl.addView(view, 0);
|
||||
if (mTagFl != null) mTagFl.addView(view, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListClick(View view, int position, Object data) {
|
||||
super.onListClick(view, position, data);
|
||||
List<String> picList = (List<String>) data;
|
||||
if (position == mAdapter.getItemCount() - 1) {
|
||||
if (picList.size() < 3) {
|
||||
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||
startActivityForResult(intent, MEDIA_STORE_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBackPressed() {
|
||||
List<String> imgList = mAdapter.getFileList();
|
||||
String title = mTitle.getText().toString().trim();
|
||||
String content = mContent.getText().toString().trim();
|
||||
if (imgList.size() > 0 || title.length() > 0 || content.length() > 0) {
|
||||
showEditBackDialog();
|
||||
return true;
|
||||
}
|
||||
return super.onBackPressed();
|
||||
}
|
||||
|
||||
private void showEditBackDialog() {
|
||||
DialogUtils.showCancelAlertDialog(getActivity(), "提示", "确定放弃提问吗?"
|
||||
, "再想想", " 放弃", null, new DialogUtils.CancelListener() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
if (getActivity() != null) getActivity().finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// todo 重构
|
||||
private void showAddTagDialog() {
|
||||
final Dialog dialog = new Dialog(getContext());
|
||||
|
||||
View view = View.inflate(getContext(), R.layout.dialog_modify_nickname, null);
|
||||
|
||||
TextView title = (TextView) view.findViewById(R.id.dialog_nickname_title);
|
||||
title.setText(R.string.vote_input_hint);
|
||||
|
||||
final EditText input = (EditText) view.findViewById(R.id.dialog_nickname_input);
|
||||
input.setHint("");
|
||||
input.setSelection(input.getText().length());
|
||||
|
||||
input.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
String nickname = input.getText().toString().trim();
|
||||
if (TextUtils.isEmpty(nickname)) {
|
||||
toast(R.string.vote_empty_hint);
|
||||
return true;
|
||||
}
|
||||
addTag(nickname, true);
|
||||
dialog.dismiss();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// 取消按钮
|
||||
TextView cancel = (TextView) view.findViewById(R.id.dialog_nickname_cancel);
|
||||
cancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
// 确定按钮
|
||||
TextView confirm = (TextView) view.findViewById(R.id.dialog_nickname_confirm);
|
||||
confirm.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String nickname = input.getText().toString().trim();
|
||||
if (TextUtils.isEmpty(nickname)) {
|
||||
toast(R.string.vote_empty_hint);
|
||||
return;
|
||||
}
|
||||
addTag(nickname, true);
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
Util_System_Keyboard.hideSoftKeyboard(getActivity());
|
||||
}
|
||||
});
|
||||
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
|
||||
mTagAdd.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Util_System_Keyboard.showSoftKeyboard(getContext(), input);
|
||||
}
|
||||
}, 300);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,120 @@
|
||||
package com.gh.gamecenter.ask;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Html;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.gh.base.OnListClickListener;
|
||||
import com.gh.common.constant.ItemViewType;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder;
|
||||
import com.gh.gamecenter.ask.entity.AskSearchEntity;
|
||||
import com.gh.gamecenter.ask.entity.Questions;
|
||||
import com.gh.gamecenter.baselist.ListAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by khy on 22/03/18.
|
||||
*/
|
||||
|
||||
public class QuestionsEditIndexAdapter extends ListAdapter<AskSearchEntity> {
|
||||
|
||||
private OnListClickListener mListClickListener;
|
||||
private String mSearchKey;
|
||||
|
||||
public QuestionsEditIndexAdapter(Context context, OnListClickListener listClickListener) {
|
||||
super(context);
|
||||
mListClickListener = listClickListener;
|
||||
}
|
||||
@Override
|
||||
protected void setListData(List<AskSearchEntity> listData) {
|
||||
if (listData == null) {
|
||||
if (mEntityList != null) mEntityList.clear();
|
||||
} else {
|
||||
mEntityList = new ArrayList<>(replayKeyword(listData));
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private List<AskSearchEntity> replayKeyword(List<AskSearchEntity> listData) {
|
||||
for (int i = 0; i < listData.size(); i++) {
|
||||
if (!TextUtils.isEmpty(mSearchKey)) {
|
||||
AskSearchEntity entity = listData.get(i);
|
||||
String brief = entity.getBrief();
|
||||
if (!TextUtils.isEmpty(brief)) {
|
||||
brief = brief.replace("<em>", "").replace("</em>", "")
|
||||
.replace(mSearchKey, getHtmlKeyword());
|
||||
entity.setBrief(brief);
|
||||
}
|
||||
String title = entity.getQuestions().getTitle();
|
||||
if (!TextUtils.isEmpty(title)) {
|
||||
title = title.replace("<em>", "").replace("</em>", "")
|
||||
.replace(mSearchKey, getHtmlKeyword());
|
||||
Questions questions = entity.getQuestions();
|
||||
questions.setTitle(title);
|
||||
entity.setQuestions(questions);
|
||||
}
|
||||
}
|
||||
}
|
||||
return listData;
|
||||
}
|
||||
|
||||
private String getHtmlKeyword() {
|
||||
return "<font color=\"#ff4147\">" + mSearchKey + "</font>";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (position == getItemCount() - 1) return ItemViewType.ITEM_FOOTER;
|
||||
return ItemViewType.ITEM_BODY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view;
|
||||
switch (viewType) {
|
||||
case ItemViewType.ITEM_FOOTER:
|
||||
view = mLayoutInflater.inflate(R.layout.refresh_footerview, parent, false);
|
||||
return new FooterViewHolder(view, mListClickListener);
|
||||
case ItemViewType.ITEM_BODY:
|
||||
view = mLayoutInflater.inflate(R.layout.questions_edit_index_item, parent, false);
|
||||
return new QuestionsEditIndexViewHolder(view, mListClickListener);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
switch (getItemViewType(position)) {
|
||||
case ItemViewType.ITEM_BODY:
|
||||
AskSearchEntity searchEntity = mEntityList.get(position);
|
||||
Questions questions = searchEntity.getQuestions();
|
||||
QuestionsEditIndexViewHolder viewHolder = (QuestionsEditIndexViewHolder) holder;
|
||||
viewHolder.mIndexTitle.setText(Html.fromHtml(questions.getTitle()));
|
||||
viewHolder.setClickData(searchEntity);
|
||||
viewHolder.mIndexAnswerCount.setText(mContext.getString(R.string.ask_answer_count, questions.getAnswerCount()));
|
||||
break;
|
||||
case ItemViewType.ITEM_FOOTER:
|
||||
FooterViewHolder footerViewHolder = (FooterViewHolder) holder;
|
||||
footerViewHolder.initItemPadding();
|
||||
footerViewHolder.initFooterViewHolder(mIsNetworkError, mIsOver, R.string.ask_loadover_hint);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mEntityList == null || mEntityList.isEmpty() ? 0 : mEntityList.size() + FOOTER_ITEM_COUNT;
|
||||
}
|
||||
|
||||
public void setSearchKey(String searchKey) {
|
||||
this.mSearchKey = searchKey;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,64 @@
|
||||
package com.gh.gamecenter.ask;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.gamecenter.NormalActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.ask.entity.AskSearchEntity;
|
||||
import com.gh.gamecenter.ask.entity.Questions;
|
||||
import com.gh.gamecenter.ask.questionsdetail.QuestionsDetailFragment;
|
||||
import com.gh.gamecenter.baselist.ListAdapter;
|
||||
import com.gh.gamecenter.baselist.ListFragment;
|
||||
import com.gh.gamecenter.baselist.LoadType;
|
||||
import com.gh.gamecenter.baselist.NormalListViewModel;
|
||||
import com.gh.gamecenter.manager.UserManager;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import rx.Observable;
|
||||
|
||||
/**
|
||||
* Created by khy on 22/03/18.
|
||||
*/
|
||||
|
||||
public class QuestionsEditIndexFragment extends ListFragment<AskSearchEntity, NormalListViewModel> {
|
||||
private QuestionsEditIndexAdapter mAdapter;
|
||||
|
||||
@Override
|
||||
protected ListAdapter provideListAdapter() {
|
||||
return mAdapter == null ? mAdapter = new QuestionsEditIndexAdapter(getContext(), this) : mAdapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<List<AskSearchEntity>> provideDataObservable(int offset) {
|
||||
return RetrofitManager.getInstance(getContext()).getApi().getAskSearch(UserManager.getInstance().getCommunityId(getContext()), "一", offset);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListClick(View view, int position, Object data) {
|
||||
switch (view.getId()) {
|
||||
case R.id.footerview_item:
|
||||
if (mAdapter.isNetworkError()) {
|
||||
mListViewModel.load(LoadType.RETRY);
|
||||
}
|
||||
break;
|
||||
case R.id.questions_edit_index_title:
|
||||
String tracers = mEntrance + "+(标题自动搜索)";
|
||||
AskSearchEntity entity = (AskSearchEntity) data;
|
||||
Questions questions = entity.getQuestions();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(EntranceUtils.KEY_QUESTIONS_ID, questions.getId());
|
||||
bundle.putString(EntranceUtils.KEY_ENTRANCE, tracers);
|
||||
NormalActivity.startFragment(getContext(), QuestionsDetailFragment.class, bundle);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void search(String key) {
|
||||
mAdapter.setSearchKey(key);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package com.gh.gamecenter.ask;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseRecyclerViewHolder;
|
||||
import com.gh.base.OnListClickListener;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.ask.entity.AskSearchEntity;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
/**
|
||||
* Created by khy on 23/03/18.
|
||||
*/
|
||||
|
||||
public class QuestionsEditIndexViewHolder extends BaseRecyclerViewHolder<AskSearchEntity> {
|
||||
@BindView(R.id.questions_edit_index_title)
|
||||
TextView mIndexTitle;
|
||||
@BindView(R.id.questions_edit_index_answer_count)
|
||||
TextView mIndexAnswerCount;
|
||||
|
||||
public QuestionsEditIndexViewHolder(View itemView, OnListClickListener listClickListener) {
|
||||
super(itemView, listClickListener);
|
||||
mIndexTitle.setOnClickListener(this);
|
||||
}
|
||||
}
|
||||
@ -293,8 +293,8 @@ public class QuestionsDetailFragment extends ListFragment<AnswerEntity, NormalLi
|
||||
window.setBackgroundDrawable(new ColorDrawable(0));
|
||||
window.setDimAmount(0.2f);
|
||||
WindowManager.LayoutParams lp = window.getAttributes();
|
||||
lp.x = DisplayUtils.dip2px(getContext(), 20);
|
||||
lp.y = DisplayUtils.dip2px(getContext(), 50);
|
||||
lp.x = DisplayUtils.dip2px(getContext(), 17);
|
||||
lp.y = DisplayUtils.dip2px(getContext(), 45); // 减去卡片高度
|
||||
window.setAttributes(lp);
|
||||
}
|
||||
dialog.show();
|
||||
|
||||
@ -17,6 +17,7 @@ import com.gh.gamecenter.ask.entity.AskSearchEntity;
|
||||
import com.gh.gamecenter.ask.entity.Questions;
|
||||
import com.gh.gamecenter.baselist.ListAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -37,9 +38,9 @@ public class AskSearchAdapter extends ListAdapter<AskSearchEntity> {
|
||||
@Override
|
||||
protected void setListData(List<AskSearchEntity> listData) {
|
||||
if (listData == null) {
|
||||
mEntityList.clear();
|
||||
if (mEntityList != null) mEntityList.clear();
|
||||
} else {
|
||||
mEntityList.addAll(replayKeyword(listData));
|
||||
mEntityList = new ArrayList<>(replayKeyword(listData));
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user