207 lines
7.9 KiB
Java
207 lines
7.9 KiB
Java
package com.gh.gamecenter;
|
||
|
||
import android.content.Context;
|
||
import android.content.Intent;
|
||
import android.os.Bundle;
|
||
import android.support.annotation.NonNull;
|
||
import android.support.v7.widget.LinearLayoutManager;
|
||
import android.support.v7.widget.RecyclerView;
|
||
import android.view.View;
|
||
import android.view.ViewGroup;
|
||
import android.widget.CheckBox;
|
||
import android.widget.CompoundButton;
|
||
import android.widget.ProgressBar;
|
||
import android.widget.RelativeLayout;
|
||
import android.widget.TextView;
|
||
|
||
import com.halo.assistant.HaloApp;
|
||
import com.gh.base.BaseActivity;
|
||
import com.gh.common.util.DisplayUtils;
|
||
import com.lightgame.utils.Utils;
|
||
import com.gh.common.view.VerticalItemDecoration;
|
||
import com.gh.gamecenter.adapter.KcSelectGameAdapter;
|
||
import com.gh.gamecenter.kuaichuan.FileInfo;
|
||
|
||
import java.util.ArrayList;
|
||
import java.util.HashMap;
|
||
import java.util.List;
|
||
|
||
import butterknife.BindView;
|
||
|
||
import static com.gh.gamecenter.FileSenderActivity.KC_REPEAT_RESULT;
|
||
|
||
/**
|
||
* Created by khy on 2017/1/20.
|
||
* 快传-选择游戏
|
||
*/
|
||
public class KcSelectGameActivity extends BaseActivity {
|
||
|
||
public static final String KEY_FILE_INFO = KcSelectGameActivity.KEY_FILE_INFO;
|
||
@BindView(R.id.select_game_rv)
|
||
RecyclerView mSelectRv;
|
||
@BindView(R.id.select_game_send)
|
||
TextView mSelectSend;
|
||
@BindView(R.id.select_game_all)
|
||
CheckBox selectAll;
|
||
@BindView(R.id.install_count)
|
||
TextView installCount;
|
||
@BindView(R.id.select_game_installed_ll)
|
||
RelativeLayout installRl;
|
||
@BindView(R.id.select_game_pb)
|
||
ProgressBar mSelectPb;
|
||
|
||
private KcSelectGameAdapter mAdapter;
|
||
|
||
public final static String KEY_ISCONN = "isConn";
|
||
public final static int SEND_OVER_REQUEST = 16; // 快传 传输完成后直接退出选择游戏(当前)页面
|
||
|
||
private boolean mIsConn;
|
||
private LinearLayoutManager layoutManager;
|
||
private RelativeLayout.LayoutParams rparams;
|
||
|
||
@NonNull
|
||
public static Intent getIntent(Context context, boolean isConn) {
|
||
Intent intent = new Intent(context, KcSelectGameActivity.class);
|
||
intent.putExtra(KEY_ISCONN, isConn);
|
||
return intent;
|
||
}
|
||
|
||
@Override
|
||
protected int getLayoutId() {
|
||
return R.layout.activity_kc_select_game;
|
||
}
|
||
|
||
@Override
|
||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||
super.onActivityResult(requestCode, resultCode, data);
|
||
if (requestCode == SEND_OVER_REQUEST) {
|
||
if (data != null && data.getExtras() != null && data.getExtras().getBoolean("isFinish")) {
|
||
finish();
|
||
}
|
||
}
|
||
}
|
||
|
||
@Override
|
||
protected void onCreate(Bundle savedInstanceState) {
|
||
super.onCreate(savedInstanceState);
|
||
setNavigationTitle(getString(R.string.title_select_game));
|
||
|
||
if (getIntent() != null && getIntent().getExtras() != null) {
|
||
mIsConn = getIntent().getExtras().getBoolean(KEY_ISCONN);
|
||
} else {
|
||
mIsConn = false;
|
||
}
|
||
|
||
selectAll.setVisibility(View.GONE);
|
||
|
||
mAdapter = new KcSelectGameAdapter(this, mSelectSend, installCount, mSelectPb);
|
||
layoutManager = new LinearLayoutManager(this);
|
||
mSelectRv.setLayoutManager(layoutManager);
|
||
mSelectRv.addItemDecoration(new VerticalItemDecoration(this, 8, false));
|
||
mSelectRv.setAdapter(mAdapter);
|
||
|
||
rparams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||
DisplayUtils.dip2px(this, 40));
|
||
|
||
mSelectSend.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View v) {
|
||
List<FileInfo> selectData = mAdapter.getSelectData();
|
||
if (selectData.size() == 0) {
|
||
Utils.toast(KcSelectGameActivity.this, "请选择要发送的游戏");
|
||
return;
|
||
}
|
||
|
||
if (mIsConn) {
|
||
List<FileInfo> oldInfo = (List<FileInfo>) HaloApp.get(KcSelectGameActivity.KEY_FILE_INFO, false);
|
||
if (oldInfo == null) {
|
||
oldInfo = new ArrayList<>();
|
||
}
|
||
for (FileInfo fileInfo : selectData) {
|
||
oldInfo.add(fileInfo);
|
||
}
|
||
setResult(KC_REPEAT_RESULT);
|
||
finish();
|
||
} else {
|
||
HaloApp.put(KcSelectGameActivity.KEY_FILE_INFO, selectData);
|
||
startActivityForResult(ChooseReceiverActivity.getIntent(KcSelectGameActivity.this, false), SEND_OVER_REQUEST);
|
||
}
|
||
|
||
}
|
||
});
|
||
|
||
selectAll.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||
@Override
|
||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||
HashMap<Integer, Boolean> selectPosition = new HashMap<>();
|
||
int itemCount = mAdapter.getItemCount();
|
||
if (isChecked) {
|
||
for (int i = 0; i < itemCount; i++) {
|
||
selectPosition.put(i, true);
|
||
}
|
||
} else {
|
||
for (int i = 0; i < itemCount; i++) {
|
||
selectPosition.put(i, false);
|
||
}
|
||
}
|
||
|
||
mAdapter.setSelectPosition(selectPosition);
|
||
mAdapter.notifyItemRangeChanged(0, itemCount);
|
||
}
|
||
});
|
||
|
||
mSelectRv.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||
@Override
|
||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||
super.onScrolled(recyclerView, dx, dy);
|
||
if (dy == 0) return;
|
||
|
||
int position = layoutManager.findFirstVisibleItemPosition();
|
||
int gameSize = mAdapter.getGameSize();
|
||
|
||
if (gameSize == 0) { // 游戏列表为空
|
||
if (position == gameSize) {
|
||
int buttom = layoutManager.findViewByPosition(position).getBottom();
|
||
int i = installRl.getHeight() + DisplayUtils.dip2px(KcSelectGameActivity.this, 43);
|
||
if (buttom <= i && i / 2 < buttom) {
|
||
rparams.topMargin = buttom - installRl.getHeight() - DisplayUtils.dip2px(KcSelectGameActivity.this, 43);
|
||
installRl.setLayoutParams(rparams);
|
||
installCount.setText("已安装的游戏(" + gameSize + ")");
|
||
} else {
|
||
installCount.setText("已安装的应用(" + mAdapter.getAppSize() + ")");
|
||
rparams.topMargin = 0;
|
||
installRl.setLayoutParams(rparams);
|
||
}
|
||
} else {
|
||
installCount.setText("已安装的应用(" + mAdapter.getAppSize() + ")");
|
||
rparams.topMargin = 0;
|
||
installRl.setLayoutParams(rparams);
|
||
}
|
||
} else {
|
||
if (position >= gameSize) {
|
||
installCount.setText("已安装的应用(" + mAdapter.getAppSize() + ")");
|
||
} else {
|
||
installCount.setText("已安装的游戏(" + mAdapter.getGameSize() + ")");
|
||
}
|
||
|
||
if (position == gameSize - 1) {
|
||
int buttom = layoutManager.findViewByPosition(position).getBottom();
|
||
if (buttom <= installRl.getHeight()) {
|
||
rparams.topMargin = buttom - installRl.getHeight();
|
||
installRl.setLayoutParams(rparams);
|
||
} else {
|
||
rparams.topMargin = 0;
|
||
installRl.setLayoutParams(rparams);
|
||
}
|
||
} else {
|
||
rparams.topMargin = 0;
|
||
installRl.setLayoutParams(rparams);
|
||
}
|
||
}
|
||
|
||
}
|
||
});
|
||
|
||
}
|
||
}
|