122 lines
4.2 KiB
Java
122 lines
4.2 KiB
Java
package com.gh.gamecenter.personal;
|
|
|
|
import android.os.Bundle;
|
|
import android.support.annotation.Nullable;
|
|
import android.support.v7.widget.LinearLayoutManager;
|
|
import android.support.v7.widget.RecyclerView;
|
|
import android.view.View;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.TextView;
|
|
|
|
import com.gh.base.BaseFragment;
|
|
import com.gh.common.util.DownloadItemUtils;
|
|
import com.gh.download.DataWatcher;
|
|
import com.gh.download.DownloadEntity;
|
|
import com.gh.download.DownloadManager;
|
|
import com.gh.gamecenter.R;
|
|
import com.gh.gamecenter.entity.GameEntity;
|
|
import com.gh.gamecenter.eventbus.EBPackage;
|
|
import com.gh.gamecenter.eventbus.EBReuse;
|
|
import com.gh.gamecenter.eventbus.EBSkip;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import butterknife.BindView;
|
|
import de.greenrobot.event.EventBus;
|
|
|
|
/**
|
|
* Created by LGT on 2016/8/12.
|
|
* 我的关注-已安装界面
|
|
*/
|
|
public class InstallFragment extends BaseFragment {
|
|
|
|
@BindView(R.id.fm_install_rv_show) RecyclerView fm_install_rv_show;
|
|
@BindView(R.id.reuse_nodata_skip) LinearLayout reuse_nodata_skip;
|
|
@BindView(R.id.reuse_nodata_skip_tv_hint) TextView reuse_nodata_skip_tv_hint;
|
|
@BindView(R.id.reuse_nodata_skip_tv_btn) TextView reuse_nodata_skip_tv_btn;
|
|
|
|
private InstallFragmentAdapter adapter;
|
|
|
|
private DataWatcher dataWatcher = new DataWatcher() {
|
|
@Override
|
|
public void onDataChanged(DownloadEntity downloadEntity) {
|
|
ArrayList<Integer> locationList = adapter.getLocationMap().get(downloadEntity.getPackageName());
|
|
if (locationList != null && locationList.size() != 0) {
|
|
GameEntity gameEntity;
|
|
for (int location : locationList) {
|
|
gameEntity = adapter.getGameList().get(location);
|
|
if (gameEntity != null) {
|
|
DownloadItemUtils.processDate(getActivity(), gameEntity,
|
|
downloadEntity, adapter, location);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
@Override
|
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
|
|
init(R.layout.fm_install);
|
|
|
|
reuse_nodata_skip.setVisibility(View.GONE);
|
|
reuse_nodata_skip_tv_hint.setText("暂无游戏");
|
|
reuse_nodata_skip_tv_btn.setText("查看精品推荐");
|
|
reuse_nodata_skip_tv_btn.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
EventBus.getDefault().post(new EBSkip("GameFragment", 1));
|
|
}
|
|
});
|
|
|
|
fm_install_rv_show.setHasFixedSize(true);
|
|
fm_install_rv_show.setLayoutManager(new LinearLayoutManager(getActivity()));
|
|
adapter = new InstallFragmentAdapter(this);
|
|
fm_install_rv_show.setAdapter(adapter);
|
|
}
|
|
|
|
@Override
|
|
public void loadEmpty() {
|
|
fm_install_rv_show.setVisibility(View.GONE);
|
|
reuse_nodata_skip.setVisibility(View.VISIBLE);
|
|
}
|
|
|
|
// 打开下载按钮事件
|
|
public void onEventMainThread(EBReuse reuse) {
|
|
if (("Refresh".equals(reuse.getType()) || "PlatformChanged".equals(reuse.getType()))
|
|
&& adapter != null) {
|
|
adapter.notifyItemRangeChanged(0, adapter.getItemCount());
|
|
}
|
|
}
|
|
|
|
//安装、卸载事件
|
|
public void onEventMainThread(EBPackage busFour) {
|
|
if ("安装".equals(busFour.getType()) || "卸载".equals(busFour.getType())) {
|
|
fm_install_rv_show.setVisibility(View.VISIBLE);
|
|
reuse_nodata_skip.setVisibility(View.GONE);
|
|
adapter = new InstallFragmentAdapter(this);
|
|
fm_install_rv_show.setAdapter(adapter);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onResume() {
|
|
if (isEverpause) {
|
|
for (GameEntity entity : adapter.getGameList()) {
|
|
entity.setEntryMap(DownloadManager.getInstance(getActivity()).getEntryMap(entity.getName()));
|
|
}
|
|
adapter.notifyDataSetChanged();
|
|
}
|
|
super.onResume();
|
|
DownloadManager.getInstance(getActivity()).addObserver(dataWatcher);
|
|
}
|
|
|
|
@Override
|
|
public void onPause() {
|
|
super.onPause();
|
|
DownloadManager.getInstance(getActivity()).removeObserver(dataWatcher);
|
|
}
|
|
|
|
}
|