问题详情与邀请回答优化(完成)
This commit is contained in:
@ -65,6 +65,7 @@ public class EntranceUtils {
|
||||
public static final String KEY_QUESTIONS_ID = "questionsId";
|
||||
public static final String KEY_QUESTIONS_TITLE = "questionsTitle";
|
||||
public static final String KEY_QUESTIONS_PATCH = "questionsPatch";
|
||||
public static final String KEY_INVITE_SEARCH_KEY = "inviteSearchKey";
|
||||
|
||||
public static void jumpActivity(Context context, Bundle bundle) {
|
||||
|
||||
|
||||
@ -147,6 +147,7 @@ public class ShareUtils {
|
||||
|
||||
|
||||
public void showShareWindows(Activity activity, View view, String url, String icon, String shareTitle, String shareSummary, ShareType shareType) {
|
||||
if (activity.isFinishing()) return;
|
||||
this.mActivity = activity;
|
||||
this.shareIcon = icon;
|
||||
this.shareUrl = url;
|
||||
@ -154,7 +155,7 @@ public class ShareUtils {
|
||||
this.mTitle = shareTitle;
|
||||
this.mShareType = shareType;
|
||||
|
||||
View contentView = View.inflate(mContext, R.layout.share_popup_layout, null);
|
||||
View contentView = View.inflate(mActivity, R.layout.share_popup_layout, null);
|
||||
contentView.setFocusable(true);
|
||||
contentView.setFocusableInTouchMode(true);
|
||||
RecyclerView shareRecyclerView = (RecyclerView) contentView.findViewById(R.id.share_rv);
|
||||
@ -190,7 +191,11 @@ public class ShareUtils {
|
||||
popupWindow = new PopupWindow(contentView, LinearLayout.LayoutParams.MATCH_PARENT
|
||||
, LinearLayout.LayoutParams.MATCH_PARENT, true);
|
||||
popupWindow.setAnimationStyle(R.style.mypopwindow_anim_style);
|
||||
popupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
|
||||
try {
|
||||
popupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
contentView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
||||
@ -17,12 +17,13 @@ import com.gh.gamecenter.ask.entity.QuestionsDetailEntity;
|
||||
import com.gh.gamecenter.ask.questionsdetail.AnswerEditFragment;
|
||||
import com.gh.gamecenter.ask.questionsdetail.AnswerFoldFragment;
|
||||
import com.gh.gamecenter.ask.questionsdetail.QuestionsDetailFragment;
|
||||
import com.gh.gamecenter.ask.questionsdetail.QuestionsInviteFragment;
|
||||
import com.gh.gamecenter.ask.questionsdetail.invite.QuestionsInviteFragment;
|
||||
|
||||
/**
|
||||
* Created by khy on 7/12/17.
|
||||
*/
|
||||
|
||||
@Deprecated
|
||||
public class QuestionsDetailActivity extends BaseActivity implements FragmentManager.OnBackStackChangedListener, View.OnClickListener {
|
||||
|
||||
public static final String TAG = "QuestionsDetailActivity";
|
||||
@ -87,20 +88,20 @@ public class QuestionsDetailActivity extends BaseActivity implements FragmentMan
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (view == mShareIv) {
|
||||
String shreIcon;
|
||||
String shareIcon;
|
||||
QuestionsDetailEntity data = mQuestionsDetailFragment.getQuestionsDetailData();
|
||||
if (data == null) return;
|
||||
if (data.getImages().size() > 0) {
|
||||
shreIcon = data.getImages().get(0);
|
||||
shareIcon = data.getImages().get(0);
|
||||
} else {
|
||||
shreIcon = getString(R.string.share_ghzs_logo);
|
||||
shareIcon = getString(R.string.share_ghzs_logo);
|
||||
}
|
||||
String description = data.getDescription();
|
||||
if (TextUtils.isEmpty(description)) {
|
||||
description = getString(R.string.ask_share_default_summary);
|
||||
}
|
||||
ShareUtils.getInstance(this).showShareWindows(this, view, getString(R.string.share_questions_url, data.getId())
|
||||
, shreIcon
|
||||
, shareIcon
|
||||
, getString(R.string.ask_share_questions_title, data.getTitle(), data.getAnswersCount())
|
||||
, description, ShareUtils.ShareType.askNormal);
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ public class ToolBoxActivity extends BaseActivity implements SwipeRefreshLayout.
|
||||
|
||||
|
||||
private boolean mIsSearch; // 记录页面状态 搜索页面/普通页面
|
||||
private String mSearckKey; // 记录搜索关键字
|
||||
private String mSearchKey; // 记录搜索关键字
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
@ -80,7 +80,7 @@ public class ToolBoxActivity extends BaseActivity implements SwipeRefreshLayout.
|
||||
|
||||
mLayoutManager = new LinearLayoutManager(this);
|
||||
mToolboxRv.setLayoutManager(mLayoutManager);
|
||||
mRvAdapter = new ToolBoxRvAdapter(this, this, ToolBoxActivity.this, mIsSearch, mSearckKey);
|
||||
mRvAdapter = new ToolBoxRvAdapter(this, this, ToolBoxActivity.this, mIsSearch, mSearchKey);
|
||||
mToolboxRv.addItemDecoration(new VerticalItemDecoration(this, 8, false));
|
||||
mToolboxRv.setAdapter(mRvAdapter);
|
||||
|
||||
@ -164,13 +164,13 @@ public class ToolBoxActivity extends BaseActivity implements SwipeRefreshLayout.
|
||||
mLoading.setVisibility(View.VISIBLE);
|
||||
}
|
||||
mIsSearch = isSearch;
|
||||
mSearckKey = searchKey;
|
||||
mSearchKey = searchKey;
|
||||
changeAdapter(false);
|
||||
}
|
||||
|
||||
private void changeAdapter(boolean isRefresh) {
|
||||
if (mIsSearch) {
|
||||
mRvAdapter = new ToolBoxRvAdapter(this, this, this, mIsSearch, mSearckKey);
|
||||
mRvAdapter = new ToolBoxRvAdapter(this, this, this, mIsSearch, mSearchKey);
|
||||
} else {
|
||||
if (mNormalRvAdapter != null && !isRefresh) {
|
||||
mRvAdapter = mNormalRvAdapter;
|
||||
|
||||
@ -50,10 +50,10 @@ public class ToolBoxRvAdapter extends BaseRecyclerAdapter {
|
||||
private List<ToolBoxEntity> mEntityList;
|
||||
private List<ToolBoxEntity> mConcernList;
|
||||
|
||||
private String mSerchKey;
|
||||
private String mSearchKey;
|
||||
private String mToken;
|
||||
|
||||
private boolean mLoadConcernDtatOver;
|
||||
private boolean mLoadConcernDataOver;
|
||||
private boolean mIsSearch;
|
||||
private boolean mIsLoading;
|
||||
private boolean mIsOver;
|
||||
@ -63,7 +63,7 @@ public class ToolBoxRvAdapter extends BaseRecyclerAdapter {
|
||||
boolean isSearch, String key) {
|
||||
super(context);
|
||||
this.mIsSearch = isSearch;
|
||||
this.mSerchKey = key;
|
||||
this.mSearchKey = key;
|
||||
|
||||
mToken = UserManager.getInstance().getToken();
|
||||
mSearchListener = searchListener;
|
||||
@ -79,15 +79,15 @@ public class ToolBoxRvAdapter extends BaseRecyclerAdapter {
|
||||
}
|
||||
mIsLoading = true;
|
||||
|
||||
if (offset > 0 && !isSearch && mLoadConcernDtatOver) {
|
||||
if (offset > 0 && !isSearch && mLoadConcernDataOver) {
|
||||
offset = offset - mConcernList.size();
|
||||
}
|
||||
|
||||
Observable<List<ToolBoxEntity>> api;
|
||||
if (!TextUtils.isEmpty(mToken) && !mLoadConcernDtatOver) {
|
||||
api = RetrofitManager.getInstance(mContext).getApi().getConcernToolKitData(offset, mSerchKey);
|
||||
if (!TextUtils.isEmpty(mToken) && !mLoadConcernDataOver) {
|
||||
api = RetrofitManager.getInstance(mContext).getApi().getConcernToolKitData(offset, mSearchKey);
|
||||
} else {
|
||||
api = RetrofitManager.getInstance(mContext).getApi().getToolKitData(offset, mSerchKey);
|
||||
api = RetrofitManager.getInstance(mContext).getApi().getToolKitData(offset, mSearchKey);
|
||||
}
|
||||
api
|
||||
.subscribeOn(Schedulers.io())
|
||||
@ -96,10 +96,10 @@ public class ToolBoxRvAdapter extends BaseRecyclerAdapter {
|
||||
@Override
|
||||
public void onResponse(List<ToolBoxEntity> response) {
|
||||
super.onResponse(response);
|
||||
if (!mLoadConcernDtatOver && response.size() < 20) {
|
||||
if (!mLoadConcernDataOver && response.size() < 20) {
|
||||
mEntityList.addAll(response);
|
||||
mConcernList = mEntityList;
|
||||
mLoadConcernDtatOver = true;
|
||||
mLoadConcernDataOver = true;
|
||||
mIsLoading = false;
|
||||
loadData(mIsSearch, 0);
|
||||
} else {
|
||||
@ -211,8 +211,8 @@ public class ToolBoxRvAdapter extends BaseRecyclerAdapter {
|
||||
|
||||
private void initSearchViewHolder(final LibaoSearchViewHolder viewHolder) {
|
||||
|
||||
if (mSerchKey != null) {
|
||||
viewHolder.searchEt.setText(mSerchKey);
|
||||
if (mSearchKey != null) {
|
||||
viewHolder.searchEt.setText(mSearchKey);
|
||||
}
|
||||
|
||||
if (mIsSearch) {
|
||||
|
||||
@ -10,10 +10,10 @@ import com.gh.common.util.AskLogUtils;
|
||||
import com.gh.common.util.CheckLoginUtils;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.gamecenter.NormalActivity;
|
||||
import com.gh.gamecenter.QuestionsDetailActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.ask.entity.AnswerEntity;
|
||||
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;
|
||||
@ -71,6 +71,7 @@ public class AskQuestionsHotFragment extends ListFragment<AnswerEntity, AskQuest
|
||||
@Override
|
||||
public void onListClick(View view, int position, Object data) {
|
||||
AnswerEntity answerEntity;
|
||||
Bundle bundle;
|
||||
switch (view.getId()) {
|
||||
case R.id.footerview_item:
|
||||
if (mAdapter.isNetworkError()) {
|
||||
@ -81,12 +82,16 @@ public class AskQuestionsHotFragment extends ListFragment<AnswerEntity, AskQuest
|
||||
String tracers = "(首页精选)";
|
||||
answerEntity = (AnswerEntity) data;
|
||||
Questions questions = answerEntity.getQuestions();
|
||||
startActivity(QuestionsDetailActivity.getIntent(getContext(), questions.getId(), tracers));
|
||||
|
||||
bundle = new Bundle();
|
||||
bundle.putString(EntranceUtils.KEY_QUESTIONS_ID, questions.getId());
|
||||
bundle.putString(EntranceUtils.KEY_ENTRANCE, tracers);
|
||||
NormalActivity.startFragment(getContext(), QuestionsDetailFragment.class, bundle);
|
||||
AskLogUtils.uploadQuestions(getContext(), tracers, questions);
|
||||
break;
|
||||
case R.id.ask_item_constraintlayout:
|
||||
answerEntity = (AnswerEntity) data;
|
||||
Bundle bundle = new Bundle();
|
||||
bundle = new Bundle();
|
||||
bundle.putString(EntranceUtils.KEY_ANSWER_ID, answerEntity.getId());
|
||||
bundle.putString(EntranceUtils.KEY_ENTRANCE, "(首页精选)");
|
||||
NormalActivity.startFragment(getContext(), AnswerDetailFragment.class, bundle);
|
||||
|
||||
@ -28,6 +28,8 @@ class QuestionsDetailEntity() : Parcelable {
|
||||
@SerializedName("community_name")
|
||||
var communityName: String? = null
|
||||
|
||||
var isExistDrafts: Boolean = false
|
||||
|
||||
var me: MeEntity = MeEntity()
|
||||
|
||||
constructor(parcel: Parcel) : this() {
|
||||
@ -39,6 +41,7 @@ class QuestionsDetailEntity() : Parcelable {
|
||||
answersCount = parcel.readInt()
|
||||
isAnswerFold = parcel.readByte() != 0.toByte()
|
||||
communityName = parcel.readString()
|
||||
isExistDrafts = parcel.readByte() != 0.toByte()
|
||||
me = parcel.readParcelable(MeEntity::class.java.classLoader)
|
||||
}
|
||||
|
||||
@ -51,6 +54,7 @@ class QuestionsDetailEntity() : Parcelable {
|
||||
parcel.writeInt(answersCount)
|
||||
parcel.writeByte(if (isAnswerFold) 1 else 0)
|
||||
parcel.writeString(communityName)
|
||||
parcel.writeByte(if (isExistDrafts) 1 else 0)
|
||||
parcel.writeParcelable(me, flags)
|
||||
}
|
||||
|
||||
|
||||
@ -51,12 +51,17 @@ public class AnswerFoldFragment extends ListFragment<AnswerEntity, NormalListVie
|
||||
return R.layout.fragment_questionsdetail_fold;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
setNavigationTitle("折叠回答");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
if (getArguments() != null)
|
||||
mQuestionsId = getArguments().getString(EntranceUtils.KEY_QUESTIONS_ID);
|
||||
super.onCreate(savedInstanceState);
|
||||
// startActivity(WebActivity.getIntentByUrl(getContext(), getString(R.string.answer_fold_tips_url)));
|
||||
mFlodHint.setOnClickListener((v) -> startActivity(NewsDetailActivity.getIntentById(getContext(),
|
||||
"5a50a008d53f8b23008b465a", "(折叠答案)"))); // todo
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package com.gh.gamecenter.ask.questionsdetail;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Spannable;
|
||||
@ -25,7 +26,6 @@ import com.gh.common.util.ImageUtils;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder;
|
||||
import com.gh.gamecenter.ask.entity.AnswerEntity;
|
||||
import com.gh.gamecenter.ask.entity.MeEntity;
|
||||
import com.gh.gamecenter.ask.entity.QuestionsDetailEntity;
|
||||
import com.gh.gamecenter.baselist.ListAdapter;
|
||||
import com.gh.gamecenter.baselist.LoadStatus;
|
||||
@ -204,8 +204,8 @@ public class QuestionsDetailAdapter extends ListAdapter<AnswerEntity> {
|
||||
View view = LayoutInflater.from(mContext).inflate(R.layout.questionsdedit_tag_item, null);
|
||||
TextView tagTv = (TextView) view;
|
||||
tagTv.setText(tag);
|
||||
tagTv.setBackgroundResource(R.drawable.comment_border_bg);
|
||||
tagTv.setTextColor(ContextCompat.getColor(mContext, R.color.theme));
|
||||
tagTv.setBackgroundResource(R.drawable.questions_detail_tag_bg);
|
||||
tagTv.setTextColor(ContextCompat.getColor(mContext, R.color.hint));
|
||||
FlexboxLayout.LayoutParams params = new FlexboxLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
params.setMargins(0, DisplayUtils.dip2px(mContext, 5), DisplayUtils.dip2px(mContext, 15),
|
||||
@ -214,20 +214,6 @@ public class QuestionsDetailAdapter extends ListAdapter<AnswerEntity> {
|
||||
holder.mTagRl.addView(view);
|
||||
}
|
||||
|
||||
if (mQuestionsDetailEntity.getMe().isQuestionFollowed()) {
|
||||
holder.mConcern.setText(R.string.concerned);
|
||||
holder.mConcern.setTextColor(ContextCompat.getColor(mContext, R.color.hint));
|
||||
} else {
|
||||
holder.mConcern.setText(R.string.concern_questions);
|
||||
holder.mConcern.setTextColor(ContextCompat.getColor(mContext, R.color.theme));
|
||||
}
|
||||
|
||||
if (mQuestionsDetailEntity.getMe().isQuestionOwn()) {
|
||||
holder.mConcern.setVisibility(View.GONE);
|
||||
} else {
|
||||
holder.mConcern.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
String description = mQuestionsDetailEntity.getDescription();
|
||||
if (TextUtils.isEmpty(description)) {
|
||||
holder.mDesRl.setVisibility(View.GONE);
|
||||
@ -235,8 +221,14 @@ public class QuestionsDetailAdapter extends ListAdapter<AnswerEntity> {
|
||||
holder.mDesRl.setVisibility(View.VISIBLE);
|
||||
holder.mDes.setText(description);
|
||||
}
|
||||
if (!TextUtils.isEmpty(mQuestionsDetailEntity.getMe().getMyAnswerId())) {
|
||||
setAnswerTv(holder.answerTv, R.string.question_detail_myanswer);
|
||||
} else if (mQuestionsDetailEntity.isExistDrafts()) {
|
||||
setAnswerTv(holder.answerTv, R.string.question_detail_resume_answer);
|
||||
} else {
|
||||
setAnswerTv(holder.answerTv, R.string.question_detail_answer);
|
||||
}
|
||||
|
||||
holder.mCommunityName.setText(mQuestionsDetailEntity.getCommunityName());
|
||||
holder.mTitle.setText(mQuestionsDetailEntity.getTitle());
|
||||
holder.mAnswercount.setText(mContext.getString(R.string.ask_answer_count, mQuestionsDetailEntity.getAnswersCount()));
|
||||
|
||||
@ -287,6 +279,20 @@ public class QuestionsDetailAdapter extends ListAdapter<AnswerEntity> {
|
||||
});
|
||||
}
|
||||
|
||||
private void setAnswerTv(TextView answerTv, @StringRes int answerTvId) {
|
||||
String answerText = mContext.getString(answerTvId);
|
||||
answerTv.setText(answerText);
|
||||
|
||||
Drawable drawable;
|
||||
if (mContext.getString(R.string.question_detail_myanswer).equals(answerText)) {
|
||||
drawable = ContextCompat.getDrawable(mContext, R.drawable.questionsdetail_myanswer_icon);
|
||||
} else {
|
||||
drawable = ContextCompat.getDrawable(mContext, R.drawable.questionsdetail_answer_icon);
|
||||
}
|
||||
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
|
||||
answerTv.setCompoundDrawables(drawable, null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
int index = 0;
|
||||
@ -307,15 +313,4 @@ public class QuestionsDetailAdapter extends ListAdapter<AnswerEntity> {
|
||||
boolean isOver() {
|
||||
return mIsOver;
|
||||
}
|
||||
|
||||
void onConcern(boolean isSuccess) {
|
||||
MeEntity me = mQuestionsDetailEntity.getMe();
|
||||
me.setQuestionFollowed(isSuccess);
|
||||
mQuestionsDetailEntity.setMe(me);
|
||||
notifyItemChanged(0);
|
||||
}
|
||||
|
||||
boolean isConcernQuestions() {
|
||||
return mQuestionsDetailEntity.getMe().isQuestionFollowed();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,31 +1,40 @@
|
||||
package com.gh.gamecenter.ask.questionsdetail;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.arch.lifecycle.Lifecycle;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.widget.DefaultItemAnimator;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.common.util.CheckLoginUtils;
|
||||
import com.gh.common.util.ConcernUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.util.ShareUtils;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.NormalActivity;
|
||||
import com.gh.gamecenter.QuestionsDetailActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.SuggestionActivity;
|
||||
import com.gh.gamecenter.ViewImageActivity;
|
||||
import com.gh.gamecenter.ask.AnswerDetailFragment;
|
||||
import com.gh.gamecenter.ask.entity.AnswerEntity;
|
||||
import com.gh.gamecenter.ask.entity.QuestionsDetailEntity;
|
||||
import com.gh.gamecenter.ask.questionsdetail.invite.QuestionsInviteWrapperFragment;
|
||||
import com.gh.gamecenter.baselist.ListAdapter;
|
||||
import com.gh.gamecenter.baselist.ListFragment;
|
||||
import com.gh.gamecenter.baselist.LoadStatus;
|
||||
@ -42,7 +51,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.HttpException;
|
||||
import rx.Observable;
|
||||
@ -55,18 +63,10 @@ import rx.schedulers.Schedulers;
|
||||
|
||||
public class QuestionsDetailFragment extends ListFragment<AnswerEntity, NormalListViewModel> {
|
||||
|
||||
@BindView(R.id.questionsdetail_answer)
|
||||
RelativeLayout mAnswer;
|
||||
@BindView(R.id.questionsdetail_invite)
|
||||
RelativeLayout mInvite;
|
||||
@BindView(R.id.questionsdetail_answer_tv)
|
||||
TextView mAnswerTv;
|
||||
@BindView(R.id.reuse_tv_none_data)
|
||||
TextView mNoDataTv;
|
||||
@BindView(R.id.questionsdetail_constraintlayout_bottom)
|
||||
View mBottomCl;
|
||||
@BindView(R.id.questionsdetail_line)
|
||||
View mLine;
|
||||
|
||||
private MenuItem mQuestionConcern;
|
||||
|
||||
private QuestionsDetailAdapter mAdapter;
|
||||
|
||||
@ -97,8 +97,24 @@ public class QuestionsDetailFragment extends ListFragment<AnswerEntity, NormalLi
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_questionsdetail;
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == QuestionsDetailActivity.QUESTIONS_DETAIL_ANSWER_REQUEST) {
|
||||
if (resultCode == AnswerEditFragment.SAVE_DRAFTS) {
|
||||
postDraftsSuccess();
|
||||
} else if (resultCode == Activity.RESULT_OK) {
|
||||
if (data != null)
|
||||
postAnswerSuccess(data.getStringExtra(EntranceUtils.KEY_ANSWER_ID));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
setNavigationTitle("问题详情");
|
||||
initMenu(R.menu.menu_questions_detail);
|
||||
mQuestionConcern = getItemMenu(R.id.menu_question_concern);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -140,31 +156,6 @@ public class QuestionsDetailFragment extends ListFragment<AnswerEntity, NormalLi
|
||||
mAdapter.loadChange(LoadStatus.LIST_OVER);
|
||||
}
|
||||
|
||||
@OnClick({R.id.questionsdetail_answer, R.id.questionsdetail_invite})
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.questionsdetail_answer:
|
||||
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
|
||||
CheckLoginUtils.checkLogin(getContext(), () -> {
|
||||
if (mQuestionsDetailEntity != null && !TextUtils.isEmpty(mQuestionsDetailEntity.getMe().getMyAnswerId())) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(EntranceUtils.KEY_ANSWER_ID, mQuestionsDetailEntity.getMe().getMyAnswerId());
|
||||
NormalActivity.startFragmentForResult(getContext(), AnswerDetailFragment.class, bundle
|
||||
, QuestionsDetailActivity.QUESTIONS_DETAIL_ANSWER_REQUEST);
|
||||
} else {
|
||||
((QuestionsDetailActivity) getActivity()).show(QuestionsDetailActivity.QUESTIONS_DETAIL_ANSWER);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
break;
|
||||
case R.id.questionsdetail_invite:
|
||||
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
|
||||
((QuestionsDetailActivity) getActivity()).show(QuestionsDetailActivity.QUESTIONS_DETAIL_INVITE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<List<AnswerEntity>> provideDataObservable(int offset) {
|
||||
return RetrofitManager.getInstance(getContext()).getApi().getQuestionsAnswer(mQuestionsId, false, offset);
|
||||
@ -195,39 +186,6 @@ public class QuestionsDetailFragment extends ListFragment<AnswerEntity, NormalLi
|
||||
NormalActivity.startFragmentForResult(getContext(), AnswerDetailFragment.class, bundle
|
||||
, QuestionsDetailActivity.QUESTIONS_DETAIL_ANSWER_REQUEST);
|
||||
break;
|
||||
case R.id.questionsdetail_item_concern:
|
||||
CheckLoginUtils.checkLogin(getContext(), () -> {
|
||||
if (!mAdapter.isConcernQuestions()) {
|
||||
ConcernUtils.INSTANCE.postConcernQuestions(getContext(), mQuestionsId
|
||||
, new ConcernUtils.onConcernListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
mAdapter.onConcern(true);
|
||||
toast("关注成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
|
||||
}
|
||||
});
|
||||
} else {
|
||||
ConcernUtils.INSTANCE.deleteConcernQuestions(getContext(), mQuestionsId
|
||||
, new ConcernUtils.onConcernListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
mAdapter.onConcern(false);
|
||||
toast("取消关注");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
break;
|
||||
case R.id.questionsdetail_item_pic1:
|
||||
imgPosition = 0;
|
||||
case R.id.questionsdetail_item_pic2:
|
||||
@ -240,10 +198,131 @@ public class QuestionsDetailFragment extends ListFragment<AnswerEntity, NormalLi
|
||||
startActivity(intent);
|
||||
}
|
||||
break;
|
||||
case R.id.questionsdetail_answer:
|
||||
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
|
||||
CheckLoginUtils.checkLogin(getContext(), () -> {
|
||||
if (mQuestionsDetailEntity != null && !TextUtils.isEmpty(mQuestionsDetailEntity.getMe().getMyAnswerId())) {
|
||||
Bundle answerDetailBundle = new Bundle();
|
||||
answerDetailBundle.putString(EntranceUtils.KEY_ANSWER_ID, mQuestionsDetailEntity.getMe().getMyAnswerId());
|
||||
NormalActivity.startFragmentForResult(getContext(), AnswerDetailFragment.class, answerDetailBundle
|
||||
, QuestionsDetailActivity.QUESTIONS_DETAIL_ANSWER_REQUEST);
|
||||
} else {
|
||||
Bundle answerEditBundle = new Bundle();
|
||||
answerEditBundle.putString(EntranceUtils.KEY_QUESTIONS_ID, mQuestionsId);
|
||||
answerEditBundle.putString(EntranceUtils.KEY_QUESTIONS_TITLE, getQuestionsTitle());
|
||||
NormalActivity.startFragmentForResult(getActivity(), AnswerEditFragment.class, answerEditBundle
|
||||
, QuestionsDetailActivity.QUESTIONS_DETAIL_ANSWER_REQUEST);
|
||||
}
|
||||
});
|
||||
break;
|
||||
case R.id.questionsdetail_invite:
|
||||
Bundle bundleInvite = new Bundle();
|
||||
bundleInvite.putParcelable(QuestionsDetailEntity.TAG, mQuestionsDetailEntity);
|
||||
NormalActivity.startFragment(getContext(), QuestionsInviteWrapperFragment.class, bundleInvite);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onMenuItemClick(MenuItem menuItem) {
|
||||
switch (menuItem.getItemId()) {
|
||||
case R.id.menu_more:
|
||||
showMoreItemDialog();
|
||||
break;
|
||||
case R.id.menu_question_concern:
|
||||
CheckLoginUtils.checkLogin(getContext(), () -> {
|
||||
if (!mQuestionsDetailEntity.getMe().isQuestionFollowed()) {
|
||||
ConcernUtils.INSTANCE.postConcernQuestions(getContext(), mQuestionsId
|
||||
, new ConcernUtils.onConcernListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
mQuestionsDetailEntity.getMe().setQuestionFollowed(true);
|
||||
mQuestionConcern.setIcon(R.drawable.menu_ic_question_concern_select);
|
||||
toast("已关注 ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
|
||||
}
|
||||
});
|
||||
} else {
|
||||
ConcernUtils.INSTANCE.deleteConcernQuestions(getContext(), mQuestionsId
|
||||
, new ConcernUtils.onConcernListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
mQuestionsDetailEntity.getMe().setQuestionFollowed(false);
|
||||
mQuestionConcern.setIcon(R.drawable.menu_ic_question_concern_unselect);
|
||||
toast("取消关注");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void showMoreItemDialog() {
|
||||
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED) || mQuestionsDetailEntity != null) {
|
||||
View view = LayoutInflater.from(getContext()).inflate(R.layout.menu_question_detail_more_item, null);
|
||||
Dialog dialog = new Dialog(getActivity());
|
||||
dialog.setContentView(view);
|
||||
Window window = dialog.getWindow();
|
||||
if (window != null) {
|
||||
window.setGravity(Gravity.RIGHT | Gravity.TOP);
|
||||
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);
|
||||
window.setAttributes(lp);
|
||||
}
|
||||
dialog.show();
|
||||
ImageView icon = view.findViewById(R.id.more_item_icon1);
|
||||
TextView title = view.findViewById(R.id.more_item_title1);
|
||||
if (mQuestionsDetailEntity.getMe().isQuestionOwn()) {
|
||||
icon.setImageResource(R.drawable.menu_more_edit);
|
||||
title.setText("编辑");
|
||||
}
|
||||
View item1 = view.findViewById(R.id.more_item1);
|
||||
View item2 = view.findViewById(R.id.more_item2);
|
||||
item1.setOnClickListener(v -> {
|
||||
dialog.dismiss();
|
||||
if ("编辑".equals(title.getText().toString())) {
|
||||
// 跳转编辑问题页面
|
||||
} else {
|
||||
// 跳转意见反馈
|
||||
SuggestionActivity.startSuggestionActivity(getContext(), 1, "report", "问题举报:");
|
||||
}
|
||||
});
|
||||
item2.setOnClickListener(v -> {
|
||||
dialog.dismiss();
|
||||
String shareIcon;
|
||||
if (mQuestionsDetailEntity.getImages().size() > 0) {
|
||||
shareIcon = mQuestionsDetailEntity.getImages().get(0);
|
||||
} else {
|
||||
shareIcon = getString(R.string.share_ghzs_logo);
|
||||
}
|
||||
String description = mQuestionsDetailEntity.getDescription();
|
||||
if (TextUtils.isEmpty(description)) {
|
||||
description = getString(R.string.ask_share_default_summary);
|
||||
}
|
||||
ShareUtils.getInstance(getActivity()).showShareWindows(getActivity(), view
|
||||
, getString(R.string.share_questions_url, mQuestionsDetailEntity.getId())
|
||||
, shareIcon
|
||||
, getString(R.string.ask_share_questions_title, mQuestionsDetailEntity.getTitle(), mQuestionsDetailEntity.getAnswersCount())
|
||||
, description, ShareUtils.ShareType.askNormal);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public String getQuestionsTitle() {
|
||||
return mAdapter.getQuestionsTitle();
|
||||
}
|
||||
@ -253,11 +332,12 @@ public class QuestionsDetailFragment extends ListFragment<AnswerEntity, NormalLi
|
||||
mQuestionsDetailEntity.getMe().setMyAnswerId(answerId);
|
||||
mBaseHandler.postDelayed(this::getQuestionsDetail, 500);
|
||||
}
|
||||
setAnswerTv(R.string.question_detail_myanswer);
|
||||
mAdapter.notifyItemChanged(0);
|
||||
}
|
||||
|
||||
public void postDraftsSuccess() {
|
||||
setAnswerTv(R.string.question_detail_resume_answer);
|
||||
mQuestionsDetailEntity.setExistDrafts(true);
|
||||
mAdapter.notifyItemChanged(0);
|
||||
}
|
||||
|
||||
|
||||
@ -274,13 +354,16 @@ public class QuestionsDetailFragment extends ListFragment<AnswerEntity, NormalLi
|
||||
@Override
|
||||
public void onResponse(QuestionsDetailEntity response) {
|
||||
super.onResponse(response);
|
||||
if (!TextUtils.isEmpty(response.getMe().getMyAnswerId())) {
|
||||
setAnswerTv(R.string.question_detail_myanswer);
|
||||
} else {
|
||||
setAnswerTv(R.string.question_detail_answer);
|
||||
if (TextUtils.isEmpty(response.getMe().getMyAnswerId())) {
|
||||
getUserAnswerDrafts();
|
||||
}
|
||||
if (response.getMe().isQuestionFollowed()) {
|
||||
mQuestionConcern.setIcon(R.drawable.menu_ic_question_concern_select);
|
||||
} else {
|
||||
mQuestionConcern.setIcon(R.drawable.menu_ic_question_concern_unselect);
|
||||
}
|
||||
response.setId(mQuestionsId);
|
||||
response.getTags().set(0, response.getCommunityName()); // 原来的[社区名字]移到问题标题的顶部,标签的左侧
|
||||
mQuestionsDetailEntity = response;
|
||||
mAdapter.setQuestionsEntity(response);
|
||||
mListViewModel.load(LoadType.REFRESH);
|
||||
@ -296,8 +379,6 @@ public class QuestionsDetailFragment extends ListFragment<AnswerEntity, NormalLi
|
||||
mReuseNoData.setVisibility(View.VISIBLE);
|
||||
mListLoading.setVisibility(View.GONE);
|
||||
mListRv.setVisibility(View.GONE);
|
||||
mBottomCl.setVisibility(View.GONE);
|
||||
mLine.setVisibility(View.GONE);
|
||||
mListRefresh.setRefreshing(false);
|
||||
mListRefresh.setEnabled(false);
|
||||
} else {
|
||||
@ -323,7 +404,8 @@ public class QuestionsDetailFragment extends ListFragment<AnswerEntity, NormalLi
|
||||
JSONObject object = new JSONObject(response.string());
|
||||
String drafts = object.getString("content");
|
||||
if (!TextUtils.isEmpty(drafts)) {
|
||||
setAnswerTv(R.string.question_detail_resume_answer);
|
||||
mQuestionsDetailEntity.setExistDrafts(true);
|
||||
mAdapter.notifyItemChanged(0);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -337,18 +419,4 @@ public class QuestionsDetailFragment extends ListFragment<AnswerEntity, NormalLi
|
||||
});
|
||||
}
|
||||
|
||||
private void setAnswerTv(@StringRes int answerTvId) {
|
||||
if (getContext() == null) return;
|
||||
String answerTv = getString(answerTvId);
|
||||
mAnswerTv.setText(answerTv);
|
||||
|
||||
Drawable drawable;
|
||||
if (getString(R.string.question_detail_myanswer).equals(answerTv)) {
|
||||
drawable = ContextCompat.getDrawable(getContext(), R.drawable.questionsdetail_myanswer_icon);
|
||||
} else {
|
||||
drawable = ContextCompat.getDrawable(getContext(), R.drawable.questionsdetail_answer_icon);
|
||||
}
|
||||
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
|
||||
mAnswerTv.setCompoundDrawables(drawable, null, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,20 +34,23 @@ public class QuestionsDetailItemViewHolder extends BaseRecyclerViewHolder {
|
||||
public SimpleDraweeView mPic3;
|
||||
@BindView(R.id.questionsdetail_item_answercount)
|
||||
public TextView mAnswercount;
|
||||
@BindView(R.id.questionsdetail_item_concern)
|
||||
public TextView mConcern;
|
||||
@BindView(R.id.questionsdetail_item_picll)
|
||||
public LinearLayout mImgLl;
|
||||
@BindView(R.id.questionsdetail_item_des_all)
|
||||
public View mDesAll;
|
||||
@BindView(R.id.questionsdetail_item_community_name)
|
||||
public TextView mCommunityName;
|
||||
@BindView(R.id.questionsdetail_answer_tv)
|
||||
TextView answerTv;
|
||||
@BindView(R.id.questionsdetail_answer)
|
||||
View answerBtn;
|
||||
@BindView(R.id.questionsdetail_invite)
|
||||
View inviteBtn;
|
||||
|
||||
public QuestionsDetailItemViewHolder(View itemView, Object data, OnListClickListener listClickListener) {
|
||||
super(itemView, data, listClickListener);
|
||||
mConcern.setOnClickListener(this);
|
||||
mPic1.setOnClickListener(this);
|
||||
mPic2.setOnClickListener(this);
|
||||
mPic3.setOnClickListener(this);
|
||||
answerBtn.setOnClickListener(this);
|
||||
inviteBtn.setOnClickListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.gh.gamecenter.ask.questionsdetail;
|
||||
package com.gh.gamecenter.ask.questionsdetail.invite;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
@ -13,6 +13,7 @@ import com.gh.gamecenter.ask.entity.InviteEntity;
|
||||
import com.gh.gamecenter.ask.entity.MeEntity;
|
||||
import com.gh.gamecenter.baselist.ListAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -28,18 +29,17 @@ public class QuestionsInviteAdapter extends ListAdapter<InviteEntity> {
|
||||
mListClickListener = listClickListener;
|
||||
}
|
||||
|
||||
protected void provideListData(List<InviteEntity> listData) {
|
||||
protected void setListData(List<InviteEntity> listData) {
|
||||
if (listData != null && listData.size() != 0) {
|
||||
mEntityList.addAll(listData);
|
||||
notifyItemRangeInserted(mEntityList.size() - listData.size() + TOP_ITEM_COUNT, listData.size());
|
||||
mEntityList = new ArrayList<>(listData);
|
||||
notifyDataSetChanged();
|
||||
// notifyItemRangeInserted(mEntityList.size() - listData.size() + TOP_ITEM_COUNT, listData.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (position == 0) {
|
||||
return ItemViewType.ITEM_TOP;
|
||||
} else if (position == getItemCount() - 1) {
|
||||
if (position == getItemCount() - 1) {
|
||||
return ItemViewType.ITEM_FOOTER;
|
||||
} else {
|
||||
return ItemViewType.ITEM_BODY;
|
||||
@ -50,9 +50,6 @@ public class QuestionsInviteAdapter extends ListAdapter<InviteEntity> {
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view;
|
||||
switch (viewType) {
|
||||
case ItemViewType.ITEM_TOP:
|
||||
view = mLayoutInflater.inflate(R.layout.questionsinvite_top_item, parent, false);
|
||||
return new QuestionsInviteTopItemViewHolder(view, null, mListClickListener);
|
||||
case ItemViewType.ITEM_FOOTER:
|
||||
view = mLayoutInflater.inflate(R.layout.refresh_footerview, parent, false);
|
||||
return new FooterViewHolder(view, null, mListClickListener);
|
||||
@ -67,22 +64,20 @@ public class QuestionsInviteAdapter extends ListAdapter<InviteEntity> {
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
switch (getItemViewType(position)) {
|
||||
case ItemViewType.ITEM_TOP:
|
||||
break;
|
||||
case ItemViewType.ITEM_FOOTER:
|
||||
FooterViewHolder footerViewHolder = (FooterViewHolder) holder;
|
||||
footerViewHolder.initItemPadding();
|
||||
footerViewHolder.initFooterViewHolder(mIsNetworkError, mIsOver, R.string.ask_loadover_hint);
|
||||
break;
|
||||
case ItemViewType.ITEM_BODY:
|
||||
((QuestionsInviteViewHolder) holder).initQuestionsInviteViewHolder(mContext, mEntityList.get(position - 1));
|
||||
((QuestionsInviteViewHolder) holder).initQuestionsInviteViewHolder(mContext, mEntityList.get(position));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mEntityList.size() != 0 ? mEntityList.size() + TOP_ITEM_COUNT + FOOTER_ITEM_COUNT : 0;
|
||||
return mEntityList != null && mEntityList.size() != 0 ? mEntityList.size() + FOOTER_ITEM_COUNT : 0;
|
||||
}
|
||||
|
||||
public void inviteSuccess(String id) {
|
||||
@ -1,21 +1,24 @@
|
||||
package com.gh.gamecenter.ask.questionsdetail;
|
||||
package com.gh.gamecenter.ask.questionsdetail.invite;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
|
||||
import com.gh.common.util.AskErrorResponseUtils;
|
||||
import com.gh.common.util.CheckLoginUtils;
|
||||
import com.gh.common.util.ShareUtils;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.ask.entity.InviteEntity;
|
||||
import com.gh.gamecenter.ask.entity.MeEntity;
|
||||
import com.gh.gamecenter.ask.entity.QuestionsDetailEntity;
|
||||
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.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
|
||||
@ -42,6 +45,8 @@ public class QuestionsInviteFragment extends ListFragment<InviteEntity, NormalLi
|
||||
|
||||
private QuestionsInviteAdapter mAdapter;
|
||||
|
||||
private String mSearchKey;
|
||||
|
||||
public static QuestionsInviteFragment getInstance(QuestionsDetailEntity questionsDetailEntity) {
|
||||
QuestionsInviteFragment fragment = new QuestionsInviteFragment();
|
||||
Bundle args = new Bundle();
|
||||
@ -50,10 +55,18 @@ public class QuestionsInviteFragment extends ListFragment<InviteEntity, NormalLi
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RecyclerView.ItemDecoration getItemDecoration() {
|
||||
return new VerticalItemDecoration(getContext(), 8, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
if (getArguments() != null)
|
||||
mQuestionsDetailEntity = getArguments().getParcelable(QuestionsDetailEntity.TAG);
|
||||
if (getArguments() != null) {
|
||||
Bundle arguments = getArguments();
|
||||
mQuestionsDetailEntity = arguments.getParcelable(QuestionsDetailEntity.TAG);
|
||||
mSearchKey = arguments.getString(EntranceUtils.KEY_INVITE_SEARCH_KEY, null);
|
||||
}
|
||||
super.onCreate(savedInstanceState);
|
||||
mListRefresh.setEnabled(false);
|
||||
}
|
||||
@ -65,7 +78,8 @@ public class QuestionsInviteFragment extends ListFragment<InviteEntity, NormalLi
|
||||
|
||||
@Override
|
||||
public Observable<List<InviteEntity>> provideDataObservable(int offset) {
|
||||
return RetrofitManager.getInstance(getContext()).getApi().getInviteExperts(mQuestionsDetailEntity.getId(), offset);
|
||||
return RetrofitManager.getInstance(getContext()).getApi().getInviteExperts(mQuestionsDetailEntity.getId()
|
||||
, TextUtils.isEmpty(mSearchKey) ? offset : offset + 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -85,31 +99,14 @@ public class QuestionsInviteFragment extends ListFragment<InviteEntity, NormalLi
|
||||
postInvite(inviteEntity.getId());
|
||||
});
|
||||
break;
|
||||
case R.id.questionsinvite_top_item_invite:
|
||||
// 第三方邀请(QQ/微信/微博)
|
||||
String shreIcon;
|
||||
if (mQuestionsDetailEntity.getImages().size() > 0) {
|
||||
shreIcon = mQuestionsDetailEntity.getImages().get(0);
|
||||
} else {
|
||||
shreIcon = getString(R.string.share_ghzs_logo);
|
||||
}
|
||||
String userName;
|
||||
if (UserManager.getInstance().getUserInfoEntity() != null) {
|
||||
userName = UserManager.getInstance().getUserInfoEntity().getName();
|
||||
} else {
|
||||
userName = "我";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String description = mQuestionsDetailEntity.getDescription();
|
||||
if (TextUtils.isEmpty(description)) {
|
||||
description = getString(R.string.ask_share_default_summary);
|
||||
}
|
||||
ShareUtils.getInstance(getContext()).showShareWindows(getActivity(), view
|
||||
, getString(R.string.share_invite_url, mQuestionsDetailEntity.getId(), UserManager.getInstance().getUserId())
|
||||
, shreIcon, getString(R.string.ask_share_invite_title, userName, mQuestionsDetailEntity.getTitle())
|
||||
, description, ShareUtils.ShareType.askInvite);
|
||||
|
||||
break;
|
||||
public void search() {
|
||||
Fragment parentFragment = getParentFragment();
|
||||
if (parentFragment instanceof QuestionsInviteWrapperFragment) {
|
||||
mSearchKey = ((QuestionsInviteWrapperFragment) parentFragment).getSearchKey();
|
||||
mListViewModel.load(LoadType.REFRESH);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.gh.gamecenter.ask.questionsdetail;
|
||||
package com.gh.gamecenter.ask.questionsdetail.invite;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.gh.gamecenter.ask.questionsdetail;
|
||||
package com.gh.gamecenter.ask.questionsdetail.invite;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
@ -0,0 +1,176 @@
|
||||
package com.gh.gamecenter.ask.questionsdetail.invite;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.AppBarLayout;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.text.TextUtils;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.util.ShareUtils;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.ask.entity.QuestionsDetailEntity;
|
||||
import com.gh.gamecenter.manager.UserManager;
|
||||
import com.gh.gamecenter.normal.NormalFragment;
|
||||
import com.lightgame.utils.Util_System_Keyboard;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
|
||||
/**
|
||||
* Created by khy on 22/03/18.
|
||||
*/
|
||||
|
||||
public class QuestionsInviteWrapperFragment extends NormalFragment {
|
||||
|
||||
@BindView(R.id.invite_appbar)
|
||||
AppBarLayout mAppBar;
|
||||
@BindView(R.id.invite_et_search)
|
||||
EditText mInviteEtSearch;
|
||||
@BindView(R.id.invite_tv_back)
|
||||
TextView mInviteTvBack;
|
||||
@BindView(R.id.invite_tv_search)
|
||||
TextView mInviteTvSearch;
|
||||
|
||||
private final static String INVITE_SEARCH_TAG = "INVITE_SEARCH_TAG";
|
||||
private final static String INVITE_NORMAL_TAG = "INVITE_NORMAL_TAG";
|
||||
|
||||
private QuestionsDetailEntity mQuestionsDetailEntity;
|
||||
|
||||
private boolean mIsSearch;
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_invite;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMenuItemClick(MenuItem menuItem) {
|
||||
if (menuItem.getItemId() == R.id.menu_answer_post) {
|
||||
// 第三方邀请(QQ/微信/微博)
|
||||
String shareIcon;
|
||||
if (mQuestionsDetailEntity.getImages().size() > 0) {
|
||||
shareIcon = mQuestionsDetailEntity.getImages().get(0);
|
||||
} else {
|
||||
shareIcon = getString(R.string.share_ghzs_logo);
|
||||
}
|
||||
String userName;
|
||||
if (UserManager.getInstance().getUserInfoEntity() != null) {
|
||||
userName = UserManager.getInstance().getUserInfoEntity().getName();
|
||||
} else {
|
||||
userName = "我";
|
||||
}
|
||||
|
||||
String description = mQuestionsDetailEntity.getDescription();
|
||||
if (TextUtils.isEmpty(description)) {
|
||||
description = getString(R.string.ask_share_default_summary);
|
||||
}
|
||||
ShareUtils.getInstance(getContext()).showShareWindows(getActivity(), new View(getContext())
|
||||
, getString(R.string.share_invite_url, mQuestionsDetailEntity.getId(), UserManager.getInstance().getUserId())
|
||||
, shareIcon, getString(R.string.ask_share_invite_title, userName, mQuestionsDetailEntity.getTitle())
|
||||
, description, ShareUtils.ShareType.askInvite);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
setNavigationTitle("达人推荐");
|
||||
initMenu(R.menu.menu_question_invite);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null)
|
||||
mQuestionsDetailEntity = getArguments().getParcelable(QuestionsDetailEntity.TAG);
|
||||
changeFragment();
|
||||
|
||||
mAppBar.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> {
|
||||
int totalScrollRange = appBarLayout.getTotalScrollRange();
|
||||
if (totalScrollRange == -verticalOffset) {
|
||||
Util_System_Keyboard.hideSoftKeyboard(getActivity());
|
||||
}
|
||||
});
|
||||
|
||||
mInviteEtSearch.setOnEditorActionListener((v, actionId, event) -> {
|
||||
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
||||
mInviteTvSearch.performClick();
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
private void changeFragment() {
|
||||
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
|
||||
hideFragments(transaction);
|
||||
if (mIsSearch) {
|
||||
alterFragment(transaction, QuestionsInviteFragment.class, INVITE_SEARCH_TAG);
|
||||
} else {
|
||||
alterFragment(transaction, QuestionsInviteFragment.class, INVITE_NORMAL_TAG);
|
||||
}
|
||||
|
||||
transaction.commitAllowingStateLoss();
|
||||
}
|
||||
|
||||
private <T extends Fragment> T alterFragment(FragmentTransaction transaction, Class<T> cls, String tag) {
|
||||
T fragmentByTag = (T) getChildFragmentManager().findFragmentByTag(tag);
|
||||
try {
|
||||
if (fragmentByTag != null) {
|
||||
transaction.show(fragmentByTag);
|
||||
if (fragmentByTag instanceof QuestionsInviteFragment && INVITE_SEARCH_TAG.equals(tag)) {
|
||||
((QuestionsInviteFragment) fragmentByTag).search();
|
||||
}
|
||||
} else {
|
||||
Bundle args = new Bundle();
|
||||
if (INVITE_SEARCH_TAG.equals(tag))
|
||||
args.putString(EntranceUtils.KEY_INVITE_SEARCH_KEY, getSearchKey());
|
||||
args.putParcelable(QuestionsDetailEntity.TAG, mQuestionsDetailEntity);
|
||||
fragmentByTag = cls.newInstance();
|
||||
fragmentByTag.setArguments(args);
|
||||
transaction.add(R.id.layout_fragment_content, fragmentByTag, tag);
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return fragmentByTag;
|
||||
}
|
||||
|
||||
@OnClick({R.id.invite_tv_back, R.id.invite_tv_search})
|
||||
public void onViewClicked(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.invite_tv_back:
|
||||
mIsSearch = false;
|
||||
break;
|
||||
case R.id.invite_tv_search:
|
||||
String key = mInviteEtSearch.getText().toString();
|
||||
if (TextUtils.isEmpty(key)) {
|
||||
toast(R.string.search_hint);
|
||||
return;
|
||||
} else if (!mIsSearch) {
|
||||
mIsSearch = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (mIsSearch) {
|
||||
mInviteTvBack.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mInviteTvBack.setVisibility(View.GONE);
|
||||
}
|
||||
Util_System_Keyboard.hideSoftKeyboard(getActivity());
|
||||
changeFragment();
|
||||
}
|
||||
|
||||
public String getSearchKey() {
|
||||
return mInviteEtSearch.getText().toString();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user