From 1cf13fc2a1caa4e2730538f8c4e01037d83a6f8f Mon Sep 17 00:00:00 2001 From: kehaoyuan Date: Fri, 23 Mar 2018 16:44:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E9=97=AE=E9=A1=B5=E9=9D=A2=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=E4=BC=98=E5=8C=96(=E8=BF=98=E5=B7=AE=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=B0=83=E8=AF=95)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 1 + .../base/fragment/WaitingDialogFragment.java | 10 + .../gamecenter/ask/QuestionsEditFragment.java | 377 +++++++++++------- .../ask/QuestionsEditIndexAdapter.java | 120 ++++++ .../ask/QuestionsEditIndexFragment.java | 64 +++ .../ask/QuestionsEditIndexViewHolder.java | 27 ++ .../QuestionsDetailFragment.java | 4 +- .../ask/search/AskSearchAdapter.java | 5 +- app/src/main/res/drawable/border_gray_bg.xml | 9 - .../res/layout/fragment_questions_edit.xml | 96 ++--- .../res/layout/layout_menu_question_post.xml | 17 + .../layout/menu_question_detail_more_item.xml | 120 +++--- .../res/layout/questions_edit_index_item.xml | 30 ++ .../main/res/layout/questions_edit_tag.xml | 96 +++++ app/src/main/res/menu/menu_question_post.xml | 11 + 15 files changed, 709 insertions(+), 278 deletions(-) create mode 100644 app/src/main/java/com/gh/gamecenter/ask/QuestionsEditIndexAdapter.java create mode 100644 app/src/main/java/com/gh/gamecenter/ask/QuestionsEditIndexFragment.java create mode 100644 app/src/main/java/com/gh/gamecenter/ask/QuestionsEditIndexViewHolder.java delete mode 100644 app/src/main/res/drawable/border_gray_bg.xml create mode 100644 app/src/main/res/layout/layout_menu_question_post.xml create mode 100644 app/src/main/res/layout/questions_edit_index_item.xml create mode 100644 app/src/main/res/layout/questions_edit_tag.xml create mode 100644 app/src/main/res/menu/menu_question_post.xml diff --git a/app/build.gradle b/app/build.gradle index 13773b7972..8152979835 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -176,6 +176,7 @@ dependencies { implementation "com.android.support:design:${androidSupport}" implementation "com.android.support:support-v4:${androidSupport}" implementation "com.android.support:appcompat-v7:${androidSupport}" + implementation "com.android.support:cardview-v7:${androidSupport}" implementation "com.android.support:support-annotations:${androidSupport}" implementation "com.android.support:percent:${androidSupport}" implementation "com.android.support.constraint:constraint-layout:${constraintLayout}" diff --git a/app/src/main/java/com/gh/base/fragment/WaitingDialogFragment.java b/app/src/main/java/com/gh/base/fragment/WaitingDialogFragment.java index 20fb62d83a..6dc1dc5522 100644 --- a/app/src/main/java/com/gh/base/fragment/WaitingDialogFragment.java +++ b/app/src/main/java/com/gh/base/fragment/WaitingDialogFragment.java @@ -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) { diff --git a/app/src/main/java/com/gh/gamecenter/ask/QuestionsEditFragment.java b/app/src/main/java/com/gh/gamecenter/ask/QuestionsEditFragment.java index f184dd01ac..98259d9b94 100644 --- a/app/src/main/java/com/gh/gamecenter/ask/QuestionsEditFragment.java +++ b/app/src/main/java/com/gh/gamecenter/ask/QuestionsEditFragment.java @@ -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 mNetWordTagList = new ArrayList<>(); private List mTagList = new ArrayList<>(); private List 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>() { @Override public void onResponse(List 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 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 picList = (List) 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 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 picList = (List) 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 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); - } - - } diff --git a/app/src/main/java/com/gh/gamecenter/ask/QuestionsEditIndexAdapter.java b/app/src/main/java/com/gh/gamecenter/ask/QuestionsEditIndexAdapter.java new file mode 100644 index 0000000000..3035ccc1df --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/ask/QuestionsEditIndexAdapter.java @@ -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 { + + private OnListClickListener mListClickListener; + private String mSearchKey; + + public QuestionsEditIndexAdapter(Context context, OnListClickListener listClickListener) { + super(context); + mListClickListener = listClickListener; + } + @Override + protected void setListData(List listData) { + if (listData == null) { + if (mEntityList != null) mEntityList.clear(); + } else { + mEntityList = new ArrayList<>(replayKeyword(listData)); + } + notifyDataSetChanged(); + } + + private List replayKeyword(List 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("", "").replace("", "") + .replace(mSearchKey, getHtmlKeyword()); + entity.setBrief(brief); + } + String title = entity.getQuestions().getTitle(); + if (!TextUtils.isEmpty(title)) { + title = title.replace("", "").replace("", "") + .replace(mSearchKey, getHtmlKeyword()); + Questions questions = entity.getQuestions(); + questions.setTitle(title); + entity.setQuestions(questions); + } + } + } + return listData; + } + + private String getHtmlKeyword() { + return "" + mSearchKey + ""; + } + + + @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; + } +} diff --git a/app/src/main/java/com/gh/gamecenter/ask/QuestionsEditIndexFragment.java b/app/src/main/java/com/gh/gamecenter/ask/QuestionsEditIndexFragment.java new file mode 100644 index 0000000000..7d1e45b5ba --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/ask/QuestionsEditIndexFragment.java @@ -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 { + private QuestionsEditIndexAdapter mAdapter; + + @Override + protected ListAdapter provideListAdapter() { + return mAdapter == null ? mAdapter = new QuestionsEditIndexAdapter(getContext(), this) : mAdapter; + } + + @Override + public Observable> 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); + } +} diff --git a/app/src/main/java/com/gh/gamecenter/ask/QuestionsEditIndexViewHolder.java b/app/src/main/java/com/gh/gamecenter/ask/QuestionsEditIndexViewHolder.java new file mode 100644 index 0000000000..a6431309f4 --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/ask/QuestionsEditIndexViewHolder.java @@ -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 { + @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); + } +} diff --git a/app/src/main/java/com/gh/gamecenter/ask/questionsdetail/QuestionsDetailFragment.java b/app/src/main/java/com/gh/gamecenter/ask/questionsdetail/QuestionsDetailFragment.java index 3699340ee9..44f65484e8 100644 --- a/app/src/main/java/com/gh/gamecenter/ask/questionsdetail/QuestionsDetailFragment.java +++ b/app/src/main/java/com/gh/gamecenter/ask/questionsdetail/QuestionsDetailFragment.java @@ -293,8 +293,8 @@ public class QuestionsDetailFragment extends ListFragment { @Override protected void setListData(List listData) { if (listData == null) { - mEntityList.clear(); + if (mEntityList != null) mEntityList.clear(); } else { - mEntityList.addAll(replayKeyword(listData)); + mEntityList = new ArrayList<>(replayKeyword(listData)); } notifyDataSetChanged(); } diff --git a/app/src/main/res/drawable/border_gray_bg.xml b/app/src/main/res/drawable/border_gray_bg.xml deleted file mode 100644 index 249192f977..0000000000 --- a/app/src/main/res/drawable/border_gray_bg.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_questions_edit.xml b/app/src/main/res/layout/fragment_questions_edit.xml index 1dcd5c042c..0ea3fc0b44 100644 --- a/app/src/main/res/layout/fragment_questions_edit.xml +++ b/app/src/main/res/layout/fragment_questions_edit.xml @@ -6,52 +6,13 @@ + android:layout_height = "match_parent" > - - - - - - - - - - - @@ -103,6 +65,7 @@ + android:textSize = "13sp" + android:text="@string/question_edit_hint"/> - + + + + + + + + + + + - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/layout_menu_question_post.xml b/app/src/main/res/layout/layout_menu_question_post.xml new file mode 100644 index 0000000000..4635d64034 --- /dev/null +++ b/app/src/main/res/layout/layout_menu_question_post.xml @@ -0,0 +1,17 @@ + + + + + + diff --git a/app/src/main/res/layout/menu_question_detail_more_item.xml b/app/src/main/res/layout/menu_question_detail_more_item.xml index e6838f1dce..c10d108d2b 100644 --- a/app/src/main/res/layout/menu_question_detail_more_item.xml +++ b/app/src/main/res/layout/menu_question_detail_more_item.xml @@ -1,71 +1,83 @@ - - - - - - - - + app:cardCornerRadius = "0dp" + app:cardElevation="3dp" + app:cardUseCompatPadding = "true" > + android:background = "@android:color/white" + android:orientation = "vertical" + android:paddingBottom = "2.5dp" + android:paddingTop = "2.5dp" > - + android:background = "@drawable/reuse_listview_item_style" + android:gravity = "center_vertical" + android:paddingRight = "25dp" > - + + + + + + + android:background = "@drawable/reuse_listview_item_style" + android:gravity = "center_vertical" + android:orientation = "horizontal" + android:paddingRight = "25dp" > + + + + + + + - - \ No newline at end of file + diff --git a/app/src/main/res/layout/questions_edit_index_item.xml b/app/src/main/res/layout/questions_edit_index_item.xml new file mode 100644 index 0000000000..19478083e8 --- /dev/null +++ b/app/src/main/res/layout/questions_edit_index_item.xml @@ -0,0 +1,30 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/questions_edit_tag.xml b/app/src/main/res/layout/questions_edit_tag.xml new file mode 100644 index 0000000000..df4ed5a244 --- /dev/null +++ b/app/src/main/res/layout/questions_edit_tag.xml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/menu_question_post.xml b/app/src/main/res/menu/menu_question_post.xml new file mode 100644 index 0000000000..a40121c025 --- /dev/null +++ b/app/src/main/res/menu/menu_question_post.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file