113 lines
3.8 KiB
Java
113 lines
3.8 KiB
Java
package com.gh.gamecenter.ask;
|
|
|
|
import android.os.Bundle;
|
|
import android.support.annotation.NonNull;
|
|
import android.support.annotation.Nullable;
|
|
import android.support.v4.app.Fragment;
|
|
import android.view.View;
|
|
|
|
import com.gh.common.util.AskLogUtils;
|
|
import com.gh.common.util.CheckLoginUtils;
|
|
import com.gh.common.util.UrlFilterUtils;
|
|
import com.gh.gamecenter.QuestionEditActivity;
|
|
import com.gh.gamecenter.QuestionsDetailActivity;
|
|
import com.gh.gamecenter.R;
|
|
import com.gh.gamecenter.ask.entity.Questions;
|
|
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 butterknife.BindView;
|
|
import butterknife.OnClick;
|
|
import rx.Observable;
|
|
|
|
|
|
/**
|
|
* Created by khy on 5/12/17.
|
|
*/
|
|
|
|
public class AskQuestionsNewBodyFragment extends ListFragment<Questions, NormalListViewModel> {
|
|
|
|
private AskQuestionsNewBodyAdapter mAdapter;
|
|
private CheckLoginUtils.OnLoginListener mOnLoginListener;
|
|
|
|
private String mType;
|
|
|
|
private String mCommunityId;
|
|
|
|
@BindView(R.id.reuse_nodata_skip_tv_btn)
|
|
View mSkipHint;
|
|
|
|
@Override
|
|
protected int getLayoutId() {
|
|
return R.layout.fragment_list_nodate_skip;
|
|
}
|
|
|
|
@Override
|
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
mCommunityId = UserManager.getInstance().getCommunityId(getContext());
|
|
mType = getArguments().getString(mCommunityId);
|
|
super.onCreate(savedInstanceState);
|
|
mOnLoginListener = () -> {
|
|
startActivity(QuestionEditActivity.getIntent(getContext()));
|
|
};
|
|
}
|
|
|
|
@Override
|
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
super.onViewCreated(view, savedInstanceState);
|
|
if (!UserManager.getInstance().getCommunityId(getContext()).equals(mCommunityId)) {
|
|
mCommunityId = UserManager.getInstance().getCommunityId(getContext());
|
|
mType = getArguments().getString(mCommunityId);
|
|
onRefresh();
|
|
}
|
|
}
|
|
|
|
@OnClick(R.id.reuse_nodata_skip_tv_btn)
|
|
public void onViewClick(View v) {
|
|
if (v.getId() == R.id.reuse_nodata_skip_tv_btn) {
|
|
CheckLoginUtils.checkLogin(getContext(), mOnLoginListener);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected ListAdapter provideListAdapter() {
|
|
return mAdapter == null ? mAdapter = new AskQuestionsNewBodyAdapter(getContext(), this) : mAdapter;
|
|
}
|
|
|
|
@Override
|
|
public Observable<List<Questions>> provideDataObservable(int page) {
|
|
return RetrofitManager.getInstance(getContext()).getApi().getAskQuestions(mCommunityId, UrlFilterUtils.getFilterQuery("tag_group", mType), page);
|
|
}
|
|
|
|
@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.ask_questions_new_item:
|
|
String tracers = "(首页问题-" + mType + ")";
|
|
Questions questions = (Questions) data;
|
|
startActivity(QuestionsDetailActivity.getIntent(getContext(), questions.getId(), tracers));
|
|
AskLogUtils.uploadQuestions(getContext(), tracers, questions);
|
|
break;
|
|
}
|
|
}
|
|
|
|
public static Fragment newInstance(String s) {
|
|
AskQuestionsNewBodyFragment questionsBodyFragment = new AskQuestionsNewBodyFragment();
|
|
Bundle args = new Bundle();
|
|
args.putString(UserManager.getInstance().getCommunityId(questionsBodyFragment.getContext()), s);
|
|
questionsBodyFragment.setArguments(args);
|
|
return questionsBodyFragment;
|
|
}
|
|
}
|