最新礼包合并
This commit is contained in:
@ -18,7 +18,7 @@ import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
import com.gh.gamecenter.libao.Libao1Fragment2;
|
||||
import com.gh.gamecenter.libao.Libao1Fragment;
|
||||
import com.gh.gamecenter.libao.Libao2Fragment;
|
||||
import com.gh.gamecenter.libao.Libao3Fragment;
|
||||
import com.lightgame.view.NoScrollableViewPager;
|
||||
@ -80,7 +80,7 @@ public class LibaoActivity extends BaseActivity implements View.OnClickListener,
|
||||
mZuixinTv.setSelected(true);
|
||||
|
||||
List<Fragment> list = new ArrayList<>();
|
||||
list.add(new Libao1Fragment2());
|
||||
list.add(new Libao1Fragment());
|
||||
list.add(new Libao2Fragment());
|
||||
list.add(new Libao3Fragment());
|
||||
mLibaoVp.setAdapter(new FragmentAdapter(getSupportFragmentManager(), list));
|
||||
|
||||
@ -1,314 +1,160 @@
|
||||
package com.gh.gamecenter.libao;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.Context;
|
||||
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.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.fragment.BaseFragment;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.view.SwipeLayout;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.LibaoActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/12/12.
|
||||
* Created by khy on 5/09/17.
|
||||
*/
|
||||
public class Libao1Fragment extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener,
|
||||
OnSearchCallBackListener {
|
||||
|
||||
@BindView(R.id.libao1_srl_refresh)
|
||||
public class Libao1Fragment extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener {
|
||||
|
||||
@BindView(R.id.libao_appbar)
|
||||
AppBarLayout mAppBar;
|
||||
@BindView(R.id.libao_refresh)
|
||||
SwipeRefreshLayout mRefreshLayout;
|
||||
@BindView(R.id.libao1_rv_list)
|
||||
RecyclerView mRecyclerView;
|
||||
@BindView(R.id.libao1_rv_history)
|
||||
RecyclerView mHistoryRv;
|
||||
@BindView(R.id.libao1_pb_loading)
|
||||
ProgressBarCircularIndeterminate mLoadingLayout;
|
||||
@BindView(R.id.reuse_no_connection)
|
||||
LinearLayout mNoConnectionLayout;
|
||||
@BindView(R.id.reuse_none_data)
|
||||
LinearLayout mEmptyLayout;
|
||||
@BindView(R.id.reuse_tv_none_data)
|
||||
TextView mEmptyTv;
|
||||
@BindView(R.id.godfather)
|
||||
SwipeLayout swipeLayout;
|
||||
@BindView(R.id.libao_et_search)
|
||||
EditText mLibaoEtSearch;
|
||||
@BindView(R.id.libao_tv_back)
|
||||
TextView mLibaoTvBack;
|
||||
@BindView(R.id.libao_tv_search)
|
||||
TextView mLibaoTvSearch;
|
||||
|
||||
private TextView mFooterHint;
|
||||
private LibaoSearchFragment mSearchFragment;
|
||||
private LibaoNewFragment mNewFragment;
|
||||
|
||||
private LinearLayoutManager mLayoutManager;
|
||||
private Libao1FragmentAdapter adapter;
|
||||
private Libao1FragmentAdapter mNormalAdapter;
|
||||
private LibaoHistoryAdapter historyAdapter;
|
||||
|
||||
private boolean mIsSearch; // 记录页面状态 搜索页面/普通页面
|
||||
private boolean isDone;
|
||||
private boolean historyIsEmpty;
|
||||
private String mSearckKey; // 记录搜索关键字
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
changeAdapter(true);
|
||||
}
|
||||
};
|
||||
private LinearLayoutManager mHistoryLm;
|
||||
private boolean mIsSearch;
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_libao1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initView(View view) {
|
||||
super.initView(view);
|
||||
mRefreshLayout.setColorSchemeResources(R.color.theme);
|
||||
mRefreshLayout.setOnRefreshListener(this);
|
||||
|
||||
swipeLayout.setDragEdge(SwipeLayout.DragEdge.Bottom);
|
||||
swipeLayout.setSwipeEnabled(false);
|
||||
mRecyclerView.setHasFixedSize(true);
|
||||
mLayoutManager = new LinearLayoutManager(getActivity());
|
||||
mRecyclerView.setLayoutManager(mLayoutManager);
|
||||
|
||||
adapter = new Libao1FragmentAdapter(this, this, this, mIsSearch, mSearckKey, mEntrance);
|
||||
mNormalAdapter = adapter;
|
||||
mRecyclerView.addItemDecoration(new VerticalItemDecoration(getContext(), 8, false));
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
|
||||
historyAdapter = new LibaoHistoryAdapter(getContext(), this);
|
||||
mHistoryLm = new LinearLayoutManager(getActivity());
|
||||
mHistoryRv.setLayoutManager(mHistoryLm);
|
||||
mHistoryRv.setAdapter(historyAdapter);
|
||||
|
||||
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
if (newState == RecyclerView.SCROLL_STATE_IDLE
|
||||
&& mLayoutManager.findLastVisibleItemPosition() + 1 == adapter.getItemCount()) {
|
||||
if (historyIsEmpty && mFooterHint != null) {
|
||||
mFooterHint.setText("加载完毕");
|
||||
}
|
||||
if (!adapter.isOver() && !adapter.isLoading() && !adapter.isNetworkError()) {
|
||||
isDone = false;
|
||||
adapter.addLibaoList(mIsSearch, adapter.getLibaoListSize());
|
||||
}
|
||||
}
|
||||
|
||||
if (mIsSearch) return;
|
||||
|
||||
if (mLayoutManager.findFirstVisibleItemPosition() == 0) {
|
||||
swipeLayout.setDragEdge(SwipeLayout.DragEdge.Left);
|
||||
} else {
|
||||
if (swipeLayout.getDragEdge() != SwipeLayout.DragEdge.Bottom)
|
||||
swipeLayout.setDragEdge(SwipeLayout.DragEdge.Bottom);
|
||||
}
|
||||
|
||||
if (mLayoutManager.findLastCompletelyVisibleItemPosition() + 1 != adapter.getItemCount()) {
|
||||
swipeLayout.setSwipeEnabled(false);
|
||||
} else {
|
||||
if (isDone && !historyIsEmpty) {
|
||||
swipeLayout.setSwipeEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() {
|
||||
@Override
|
||||
public void onStartOpen(SwipeLayout layout) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(SwipeLayout layout) {
|
||||
// swipeLayout.setSwipeTrue(true);
|
||||
swipeLayout.setSwipeEnabled(true);
|
||||
EventBus.getDefault().post(new EBReuse("openPage"));
|
||||
if (mFooterHint != null) {
|
||||
mFooterHint.setText("下拉回到最新礼包");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartClose(SwipeLayout layout) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(SwipeLayout layout) {
|
||||
EventBus.getDefault().post(new EBReuse("closePage"));
|
||||
// swipeLayout.setSwipeTrue(false);
|
||||
swipeLayout.setSwipeEnabled(false);
|
||||
adapter.notifyItemChanged(adapter.getItemCount() - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHandRelease(SwipeLayout layout, float xvel, float yvel) {
|
||||
}
|
||||
});
|
||||
|
||||
mHistoryRv.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
if (newState == RecyclerView.SCROLL_STATE_IDLE
|
||||
&& mHistoryLm.findLastVisibleItemPosition() + 1 == historyAdapter.getItemCount()) {
|
||||
if (!historyAdapter.isOver() && !historyAdapter.isLoading() && !historyAdapter.isNetworkError()) {
|
||||
isDone = false;
|
||||
historyAdapter.loadList(historyAdapter.getLibaoListSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||
swipeLayout.setEnabled(mHistoryLm.findFirstCompletelyVisibleItemPosition() == 0);
|
||||
}
|
||||
});
|
||||
return R.layout.fragment_libao12;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mRefreshLayout.setColorSchemeResources(R.color.theme);
|
||||
mRefreshLayout.setOnRefreshListener(this);
|
||||
mRefreshLayout.setEnabled(false);
|
||||
|
||||
mIsSearch = false;
|
||||
isDone = false;
|
||||
historyIsEmpty = false;
|
||||
mSearckKey = null;
|
||||
changeFragment();
|
||||
|
||||
mAppBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
|
||||
@Override
|
||||
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
|
||||
if (verticalOffset == 0) {
|
||||
mRefreshLayout.setEnabled(true);
|
||||
} else {
|
||||
mRefreshLayout.setEnabled(false);
|
||||
}
|
||||
int totalScrollRange = appBarLayout.getTotalScrollRange();
|
||||
if (totalScrollRange == -verticalOffset) {
|
||||
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(getActivity().getWindow().getDecorView().getWindowToken(), 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDone() { // 数据加载成功回调
|
||||
mRefreshLayout.setRefreshing(false);
|
||||
mLoadingLayout.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
// 数据加载完毕
|
||||
@Override
|
||||
public void loadDone(Object obj) {
|
||||
super.loadDone(obj);
|
||||
if (obj.toString().equals("NULL")) {
|
||||
historyIsEmpty = true;
|
||||
return;
|
||||
}
|
||||
|
||||
isDone = true;
|
||||
int i = mRecyclerView.getChildCount() - 1;
|
||||
if (!mIsSearch && i > 0) {
|
||||
View view = mRecyclerView.getChildAt(i);
|
||||
mFooterHint = (TextView) view.findViewById(R.id.footerview_hint);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadError() { // 数据加载失败回调
|
||||
mRefreshLayout.setRefreshing(false);
|
||||
mLoadingLayout.setVisibility(View.GONE);
|
||||
mRecyclerView.setVisibility(View.GONE);
|
||||
mNoConnectionLayout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadEmpty() {
|
||||
mRefreshLayout.setRefreshing(false);
|
||||
mLoadingLayout.setVisibility(View.GONE);
|
||||
// mRecyclerView.setVisibility(View.GONE);
|
||||
mEmptyLayout.setVisibility(View.VISIBLE);
|
||||
// mRefreshLayout.setEnabled(false);
|
||||
|
||||
private void changeFragment() {
|
||||
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
|
||||
hideFragments(transaction);
|
||||
if (mIsSearch) {
|
||||
mEmptyTv.setText("很抱歉,没找到相关礼包");
|
||||
mSearchFragment = alterFragment(transaction, LibaoSearchFragment.class);
|
||||
} else {
|
||||
mEmptyTv.setText("这里还没有东西哦");
|
||||
mNewFragment = alterFragment(transaction, LibaoNewFragment.class);
|
||||
}
|
||||
|
||||
transaction.commit();
|
||||
}
|
||||
|
||||
// 将所有的Fragment都置为隐藏状态。
|
||||
private void hideFragments(FragmentTransaction transaction) {
|
||||
List<Fragment> list = getChildFragmentManager().getFragments();
|
||||
if (list != null) {
|
||||
for (Fragment fragment : list) {
|
||||
transaction.hide(fragment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == 0x123 && adapter.getSkipPosition() != -1) {
|
||||
// 更新对应位置
|
||||
adapter.notifyItemChanged(adapter.getSkipPosition());
|
||||
adapter.setSkipPosition(-1);
|
||||
private <T extends Fragment> T alterFragment(FragmentTransaction transaction, Class<T> cls) {
|
||||
T fragmentByTag = (T) getChildFragmentManager().findFragmentByTag(cls.getSimpleName());
|
||||
try {
|
||||
if (fragmentByTag != null) {
|
||||
transaction.show(fragmentByTag);
|
||||
if (fragmentByTag instanceof LibaoSearchFragment) {
|
||||
((LibaoSearchFragment) fragmentByTag).search();
|
||||
}
|
||||
} else {
|
||||
fragmentByTag = cls.newInstance();
|
||||
transaction.add(R.id.layout_fragment_content, fragmentByTag, cls.getSimpleName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return fragmentByTag;
|
||||
}
|
||||
|
||||
@OnClick({R.id.libao_tv_back, R.id.libao_tv_search})
|
||||
public void onViewClicked(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.libao_tv_back:
|
||||
mIsSearch = false;
|
||||
break;
|
||||
case R.id.libao_tv_search:
|
||||
String key = mLibaoEtSearch.getText().toString();
|
||||
if (TextUtils.isEmpty(key)) {
|
||||
toast("请输入关键字");
|
||||
return;
|
||||
} else if (!mIsSearch){
|
||||
mIsSearch = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (mIsSearch) {
|
||||
mLibaoTvBack.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mLibaoTvBack.setVisibility(View.GONE);
|
||||
}
|
||||
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(getActivity().getWindow().getDecorView().getWindowToken(), 0);
|
||||
changeFragment();
|
||||
}
|
||||
|
||||
public String getSearchKey() {
|
||||
return mLibaoEtSearch.getText().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
postDelayedRunnable(runnable, 1000);
|
||||
}
|
||||
|
||||
@OnClick(R.id.reuse_no_connection)
|
||||
public void reconnection() { // 重新连接
|
||||
mRefreshLayout.setRefreshing(true);
|
||||
mRecyclerView.setVisibility(View.VISIBLE);
|
||||
mLoadingLayout.setVisibility(View.VISIBLE);
|
||||
mNoConnectionLayout.setVisibility(View.GONE);
|
||||
postDelayedRunnable(runnable, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void search(boolean isSearch, String searchKey) { //搜索回调
|
||||
if (mEmptyLayout.getVisibility() == View.VISIBLE) {
|
||||
mEmptyLayout.setVisibility(View.GONE);
|
||||
}
|
||||
mIsSearch = isSearch;
|
||||
mSearckKey = searchKey;
|
||||
changeAdapter(false);
|
||||
|
||||
// if (isSearch) {
|
||||
// swipeLayout.setSwipeEnabled(false);
|
||||
// } else {
|
||||
// swipeLayout.setSwipeEnabled(true);
|
||||
// }
|
||||
}
|
||||
|
||||
private void changeAdapter(boolean isRefresh) {
|
||||
String entrance = getActivity().getIntent().getStringExtra(EntranceUtils.KEY_ENTRANCE);
|
||||
if (mIsSearch) {
|
||||
adapter = new Libao1FragmentAdapter(this, this, this, mIsSearch, mSearckKey, entrance);
|
||||
mSearchFragment.onRefresh();
|
||||
} else {
|
||||
if (mNormalAdapter != null && !isRefresh) {
|
||||
adapter = mNormalAdapter;
|
||||
// adapter.setSearchKey(mSearckKey);
|
||||
} else {
|
||||
adapter = new Libao1FragmentAdapter(this, this, this, mIsSearch, null, entrance);
|
||||
mNormalAdapter = adapter;
|
||||
adapter.addLibaoList(false, 0);
|
||||
}
|
||||
mNewFragment.onRefresh();
|
||||
}
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
// Fragment界面切换事件
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEventMainThread(EBUISwitch busNine) {
|
||||
if (LibaoActivity.EB_LIBAOACTIVITY_TAG.equals(busNine.getFrom())) {
|
||||
if (busNine.getPosition() == 0) {
|
||||
if (mLoadingLayout.getVisibility() == View.VISIBLE) {
|
||||
adapter.addLibaoList(false, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void colseRefresh() {
|
||||
mRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,160 +0,0 @@
|
||||
package com.gh.gamecenter.libao;
|
||||
|
||||
import android.content.Context;
|
||||
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.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.fragment.BaseFragment;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
|
||||
/**
|
||||
* Created by khy on 5/09/17.
|
||||
*/
|
||||
|
||||
public class Libao1Fragment2 extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener {
|
||||
|
||||
@BindView(R.id.libao_appbar)
|
||||
AppBarLayout mAppBar;
|
||||
@BindView(R.id.libao_refresh)
|
||||
SwipeRefreshLayout mRefreshLayout;
|
||||
@BindView(R.id.libao_et_search)
|
||||
EditText mLibaoEtSearch;
|
||||
@BindView(R.id.libao_tv_back)
|
||||
TextView mLibaoTvBack;
|
||||
@BindView(R.id.libao_tv_search)
|
||||
TextView mLibaoTvSearch;
|
||||
|
||||
private LibaoSearchFragment mSearchFragment;
|
||||
private LibaoNewFragment mNewFragment;
|
||||
|
||||
private boolean mIsSearch;
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_libao12;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mRefreshLayout.setColorSchemeResources(R.color.theme);
|
||||
mRefreshLayout.setOnRefreshListener(this);
|
||||
mRefreshLayout.setEnabled(false);
|
||||
|
||||
changeFragment();
|
||||
|
||||
mAppBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
|
||||
@Override
|
||||
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
|
||||
if (verticalOffset == 0) {
|
||||
mRefreshLayout.setEnabled(true);
|
||||
} else {
|
||||
mRefreshLayout.setEnabled(false);
|
||||
}
|
||||
int totalScrollRange = appBarLayout.getTotalScrollRange();
|
||||
if (totalScrollRange == -verticalOffset) {
|
||||
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(getActivity().getWindow().getDecorView().getWindowToken(), 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void changeFragment() {
|
||||
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
|
||||
hideFragments(transaction);
|
||||
if (mIsSearch) {
|
||||
mSearchFragment = alterFragment(transaction, LibaoSearchFragment.class);
|
||||
} else {
|
||||
mNewFragment = alterFragment(transaction, LibaoNewFragment.class);
|
||||
}
|
||||
|
||||
transaction.commit();
|
||||
}
|
||||
|
||||
// 将所有的Fragment都置为隐藏状态。
|
||||
private void hideFragments(FragmentTransaction transaction) {
|
||||
List<Fragment> list = getChildFragmentManager().getFragments();
|
||||
if (list != null) {
|
||||
for (Fragment fragment : list) {
|
||||
transaction.hide(fragment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private <T extends Fragment> T alterFragment(FragmentTransaction transaction, Class<T> cls) {
|
||||
T fragmentByTag = (T) getChildFragmentManager().findFragmentByTag(cls.getSimpleName());
|
||||
try {
|
||||
if (fragmentByTag != null) {
|
||||
transaction.show(fragmentByTag);
|
||||
if (fragmentByTag instanceof LibaoSearchFragment) {
|
||||
((LibaoSearchFragment) fragmentByTag).search();
|
||||
}
|
||||
} else {
|
||||
fragmentByTag = cls.newInstance();
|
||||
transaction.add(R.id.layout_fragment_content, fragmentByTag, cls.getSimpleName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return fragmentByTag;
|
||||
}
|
||||
|
||||
@OnClick({R.id.libao_tv_back, R.id.libao_tv_search})
|
||||
public void onViewClicked(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.libao_tv_back:
|
||||
mIsSearch = false;
|
||||
break;
|
||||
case R.id.libao_tv_search:
|
||||
String key = mLibaoEtSearch.getText().toString();
|
||||
if (TextUtils.isEmpty(key)) {
|
||||
toast("请输入关键字");
|
||||
return;
|
||||
} else if (!mIsSearch){
|
||||
mIsSearch = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (mIsSearch) {
|
||||
mLibaoTvBack.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mLibaoTvBack.setVisibility(View.GONE);
|
||||
}
|
||||
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(getActivity().getWindow().getDecorView().getWindowToken(), 0);
|
||||
changeFragment();
|
||||
}
|
||||
|
||||
public String getSearchKey() {
|
||||
return mLibaoEtSearch.getText().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
if (mIsSearch) {
|
||||
mSearchFragment.onRefresh();
|
||||
} else {
|
||||
mNewFragment.onRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
public void colseRefresh() {
|
||||
mRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,370 +0,0 @@
|
||||
package com.gh.gamecenter.libao;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.RecyclerView.ViewHolder;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
import com.gh.base.OnRequestCallBackListener;
|
||||
import com.lightgame.adapter.BaseRecyclerAdapter;
|
||||
import com.gh.common.constant.ItemViewType;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.LibaoUtils;
|
||||
import com.gh.common.util.PlatformUtils;
|
||||
import com.lightgame.utils.Utils;
|
||||
import com.gh.gamecenter.LibaoDetailActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.LibaoNormalViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.LibaoSearchViewHolder;
|
||||
import com.gh.gamecenter.db.LibaoDao;
|
||||
import com.gh.gamecenter.entity.LibaoEntity;
|
||||
import com.gh.gamecenter.entity.LibaoStatusEntity;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import retrofit2.HttpException;
|
||||
import rx.Observable;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.functions.Func1;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/12/12.
|
||||
*/
|
||||
class Libao1FragmentAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
|
||||
private final static int ITEM_SEARCH = 1;
|
||||
private final static int ITEM_FOOTER = 1;
|
||||
private Libao1Fragment mLibao1Fragment;
|
||||
private OnRequestCallBackListener mCallBackListener;
|
||||
private OnSearchCallBackListener mSearchListener;
|
||||
private List<LibaoEntity> mLibaoList;
|
||||
private LibaoDao mLibaoDao;
|
||||
private String mSerchKey;
|
||||
private String mEntrance;
|
||||
private int skipPosition;
|
||||
private boolean mIsSearch;
|
||||
private boolean isLoading;
|
||||
private boolean isOver;
|
||||
private boolean isNetworkError;
|
||||
|
||||
Libao1FragmentAdapter(Libao1Fragment libao1Fragment,OnRequestCallBackListener requestCallBackListener,
|
||||
OnSearchCallBackListener searchListener, boolean isSearch, String key, String entrance) {
|
||||
super(libao1Fragment.getActivity());
|
||||
mLibao1Fragment = libao1Fragment;
|
||||
mCallBackListener = requestCallBackListener;
|
||||
mSearchListener = searchListener;
|
||||
mIsSearch = isSearch;
|
||||
mSerchKey = key;
|
||||
|
||||
mEntrance = entrance;
|
||||
|
||||
mLibaoList = new ArrayList<>();
|
||||
|
||||
mLibaoDao = new LibaoDao(mContext);
|
||||
|
||||
skipPosition = -1;
|
||||
|
||||
if (isSearch) {
|
||||
addLibaoList(true, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void addLibaoList(boolean isSearch, int offset) {
|
||||
if (isLoading) return;
|
||||
|
||||
isLoading = true;
|
||||
|
||||
final Observable<List<LibaoEntity>> libaoApi;
|
||||
if (isSearch) {
|
||||
libaoApi = RetrofitManager.getLibao().getLibaoBySearch(mSerchKey, offset);
|
||||
} else {
|
||||
libaoApi = RetrofitManager.getLibao().getLibao(offset);
|
||||
}
|
||||
|
||||
libaoApi.map(new Func1<List<LibaoEntity>, List<LibaoEntity>>() {
|
||||
@Override
|
||||
public List<LibaoEntity> call(List<LibaoEntity> list) {
|
||||
// 去掉重复数据
|
||||
return LibaoUtils.removeDuplicateData(mLibaoList, list);
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<List<LibaoEntity>>() {
|
||||
@Override
|
||||
public void onResponse(List<LibaoEntity> response) {
|
||||
mLibaoList.addAll(response);
|
||||
notifyDataSetChanged();
|
||||
|
||||
if (response.size() < 20) {
|
||||
isOver = true;
|
||||
mCallBackListener.loadDone("TAG");
|
||||
}
|
||||
|
||||
if (mLibaoList.size() == 0) {
|
||||
mCallBackListener.loadEmpty();
|
||||
} else {
|
||||
mCallBackListener.loadDone();
|
||||
}
|
||||
|
||||
isLoading = false;
|
||||
isNetworkError = false;
|
||||
|
||||
if (response.size() != 0) {
|
||||
getLibaoStatus(response);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
mCallBackListener.loadError();
|
||||
isNetworkError = true;
|
||||
isLoading = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 重复领取实现 在可重复领取的情况下
|
||||
* 1.判断当前礼包是否可以领取或淘号,否,有领取记录以淘号优先,没领取记录则按照原来的规则显示
|
||||
* 2.记录最后一个领取时间,没有领取过则按照原来的规则显示
|
||||
* 3.判断最后领取时间是不是当天,不是则按照原来的规则显示
|
||||
* 4.定时刷新-游戏详情
|
||||
* 4-1:每次进来都要获取服务器时间
|
||||
* 4-2:获取当前时间到凌晨12点的差值 定时刷新
|
||||
*/
|
||||
|
||||
//获取礼包状态
|
||||
private void getLibaoStatus(List<LibaoEntity> response) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0, size = response.size(); i < size; i++) {
|
||||
builder.append(response.get(i).getId());
|
||||
builder.append("-");
|
||||
}
|
||||
if (builder.length() == 0) return;
|
||||
builder.deleteCharAt(builder.length() - 1);
|
||||
String ids = builder.toString();
|
||||
|
||||
LibaoUtils.getLibaoStatus(ids, new LibaoUtils.PostLibaoListener() {
|
||||
@Override
|
||||
public void postSucced(Object response) {
|
||||
List<LibaoStatusEntity> statusList = (List<LibaoStatusEntity>) response;
|
||||
|
||||
LibaoUtils.initLiBaoEntity(mLibaoDao, statusList, mLibaoList, mContext);
|
||||
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postFailed(Throwable error) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view;
|
||||
switch (viewType) {
|
||||
case ItemViewType.SEARCH_NORMAL:
|
||||
view = mLayoutInflater.inflate(R.layout.libao_item_search, parent, false);
|
||||
return new LibaoSearchViewHolder(view);
|
||||
case ItemViewType.LOADING:
|
||||
view = mLayoutInflater.inflate(R.layout.refresh_footerview, parent, false);
|
||||
return new FooterViewHolder(view);
|
||||
default:
|
||||
view = mLayoutInflater.inflate(R.layout.libao_item, parent, false);
|
||||
return new LibaoNormalViewHolder(view);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
if (holder instanceof LibaoNormalViewHolder) {
|
||||
initLibaoViewHolder((LibaoNormalViewHolder) holder, position);
|
||||
} else if (holder instanceof LibaoSearchViewHolder) {
|
||||
initSearchViewHolder((LibaoSearchViewHolder) holder);
|
||||
} else if (holder instanceof FooterViewHolder) {
|
||||
initFooterViewHolder((FooterViewHolder) holder);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (position == 0) {
|
||||
return ItemViewType.SEARCH_NORMAL;
|
||||
} else if (position == getItemCount() - 1) {
|
||||
return ItemViewType.LOADING;
|
||||
} else {
|
||||
return ItemViewType.LIBAO_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (mLibaoList.size() == 0) {
|
||||
return 1;
|
||||
}
|
||||
return mLibaoList.size() + ITEM_FOOTER + ITEM_SEARCH;
|
||||
}
|
||||
|
||||
private void initLibaoViewHolder(final LibaoNormalViewHolder holder, final int position) {
|
||||
final LibaoEntity libaoEntity = mLibaoList.get(position - 1);
|
||||
holder.libaoName.setText(libaoEntity.getName());
|
||||
if (TextUtils.isEmpty(libaoEntity.getPlatform())) {
|
||||
holder.libaoGameName.setText(libaoEntity.getGame().getName());
|
||||
} else {
|
||||
holder.libaoGameName.setText(libaoEntity.getGame().getName() + " - " + PlatformUtils.getInstance(mContext)
|
||||
.getPlatformName(libaoEntity.getPlatform()));
|
||||
}
|
||||
// holder.libaoGameIcon.setImageURI(libaoEntity.getIcon());
|
||||
ImageUtils.Companion.display(holder.libaoGameIcon, libaoEntity.getIcon());
|
||||
|
||||
String content;
|
||||
if (libaoEntity.getContent().contains("<br/>")) {
|
||||
content = libaoEntity.getContent().replaceAll("<br/>", " ");
|
||||
} else {
|
||||
content = libaoEntity.getContent();
|
||||
}
|
||||
holder.libaoDes.setText(content);
|
||||
|
||||
if (libaoEntity.getStatus() != null) {
|
||||
LibaoUtils.initLibaoBtn(mContext, holder.libaoBtnStatus, libaoEntity, mLibaoDao, false, null,
|
||||
mEntrance + "+(礼包中心:最新)");
|
||||
// holder.libaoBtnStatus.setClickable(false);
|
||||
String tv = holder.libaoBtnStatus.getText().toString();
|
||||
if ("已结束".equals(tv) || "已领光".equals(tv)) {
|
||||
holder.libaoBtnStatus.setClickable(true);
|
||||
} else {
|
||||
holder.libaoBtnStatus.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startLibaoDetailActivity(position, libaoEntity);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startLibaoDetailActivity(position, libaoEntity);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void startLibaoDetailActivity(int position, LibaoEntity libaoEntity) {
|
||||
skipPosition = position;
|
||||
Intent intent = LibaoDetailActivity.getIntent(mContext, libaoEntity, mEntrance + "+(礼包中心:最新)");
|
||||
mLibao1Fragment.startActivityForResult(intent, 0x123);
|
||||
}
|
||||
|
||||
private void initSearchViewHolder(final LibaoSearchViewHolder holder) {
|
||||
if (mSerchKey != null) {
|
||||
holder.searchEt.setText(mSerchKey);
|
||||
}
|
||||
|
||||
if (mIsSearch) {
|
||||
holder.backTv.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.backTv.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
holder.backTv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mSearchListener.search(false, holder.searchEt.getText().toString());
|
||||
}
|
||||
});
|
||||
|
||||
holder.searchTv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
if (TextUtils.isEmpty(holder.searchEt.getText().toString())) {
|
||||
Utils.toast(mContext, "请输入关键字");
|
||||
return;
|
||||
}
|
||||
mSearchListener.search(true, holder.searchEt.getText().toString());
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
holder.searchEt.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||
@Override
|
||||
public void onFocusChange(View v, boolean hasFocus) {
|
||||
if (!hasFocus) {
|
||||
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(mLibao1Fragment.getActivity().getWindow().getDecorView().getWindowToken(), 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initFooterViewHolder(FooterViewHolder holder) {
|
||||
holder.initItemPadding();
|
||||
if (isNetworkError) {
|
||||
holder.loading.setVisibility(View.GONE);
|
||||
holder.hint.setText("加载失败,点击重试");
|
||||
holder.itemView.setClickable(true);
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
isNetworkError = false;
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
addLibaoList(mIsSearch, mLibaoList.size());
|
||||
}
|
||||
});
|
||||
} else if (isOver) {
|
||||
holder.loading.setVisibility(View.GONE);
|
||||
holder.itemView.setClickable(false);
|
||||
if (mIsSearch) {
|
||||
holder.hint.setText("加载完毕");
|
||||
} else {
|
||||
holder.hint.setText("上拉查看历史礼包");
|
||||
}
|
||||
} else {
|
||||
holder.loading.setVisibility(View.VISIBLE);
|
||||
holder.hint.setText(R.string.loading);
|
||||
holder.itemView.setClickable(false);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isNetworkError() {
|
||||
return isNetworkError;
|
||||
}
|
||||
|
||||
public void setNetworkError(boolean networkError) {
|
||||
isNetworkError = networkError;
|
||||
}
|
||||
|
||||
public boolean isOver() {
|
||||
return isOver;
|
||||
}
|
||||
|
||||
public boolean isLoading() {
|
||||
return isLoading;
|
||||
}
|
||||
|
||||
public int getLibaoListSize() {
|
||||
return mLibaoList.size();
|
||||
}
|
||||
|
||||
public int getSkipPosition() {
|
||||
return skipPosition;
|
||||
}
|
||||
|
||||
public void setSkipPosition(int position) {
|
||||
skipPosition = position;
|
||||
}
|
||||
|
||||
}
|
||||
@ -205,7 +205,8 @@ class LibaoNewAdapter(callBackListener: OnRequestCallBackListener<Any>,
|
||||
holder.libaoDes.text = content
|
||||
|
||||
if (libaoEntity.status != null) {
|
||||
LibaoUtils.initLibaoBtn(mContext, holder.libaoBtnStatus, libaoEntity, mLibaoDao, false, null, "(礼包中心-最新)")
|
||||
LibaoUtils.initLibaoBtn(mContext, holder.libaoBtnStatus, libaoEntity, mLibaoDao, false, null,
|
||||
mEntrance + "+(礼包中心:最新)")
|
||||
val tv = holder.libaoBtnStatus.text.toString()
|
||||
if ("已结束" == tv || "已领光" == tv) {
|
||||
holder.libaoBtnStatus.isClickable = true
|
||||
@ -219,7 +220,7 @@ class LibaoNewAdapter(callBackListener: OnRequestCallBackListener<Any>,
|
||||
|
||||
fun startLibaoDetailActivity(position: Int, libaoEntity: LibaoEntity) {
|
||||
skipPosition = position
|
||||
val intent = LibaoDetailActivity.getIntent(mContext, libaoEntity, mEntrance + "+(礼包中心-最新)")
|
||||
val intent = LibaoDetailActivity.getIntent(mContext, libaoEntity, mEntrance + "+(礼包中心:最新)")
|
||||
mFragment.startActivityForResult(intent, 0x123)
|
||||
}
|
||||
|
||||
|
||||
@ -247,8 +247,8 @@ public class LibaoNewFragment extends BaseFragment implements SwipeRefreshLayout
|
||||
|
||||
private void colseRefresh() {
|
||||
Fragment parentFragment = getParentFragment();
|
||||
if (parentFragment instanceof Libao1Fragment2) {
|
||||
((Libao1Fragment2) parentFragment).colseRefresh();
|
||||
if (parentFragment instanceof Libao1Fragment) {
|
||||
((Libao1Fragment) parentFragment).colseRefresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ class LibaoSearchAdapter(fragment: LibaoSearchFragment,
|
||||
fun addLibaoList(offset: Int) {
|
||||
val parentFragment = mFragment.parentFragment
|
||||
var searchKey: String? = null
|
||||
if (parentFragment is Libao1Fragment2) {
|
||||
if (parentFragment is Libao1Fragment) {
|
||||
searchKey = parentFragment.searchKey
|
||||
}
|
||||
|
||||
@ -217,7 +217,8 @@ class LibaoSearchAdapter(fragment: LibaoSearchFragment,
|
||||
holder.libaoDes.text = content
|
||||
|
||||
if (libaoEntity.status != null) {
|
||||
LibaoUtils.initLibaoBtn(mContext, holder.libaoBtnStatus, libaoEntity, mLibaoDao, false, null, "(礼包中心-最新)")
|
||||
LibaoUtils.initLibaoBtn(mContext, holder.libaoBtnStatus, libaoEntity, mLibaoDao, false, null,
|
||||
mEntrance + "+(礼包中心:最新)")
|
||||
val tv = holder.libaoBtnStatus.text.toString()
|
||||
if ("已结束" == tv || "已领光" == tv) {
|
||||
holder.libaoBtnStatus.isClickable = true
|
||||
@ -231,7 +232,7 @@ class LibaoSearchAdapter(fragment: LibaoSearchFragment,
|
||||
|
||||
fun startLibaoDetailActivity(position: Int, libaoEntity: LibaoEntity) {
|
||||
skipPosition = position
|
||||
val intent = LibaoDetailActivity.getIntent(mContext, libaoEntity, mEntrance + "+(礼包中心-最新)")
|
||||
val intent = LibaoDetailActivity.getIntent(mContext, libaoEntity, mEntrance + "+(礼包中心:最新)")
|
||||
mFragment.startActivityForResult(intent, 0x123)
|
||||
}
|
||||
|
||||
|
||||
@ -117,8 +117,8 @@ public class LibaoSearchFragment extends BaseFragment implements SwipeRefreshLay
|
||||
|
||||
private void colseRefresh() {
|
||||
Fragment parentFragment = getParentFragment();
|
||||
if (parentFragment instanceof Libao1Fragment2) {
|
||||
((Libao1Fragment2) parentFragment).colseRefresh();
|
||||
if (parentFragment instanceof Libao1Fragment) {
|
||||
((Libao1Fragment) parentFragment).colseRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user