This commit is contained in:
2019-12-30 15:34:57 +08:00
commit ce9ca54dcb
405 changed files with 47305 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
package com.mjsheng.myappstore.activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import com.blankj.utilcode.util.AppUtils;
import com.mjsheng.myappstore.R;
import com.mjsheng.myappstore.base.BaseActivity;
import cn.jpush.android.api.JPushInterface;
public class AboutActivity extends BaseActivity {
private TextView mTv_version_code;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
mTv_version_code = (TextView) findViewById(R.id.tv_version_code);
mTv_version_code.setText("版本号:" + AppUtils.getAppVersionName() + "");
mTv_version_code.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String registrationID = JPushInterface.getRegistrationID(AboutActivity.this);
Log.e("mjsheng", registrationID + "------------------------");
// ToastUtils.showLong("registrationID::" + registrationID);
}
});
}
public void onClick(View view) {
finish();
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,644 @@
package com.mjsheng.myappstore.activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.blankj.utilcode.util.AppUtils;
import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheMode;
import com.mjsheng.myappstore.R;
import com.mjsheng.myappstore.adapter.AppUpdateListAdapter;
import com.mjsheng.myappstore.adapter.DownloadListAdapter;
import com.mjsheng.myappstore.adapter.UninstallListAdapter;
import com.mjsheng.myappstore.base.BaseActivity;
import com.mjsheng.myappstore.bean.AppContentInfo;
import com.mjsheng.myappstore.bean.AppDownloadInfo;
import com.mjsheng.myappstore.bean.AppUpdateInfo;
import com.mjsheng.myappstore.bean.JsonCallback;
import com.mjsheng.myappstore.bean.LocalAppInfo;
import com.mjsheng.myappstore.bean.LzyResponse;
import com.mjsheng.myappstore.utils.AppsManagerUtils;
import com.mjsheng.myappstore.utils.Configure;
import com.mjsheng.myappstore.utils.SaveListUtils;
import com.mjsheng.myappstore.utils.SpacesItemDecoration;
import com.mjsheng.myappstore.utils.Utils;
import com.mjsheng.myappstore.view.RecycleGridLayoutManager;
import com.mjsheng.myappstore.widget.Sound;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import cn.jpush.android.api.JPushInterface;
import okhttp3.Call;
import okhttp3.Response;
public class DownloadActivity extends BaseActivity implements OnCheckedChangeListener, Runnable {
private static final int DOWNLOAD_RADID_BTTON_INDEX = 10;
private static final int UNINSTALL_RADID_BTTON_INDEX = 11;
private static final int UPDATE_RADID_BTTON_INDEX = 12;
private static final int ABOUT_RADID_BTTON_INDEX = 13;
private DownloadListAdapter mDownloadListAdapter;
private UninstallListAdapter mUninstallListAdapter;
private AppUpdateListAdapter mUpdateAppListAdapter;
private RelativeLayout reLayout1, reLayout2, reLayout3;
private RecyclerView mDownloadListView, mUninstallListView, mAppupdateListView;
private RadioButton mDownloadRadioButton, mUpdateRadioButton, mUninstallRadioButton;
// , mAboutRadioButton;
private RelativeLayout mLoadingLayout;
private ImageView mLoadImg;
private Integer index = 0;
private RadioGroup mManageRadioGroup;
private Integer LastCheckedId;
private List<AppContentInfo> updateAllList = new ArrayList<>();
private List<LocalAppInfo> uninstallAllList = new ArrayList<>();
private Sound sound;
private DownloadReceiver downloadReceiver;
private ExecutorService mExecutorService;
private TextView mManage_load_tv;
private RecycleGridLayoutManager mManager;
private RecycleGridLayoutManager mGridLayoutManager;
private TextView mTv_version_code;
private Button manage_about_tab;
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
initParameter();
initViews();
switch (index) {
case DOWNLOAD_RADID_BTTON_INDEX:
mDownloadRadioButton.setChecked(true);
break;
case UNINSTALL_RADID_BTTON_INDEX:
mUpdateRadioButton.setChecked(true);
break;
case UPDATE_RADID_BTTON_INDEX:
mUninstallRadioButton.setChecked(true);
break;
// case ABOUT_RADID_BTTON_INDEX:
// mAboutRadioButton.setChecked(true);
// break;
}
}
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case DOWNLOAD_RADID_BTTON_INDEX:
if (mDownloadListAdapter.getItemCount() == 0) {
// int width = (int) getResources().getDimension(R.dimen.managepage_notask_Width);
// ;
// int hight = (int) getResources().getDimension(R.dimen.managepage_notask_Hight);
// ;
// mLoadImg.setMaxWidth(width);
// mLoadImg.setMaxHeight(hight);
// ImageLoader.getDefault().load(DownloadActivity.this, R.drawable.manage_notask, mLoadImg);
mManage_load_tv.setText("没有任务");
mLoadingLayout.setVisibility(View.VISIBLE);
} else {
mLoadingLayout.setVisibility(View.GONE);
}
break;
case UNINSTALL_RADID_BTTON_INDEX:
if (mUninstallListAdapter.getItemCount() == 0) {
int width = (int) getResources().getDimension(R.dimen.managepage_notask_Width);
;
int hight = (int) getResources().getDimension(R.dimen.managepage_notask_Hight);
;
mManage_load_tv.setText("没有任务");
// mLoadImg.setMaxWidth(width);
// mLoadImg.setMaxHeight(hight);
// ImageLoader.getDefault().load(DownloadActivity.this, R.drawable.manage_notask, mLoadImg);
mLoadingLayout.setVisibility(View.VISIBLE);
} else {
mLoadingLayout.setVisibility(View.GONE);
}
break;
case UPDATE_RADID_BTTON_INDEX:
if (mUpdateAppListAdapter.getItemCount() == 0) {
// int width = (int) getResources().getDimension(R.dimen.managepage_noupdate_Width);
// ;
// int hight = (int) getResources().getDimension(R.dimen.managepage_notask_Hight);
// ;
// mLoadImg.setMaxWidth(width);
// mLoadImg.setMaxHeight(hight);
// ImageLoader.getDefault().load(DownloadActivity.this, R.drawable.manage_noupdate, mLoadImg);
mManage_load_tv.setText("没有更新");
mLoadingLayout.setVisibility(View.VISIBLE);
} else {
mLoadingLayout.setVisibility(View.GONE);
}
break;
case ABOUT_RADID_BTTON_INDEX:
mLoadingLayout.setVisibility(View.GONE);
break;
case Configure.SUCCESS:
Bundle data = msg.getData();
String httTag = data.getString("httpTag");
if (httTag.equals(Configure.RANKING_TYPE_UPDATE)) {
if (msg.obj != null) {
List<AppContentInfo> list = (List<AppContentInfo>) msg.obj;
if (!list.isEmpty()) {
mLoadingLayout.setVisibility(View.GONE);
updateAllList.addAll(list);
mUpdateAppListAdapter.setDatas(updateAllList);
mUpdateRadioButton.setText("可更新(" + list.size() + ")");
} else {
mUpdateRadioButton.setText("可更新(0)");
}
}
}
break;
default:
break;
}
}
};
private RecycleGridLayoutManager mLayoutManager;
protected void initParameter() {
setContentView(R.layout.manage_page_layout);
sound = new Sound(DownloadActivity.this);
mExecutorService = Executors.newCachedThreadPool();
downloadReceiver = new DownloadReceiver();
/* 注册广播 */
IntentFilter mScreenOnFilter = new IntentFilter();
mScreenOnFilter.addAction(Utils.DOWNLOAD_SERVICE_ACTION);
mScreenOnFilter.addAction(Utils.DOWNLOAD_ALLSERVICE_ACTION);
mScreenOnFilter.addAction(Utils.DOWNLOAD_NEWSERVICE_ACTION);
mScreenOnFilter.addAction(Utils.ACTION_PACKAGE_REPLACED);
mScreenOnFilter.addAction(Utils.ACTION_PACKAGE_REMOVED);
mScreenOnFilter.addAction(Utils.ACTION_PACKAGE_ADDED);
registerReceiver(downloadReceiver, mScreenOnFilter);
}
protected void initViews() {
reLayout1 = (RelativeLayout) findViewById(R.id.manage_rLayout1);
reLayout2 = (RelativeLayout) findViewById(R.id.manage_rLayout2);
reLayout3 = (RelativeLayout) findViewById(R.id.manage_rLayout3);
mDownloadListView = (RecyclerView) findViewById(R.id.download_manage_listview);
mUninstallListView = (RecyclerView) findViewById(R.id.uninstall_manage_listview);
mAppupdateListView = (RecyclerView) findViewById(R.id.appupdate_manage_listview);
mManageRadioGroup = (RadioGroup) findViewById(R.id.manage_radio_group);
mManageRadioGroup.setOnCheckedChangeListener(this);
mDownloadRadioButton = findViewById(R.id.manage_download_tab);
mUpdateRadioButton = findViewById(R.id.manage_update_tab);
mUninstallRadioButton = findViewById(R.id.manage_uninstall_tab);
// mAboutRadioButton = findViewById(R.id.manage_about_tab);
mLoadingLayout = (RelativeLayout) findViewById(R.id.manage_linearlayout);
mLoadImg = (ImageView) findViewById(R.id.manage_load_img);
mManage_load_tv = (TextView) findViewById(R.id.manage_load_tv);
findViewById(R.id.iv_back).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
mTv_version_code = (TextView) findViewById(R.id.tv_version_code);
mTv_version_code.setText("版本号:" + AppUtils.getAppVersionName() + "");
mTv_version_code.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String registrationID = JPushInterface.getRegistrationID(DownloadActivity.this);
Log.e("mjsheng", registrationID + "------------------------");
// ToastUtils.showLong("registrationID::" + registrationID);
}
});
manage_about_tab = findViewById(R.id.manage_about_tab);
manage_about_tab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(DownloadActivity.this, AboutActivity.class));
}
});
reLayout1.setVisibility(View.GONE);
reLayout2.setVisibility(View.GONE);
mDownloadRadioButton.setChecked(true);
mExecutorService.execute(this);
}
@Override
public void onDestroy() {
super.onDestroy();
// 注销广播接收
if (downloadReceiver != null) {
unregisterReceiver(downloadReceiver);
}
}
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// sound.playSoundEffect();
RadioButton button = (RadioButton) findViewById(checkedId);
// button.setTextColor(getResources().getColor(R.color.main_color));
if (checkedId == R.id.manage_download_tab) {
index = DOWNLOAD_RADID_BTTON_INDEX;
} else if (checkedId == R.id.manage_uninstall_tab) {
index = UNINSTALL_RADID_BTTON_INDEX;
} else if (checkedId == R.id.manage_update_tab) {
index = UPDATE_RADID_BTTON_INDEX;
}
// else if (checkedId == R.id.manage_about_tab) {
// index = ABOUT_RADID_BTTON_INDEX;
// }
showContentList(index);
if (LastCheckedId != null && LastCheckedId != checkedId) {
RadioButton radioButton = (RadioButton) findViewById(LastCheckedId);
// radioButton.setBackgroundColor(Color.TRANSPARENT);
// radioButton.setTextColor(getResources().getColor(R.color.textColor));
}
LastCheckedId = checkedId;
}
private void initUpdateAppDatas() {
List<AppUpdateInfo> upadteApps = AppsManagerUtils.getUpadteApps(this);
String update = new Gson().toJson(upadteApps);
OkGo.post(Configure.HTTP_TAG_APPBAOMING)
.params("baoming", java.net.URLEncoder.encode(update))
.tag(this)
.cacheKey(Configure.HTTP_TAG_APPBAOMING + java.net.URLEncoder.encode(update))
.cacheMode(CacheMode.NO_CACHE)
.execute(new JsonCallback<LzyResponse<List<AppContentInfo>>>() {
@Override
public void onSuccess(LzyResponse<List<AppContentInfo>> listLzyResponse, Call call, Response response) {
Message msg = new Message();
msg.what = Configure.SUCCESS;
Bundle bundle = new Bundle();
bundle.putString("httpTag", Configure.RANKING_TYPE_UPDATE);
msg.obj = listLzyResponse.data;
msg.setData(bundle);
mHandler.sendMessage(msg);
}
@Override
public void onError(Call call, Response response, Exception e) {
super.onError(call, response, e);
mUpdateRadioButton.setText("可更新(0)");
}
});
}
private void showContentList(int index) {
if (index == DOWNLOAD_RADID_BTTON_INDEX) {
mDownloadListView.setVisibility(View.VISIBLE);
reLayout1.setVisibility(View.GONE);
reLayout2.setVisibility(View.GONE);
reLayout3.setVisibility(View.GONE);
mDownloadListView.smoothScrollToPosition(0);
mHandler.sendEmptyMessage(DOWNLOAD_RADID_BTTON_INDEX);
} else if (index == UNINSTALL_RADID_BTTON_INDEX) {
mDownloadListView.setVisibility(View.GONE);
reLayout2.setVisibility(View.GONE);
reLayout1.setVisibility(View.VISIBLE);
reLayout3.setVisibility(View.GONE);
mUninstallListView.smoothScrollToPosition(0);
mHandler.sendEmptyMessage(UNINSTALL_RADID_BTTON_INDEX);
} else if (index == UPDATE_RADID_BTTON_INDEX) {
mDownloadListView.setVisibility(View.GONE);
reLayout1.setVisibility(View.GONE);
reLayout2.setVisibility(View.VISIBLE);
reLayout3.setVisibility(View.GONE);
mAppupdateListView.smoothScrollToPosition(0);
mHandler.sendEmptyMessage(UPDATE_RADID_BTTON_INDEX);
}
// else if (index == ABOUT_RADID_BTTON_INDEX) {
// mDownloadListView.setVisibility(View.GONE);
// reLayout1.setVisibility(View.GONE);
// reLayout2.setVisibility(View.GONE);
// reLayout3.setVisibility(View.VISIBLE);
// mHandler.sendEmptyMessage(ABOUT_RADID_BTTON_INDEX);
//
// }
}
@Override
public void run() {
int orientation = getResources().getConfiguration().orientation;
mDownloadListAdapter = new DownloadListAdapter(this, new DownloadListAdapter.setItemSizeListener() {
@Override
public void setItemSize(int size) {
mDownloadRadioButton.setText("新任务(" + size + ")");
if (index == DOWNLOAD_RADID_BTTON_INDEX) {
mHandler.sendEmptyMessage(DOWNLOAD_RADID_BTTON_INDEX);
}
}
});
switch (orientation) {
case Configuration.ORIENTATION_PORTRAIT:
mManager = new RecycleGridLayoutManager(this, 1);
break;
case Configuration.ORIENTATION_LANDSCAPE:
mManager = new RecycleGridLayoutManager(this, 2);
break;
}
mManager.setOrientation(GridLayoutManager.VERTICAL);
mManager.setSmoothScrollbarEnabled(true);
mDownloadListView.setLayoutManager(mManager);
mDownloadListView.setNestedScrollingEnabled(false);
mDownloadListView.addItemDecoration(new SpacesItemDecoration(getResources().getDimensionPixelSize(R.dimen.PX5x), getResources().getDimensionPixelSize(R.dimen.PX5x),
getResources().getDimensionPixelSize(R.dimen.PX10x), getResources().getDimensionPixelSize(R.dimen.PX10x)));
((DefaultItemAnimator) mDownloadListView.getItemAnimator()).setSupportsChangeAnimations(false);
runOnUiThread(new Runnable() {
@Override
public void run() {
mDownloadListView.setAdapter(mDownloadListAdapter);
}
});
mUninstallListAdapter = new UninstallListAdapter(this, new UninstallListAdapter.setItemSizeListener() {
@Override
public void setItemSize(int size) {
mUninstallRadioButton.setText("已安装(" + uninstallAllList.size() + ")");
if (index == UNINSTALL_RADID_BTTON_INDEX) {
mHandler.sendEmptyMessage(UNINSTALL_RADID_BTTON_INDEX);
}
}
});
switch (orientation) {
case Configuration.ORIENTATION_PORTRAIT:
mLayoutManager = new RecycleGridLayoutManager(this, 1);
break;
case Configuration.ORIENTATION_LANDSCAPE:
mLayoutManager = new RecycleGridLayoutManager(this, 3);
break;
}
mLayoutManager.setOrientation(GridLayoutManager.VERTICAL);
mLayoutManager.setSmoothScrollbarEnabled(true);
mUninstallListView.setLayoutManager(mLayoutManager);
mUninstallListView.setNestedScrollingEnabled(false);
mUninstallListView.addItemDecoration(new SpacesItemDecoration(getResources().getDimensionPixelSize(R.dimen.PX5x), getResources().getDimensionPixelSize(R.dimen.PX5x),
getResources().getDimensionPixelSize(R.dimen.PX10x), getResources().getDimensionPixelSize(R.dimen.PX10x)));
((DefaultItemAnimator) mUninstallListView.getItemAnimator()).setSupportsChangeAnimations(false);
runOnUiThread(new Runnable() {
@Override
public void run() {
mUninstallListView.setAdapter(mUninstallListAdapter);
}
});
mUpdateAppListAdapter = new AppUpdateListAdapter(this, new AppUpdateListAdapter.setItemSizeListener() {
@Override
public void setItemSize(int size) {
mUpdateRadioButton.setText("可更新(" + updateAllList.size() + ")");
if (index == UNINSTALL_RADID_BTTON_INDEX) {
mHandler.sendEmptyMessage(UPDATE_RADID_BTTON_INDEX);
}
}
});
switch (orientation) {
case Configuration.ORIENTATION_PORTRAIT:
mGridLayoutManager = new RecycleGridLayoutManager(this, 1);
break;
case Configuration.ORIENTATION_LANDSCAPE:
mGridLayoutManager = new RecycleGridLayoutManager(this, 3);
break;
}
mGridLayoutManager.setOrientation(GridLayoutManager.VERTICAL);
mGridLayoutManager.setSmoothScrollbarEnabled(true);
mAppupdateListView.setLayoutManager(mGridLayoutManager);
mAppupdateListView.setNestedScrollingEnabled(false);
mAppupdateListView.addItemDecoration(new SpacesItemDecoration(getResources().getDimensionPixelSize(R.dimen.PX5x), getResources().getDimensionPixelSize(R.dimen.PX5x),
getResources().getDimensionPixelSize(R.dimen.PX10x), getResources().getDimensionPixelSize(R.dimen.PX10x)));
((DefaultItemAnimator) mAppupdateListView.getItemAnimator()).setSupportsChangeAnimations(false);
runOnUiThread(new Runnable() {
@Override
public void run() {
mAppupdateListView.setAdapter(mUpdateAppListAdapter);
}
});
mUninstallListView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
switch (newState) {
case RecyclerView.SCROLL_STATE_DRAGGING:
case RecyclerView.SCROLL_STATE_SETTLING:
// 当ListView处于滑动状态时停止加载图片保证操作界面流畅
Glide.with(DownloadActivity.this).pauseRequests();
break;
case RecyclerView.SCROLL_STATE_IDLE:
// 当ListView处于静止状态时继续加载图片
Glide.with(DownloadActivity.this).resumeRequests();
break;
}
}
});
mUninstallListView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
switch (newState) {
case RecyclerView.SCROLL_STATE_DRAGGING:
case RecyclerView.SCROLL_STATE_SETTLING:
// 当ListView处于滑动状态时停止加载图片保证操作界面流畅
Glide.with(DownloadActivity.this).pauseRequests();
break;
case RecyclerView.SCROLL_STATE_IDLE:
// 当ListView处于静止状态时继续加载图片
Glide.with(DownloadActivity.this).resumeRequests();
break;
}
}
});
Intent allIntent = new Intent();
allIntent.setAction(Utils.DOWNLOAD_ALLTASK_ACTION);
sendBroadcast(allIntent);
uninstallAllList = AppsManagerUtils.getUserApps(this);
if (uninstallAllList != null && !uninstallAllList.isEmpty()) {
if (mUninstallListAdapter != null) {
mUninstallListView.post(new Runnable() {
@Override
public void run() {
mUninstallListAdapter.setDatas(uninstallAllList);
mUninstallRadioButton.setText("已安装(" + uninstallAllList.size() + ")");
}
});
}
}
initUpdateAppDatas();
}
private void getUpdateAppDatas(String packageName) {
List<AppUpdateInfo> upadteApps = new ArrayList<>();
upadteApps.add(AppsManagerUtils.getUpAppsByPackageName(this, packageName));
String update = new Gson().toJson(upadteApps);
OkGo.post(Configure.HTTP_TAG_APPBAOMING)
.params("baoming", java.net.URLEncoder.encode(update))
.tag(this)
.cacheKey(Configure.HTTP_TAG_APPBAOMING + java.net.URLEncoder.encode(update))
.cacheMode(CacheMode.NO_CACHE)
.execute(new JsonCallback<LzyResponse<List<AppContentInfo>>>() {
@Override
public void onSuccess(LzyResponse<List<AppContentInfo>> listLzyResponse, Call call, Response response) {
List<AppContentInfo> infoList = listLzyResponse.data;
if (!infoList.isEmpty() && infoList.get(0) != null) {
updateAllList.addAll(infoList);
mUpdateAppListAdapter.addDatas(infoList.get(0));
}
}
@Override
public void onError(Call call, Response response, Exception e) {
super.onError(call, response, e);
}
});
}
public class DownloadReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Utils.DOWNLOAD_SERVICE_ACTION.equals(intent.getAction())) {
AppDownloadInfo downloadInfo = (AppDownloadInfo) intent.getSerializableExtra("DownloadInfo");
if (downloadInfo == null)
return;
if (downloadInfo.getState() == 10) {
mDownloadListAdapter.removeItem(downloadInfo);
if (updateAllList != null) {
Iterator<AppContentInfo> it = updateAllList.iterator();
int number = -1;
while (it.hasNext()) {
number++;
AppContentInfo value = it.next();
if (downloadInfo.getPackageName().equals(value.getApp_baoming())) {
it.remove();
}
}
}
} else {
mDownloadListAdapter.updateProgress(downloadInfo);
}
int position = -1;
for (int i = 0; i < mDownloadListAdapter.allTask.size(); i++) {
if (downloadInfo.getUrl().equals(mDownloadListAdapter.allTask.get(i).getUrl())) {
position = i;
}
}
if (position != -1) {
mDownloadListAdapter.allTask.set(position, downloadInfo);
}
if (position == 0) {
mDownloadListAdapter.notifyItemChanged(0);
}
mUpdateAppListAdapter.updateProgress(downloadInfo); //更新进度
} else if (Utils.DOWNLOAD_ALLSERVICE_ACTION.equals(intent.getAction())) {
List<AppDownloadInfo> list = (List<AppDownloadInfo>) intent.getSerializableExtra("allTask");
mDownloadListAdapter.setDatas(list);
} else if (Utils.DOWNLOAD_NEWSERVICE_ACTION.equals(intent.getAction())) {
AppDownloadInfo downloadInfo = (AppDownloadInfo) intent.getSerializableExtra("addTask");
mDownloadListAdapter.addDatas(downloadInfo);
} else if (Utils.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {
String packageName = intent.getStringExtra("packageName");
Log.e("fht", "安装成功" + packageName);
mDownloadListAdapter.removeItem(packageName);
SaveListUtils.getDownLoadList().remove(packageName);//移除下载列表
LocalAppInfo info = AppsManagerUtils.getAppsByPackageName(DownloadActivity.this, packageName);
if (uninstallAllList != null) {
uninstallAllList.add(info);
}
mUninstallListAdapter.addDatas(info);
getUpdateAppDatas(packageName);
} else if (Utils.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
String packageName = intent.getStringExtra("packageName");
Log.e("aaaaa", "卸载成功" + packageName);
if (uninstallAllList != null) {
Iterator<LocalAppInfo> it = uninstallAllList.iterator();
int number = -1;
while (it.hasNext()) {
number++;
LocalAppInfo value = it.next();
if (packageName.equals(value.getPackageName())) {
it.remove();
}
}
}
mUninstallListAdapter.removeItem(packageName);
if (updateAllList != null) {
Iterator<AppContentInfo> it = updateAllList.iterator();
int number = -1;
while (it.hasNext()) {
number++;
AppContentInfo value = it.next();
if (packageName.equals(value.getApp_baoming())) {
it.remove();
mUpdateAppListAdapter.removeUpItem(packageName);
}
}
}
} else if (Utils.ACTION_PACKAGE_REPLACED.equals(intent.getAction())) {
String packageName = intent.getStringExtra("packageName");
Log.e("aaaaa", "替换成功" + packageName);
if (uninstallAllList != null) {
int position = -1;
for (int i = 0; i < mUninstallListAdapter.mDataList.size(); i++) {
if (packageName.equals(mUninstallListAdapter.mDataList.get(i).getPackageName())) {
position = i;
}
}
if (position != -1) {
LocalAppInfo info = AppsManagerUtils.getAppsByPackageName(DownloadActivity.this, packageName);
mUninstallListAdapter.notifyItem(position, info);
uninstallAllList.set(position, info);
}
}
getUpdateAppDatas(packageName);
}
}
}
}

View File

@@ -0,0 +1,218 @@
package com.mjsheng.myappstore.activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
import com.blankj.utilcode.util.LogUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheMode;
import com.mjsheng.myappstore.R;
import com.mjsheng.myappstore.adapter.SearchHistoryAdapter;
import com.mjsheng.myappstore.base.BaseActivity;
import com.mjsheng.myappstore.bean.AppData;
import com.mjsheng.myappstore.bean.AppDateInfo;
import com.mjsheng.myappstore.bean.JsonCallback;
import com.mjsheng.myappstore.bean.LzyResponse;
import com.mjsheng.myappstore.bean.SearchBean;
import com.mjsheng.myappstore.comm.CommonDatas;
import com.mjsheng.myappstore.utils.Configure;
import com.mjsheng.myappstore.utils.MySQLData;
import com.mjsheng.myappstore.utils.Utils;
import com.mjsheng.myappstore.widget.Sound;
import java.util.ArrayList;
import java.util.List;
import okhttp3.Call;
import okhttp3.Response;
import okhttp3.internal.Util;
public class SearchActivity extends BaseActivity implements View.OnClickListener, AdapterView.OnItemClickListener {
private EditText mSearchEditText;
private ListView mListView;
private SearchHistoryAdapter adapter;
private Sound sound;
private Handler mHandler = new Handler() {
@SuppressWarnings("unchecked")
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
Bundle data = msg.getData();
switch (msg.what) {
case Configure.SUCCESS:
if (data != null) {
String httTag = data.getString("httpTag");
if (TextUtils.isEmpty(httTag)) {
Utils.showToast(SearchActivity.this,"没有搜索到相关内容!");
return;
}
if (null == msg.obj)
return;
if (httTag.equals(Configure.HTTP_TAG_SEARCH)) {
ArrayList<AppDateInfo> serachList = (ArrayList<AppDateInfo>) msg.obj;
if (serachList != null && !serachList.isEmpty()) {
showSearchResultPageActivity(serachList);
} else {
Utils.showToast(SearchActivity.this,"没有搜索到相关内容!");
}
}
}
break;
}
}
};
private void showSearchResultPageActivity(ArrayList<AppDateInfo> serachList) {
LogUtils.e(serachList);
Intent intent = new Intent(SearchActivity.this, SubjectMoreActivity.class);
Bundle bundle = new Bundle();
bundle.putSerializable("AppDateInfo", serachList);
bundle.putString("title", "search_result");
intent.putExtras(bundle);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
sound = new Sound(this);
initView();
}
private void initView() {
mSearchEditText = (EditText) findViewById(R.id.search_edit);
findViewById(R.id.search_btn).setOnClickListener(this);
mListView = (ListView) findViewById(R.id.search_ListView);
adapter = new SearchHistoryAdapter(this);
mListView.setOnItemClickListener(this);
mListView.setAdapter(adapter);
findViewById(R.id.iv_back).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
initData();
}
private void initData() {
adapter.histories = AppData.getSearchData(this);
adapter.notifyDataSetChanged();
}
@Override
public void onClick(View v) {
sound.playSoundEffect();
switch (v.getId()) {
case R.id.search_btn:
Utils.CloseKeyBoard(this);
doSearch();
break;
}
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String value = (String) adapter.getItem(position);
mSearchEditText.setText(value);
doSearch();
}
private void doSearch() {
if (mSearchEditText != null
&& !TextUtils.isEmpty(mSearchEditText.getText())) {
doPost(mSearchEditText.getText().toString());
for (int i = 0; i < adapter.histories.size(); i++){
SearchBean info = adapter.histories.get(i);
if (info.getCategory().equals(mSearchEditText.getText().toString())){
adapter. histories.remove(info);
}
}
SearchBean bean = new SearchBean();
bean.setCategory(mSearchEditText.getText().toString());
bean.setSearch_time((int) System.currentTimeMillis());
AppData.upSearchData(this, mSearchEditText.getText().toString(), (int) System.currentTimeMillis());
adapter.histories.add(0,bean);
adapter.notifyDataSetChanged();
}
}
public void doPost(String keyWord) {
OkGo.post(Configure.HTTP_TAG_SEARCH_URL)
.tag(this)
.params("sn", Utils.getSerial())
.params("key", Configure.HTTP_KEY)
.params("page", "1")
.params("keywords", keyWord)
.cacheKey(Configure.HTTP_TAG_SEARCH_URL)
.cacheMode(CacheMode.NO_CACHE)
.execute(new JsonCallback<LzyResponse<List<AppDateInfo>>>() {
@Override
public void onSuccess(LzyResponse<List<AppDateInfo>> listLzyResponse, Call call, Response response) {
Message msg = new Message();
msg.what = Configure.SUCCESS;
Bundle bundle = new Bundle();
bundle.putString("httpTag", Configure.HTTP_TAG_SEARCH);
msg.obj = listLzyResponse.data;
msg.setData(bundle);
mHandler.sendMessage(msg);
}
@Override
public void onError(Call call, Response response, Exception e) {
super.onError(call, response, e);
if (response.code() != 200){
Utils.showToast(SearchActivity.this, "网络连接不稳定,请稍后重试!");
}
}
});
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
View v = getCurrentFocus();
if (Utils.isShouldHideInput(v, ev)) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
}
return super.dispatchTouchEvent(ev);
}
// 必不可少否则所有的组件都不会有TouchEvent了
if (getWindow().superDispatchTouchEvent(ev)) {
return true;
}
return onTouchEvent(ev);
}
@Override
public void finish() {
super.finish();
overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
}
}

View File

@@ -0,0 +1,98 @@
package com.mjsheng.myappstore.activity;
import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.mjsheng.myappstore.R;
import com.mjsheng.myappstore.base.BaseActivity;
import com.mjsheng.myappstore.comm.CommonDatas;
import com.mjsheng.myappstore.utils.MySQLData;
import com.mjsheng.myappstore.view.ToggleButton;
import com.mjsheng.myappstore.widget.Sound;
/**
* Created by chris on 2015/12/4.
*/
public class SettingActivity extends BaseActivity implements View.OnClickListener {
private boolean selector = false;
private boolean mIsPasswordLock;
private ImageView toBackImg;
private TextView statementTv;
private ToggleButton toggleBtn;
private Sound sound;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setting);
sound = new Sound(this);
initView();
}
private void initView() {
toBackImg = (ImageView) findViewById(R.id.iv_selecter_back);
statementTv = (TextView) findViewById(R.id.tv_statement);
statementTv.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线
statementTv.getPaint().setAntiAlias(true);//抗锯齿
mIsPasswordLock = MySQLData.GetBooleanData(SettingActivity.this, CommonDatas.SP_PASSWORD_LOCK);
toggleBtn = (ToggleButton) findViewById(R.id.iv_setting);
toggleBtn.setOnToggleChanged(new ToggleButton.OnToggleChanged() {
@Override
public void onToggle(boolean on) {
if (selector == false) {
selector = true;
} else {
selector = false;
}
}
});
if (mIsPasswordLock) {
selector = true;
toggleBtn.setToggleOn();
} else {
selector = false;
toggleBtn.setToggleOff();
}
toBackImg.setOnClickListener(this);
statementTv.setOnClickListener(this);
}
@Override
public void onClick(View v) {
sound.playSoundEffect();
switch (v.getId()) {
case R.id.tv_statement:
Intent intent = new Intent();
intent.setClass(this, StatementActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
break;
case R.id.iv_selecter_back:
finish();
break;
}
}
@Override
protected void onDestroy() {
super.onDestroy();
MySQLData.SetBooleanData(SettingActivity.this, CommonDatas.SP_PASSWORD_LOCK, selector);
}
@Override
public void finish() {
super.finish();
overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
}
}

View File

@@ -0,0 +1,40 @@
package com.mjsheng.myappstore.activity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import com.mjsheng.myappstore.R;
import com.mjsheng.myappstore.base.BaseActivity;
import com.mjsheng.myappstore.widget.Sound;
/**
* Created by chris on 2015/12/9.
*/
public class StatementActivity extends BaseActivity {
private WebView webView;
private Sound sound;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_statement);
sound = new Sound(this);
webView = (WebView) findViewById(R.id.web);
webView.loadUrl("file:///android_asset/description.html");
findViewById(R.id.iv_statement_back).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sound.playSoundEffect();
finish();
}
});
}
@Override
public void finish() {
super.finish();
overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
}
}

View File

@@ -0,0 +1,516 @@
package com.mjsheng.myappstore.activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.blankj.utilcode.util.LogUtils;
import com.bumptech.glide.Glide;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheMode;
import com.mjsheng.myappstore.R;
import com.mjsheng.myappstore.adapter.SubjectMoreAdapter;
import com.mjsheng.myappstore.base.BaseFragmentActivity;
import com.mjsheng.myappstore.bean.AppDateInfo;
import com.mjsheng.myappstore.bean.JsonCallback;
import com.mjsheng.myappstore.bean.LzyResponse;
import com.mjsheng.myappstore.callback.MyItemClickListener;
import com.mjsheng.myappstore.dialog.AppDetailDialog;
import com.mjsheng.myappstore.listener.AutoLoadListener;
import com.mjsheng.myappstore.network.Network;
import com.mjsheng.myappstore.network.api.AppLimitApi;
import com.mjsheng.myappstore.utils.Configure;
import com.mjsheng.myappstore.utils.SpacesItemDecoration;
import com.mjsheng.myappstore.utils.Utils;
import com.mjsheng.myappstore.view.RecycleGridLayoutManager;
import com.mjsheng.myappstore.view.VaryViewHelper;
import com.mjsheng.myappstore.widget.Sound;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.Call;
import okhttp3.Response;
import okhttp3.ResponseBody;
import rx.Observable;
import rx.functions.Action1;
public class SubjectMoreActivity extends BaseFragmentActivity implements View.OnClickListener, Runnable {
private String title, url, httpmethod;
private TextView titleImgView;
private ImageView mBackBtn;
private List<AppDateInfo> mList = new ArrayList<>();
private List<AppDateInfo> allList = new ArrayList<>();
private RecyclerView mRecycleView;
private SubjectMoreAdapter mAdapter;
private TextView numberTV;
private VaryViewHelper mVaryViewHelper;
private Sound sound;
private ExecutorService mExecutorService;
private List<AppDateInfo> pageList = new ArrayList<>();
private int page = 1;
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
Bundle data = msg.getData();
switch (msg.what) {
case Configure.SUCCESS:
String httTag = data.getString("httpTag");
if (httTag.equals(Configure.RANKING_TYPE_MOREAPP)) {
if (msg.obj != null) {
List<AppDateInfo> contentList = (List<AppDateInfo>) msg.obj;
Log.e("mjsheng", "contentList===" + contentList.size());
if (contentList.size() <= 0 || contentList == null) {
// Utils.showToast(SubjectMoreActivity.this, "没有数据!");
if (page == 1) {
mVaryViewHelper.showEmptyView();
numberTV.setText("0款应用");
}
return;
}
if (contentList.size() >= 8 && !title.equals("all_apps")) {
pageList.addAll(contentList.subList(0, 8));
} else {
pageList.addAll(contentList);
}
Log.e("mjsheng", "pageList===" + pageList.size());
setList(pageList);
}
break;
}
}
}
};
private String id;
private RecycleGridLayoutManager mLayoutManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_subject_more);
sound = new Sound(this);
Bundle bundle = this.getIntent().getExtras();
title = bundle.getString("title");
url = bundle.getString("URL");
id = bundle.getString("id");
Log.e("mjsheng", "rul----------" + url);
httpmethod = bundle.getString("HTTP");
mList = (List<AppDateInfo>) bundle.getSerializable("AppDateInfo");
mExecutorService = Executors.newCachedThreadPool();
numberTV = (TextView) findViewById(R.id.subject_number_tv);
if (title.equals("all_apps")) {
numberTV.setVisibility(View.VISIBLE);
} else numberTV.setVisibility(View.GONE);
findViewById(R.id.iv_back).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
mVaryViewHelper = new VaryViewHelper.Builder()
.setContent(this)
.setDataView(findViewById(R.id.subject_refreshLayout))//放数据的父布局逻辑处理在该Activity中处理
.setLoadingView(LayoutInflater.from(this).inflate(R.layout.layout_loadingview, null))//加载页,无实际逻辑处理
.setEmptyView(LayoutInflater.from(this).inflate(R.layout.layout_emptyview, null))//空页面,无实际逻辑处理
.setErrorView(LayoutInflater.from(this).inflate(R.layout.layout_errorview, null))//错误页面
.setRefreshListener(new SubjectMoreActivity.ErrorClickListener())//错误页点击刷新实现
.build();
mVaryViewHelper.showLoadingView();
initView();
mExecutorService.execute(this);
}
private void initView() {
int orientation = getResources().getConfiguration().orientation;
mRecycleView = (RecyclerView) findViewById(R.id.subject_recycleView);
// AutoLoadListener autoLoadListener = new AutoLoadListener(mCallBack);
// mRecycleView.addOnScrollListener(autoLoadListener);
switch (orientation) {
case Configuration.ORIENTATION_PORTRAIT:
mLayoutManager = new RecycleGridLayoutManager(this, 1);
break;
case Configuration.ORIENTATION_LANDSCAPE:
mLayoutManager = new RecycleGridLayoutManager(this, 3);
break;
}
mLayoutManager.setOrientation(GridLayoutManager.VERTICAL);
mLayoutManager.setSmoothScrollbarEnabled(true);
mRecycleView.setLayoutManager(mLayoutManager);
// mRecycleView.setNestedScrollingEnabled(false);
mRecycleView.addItemDecoration(new SpacesItemDecoration(getResources().getDimensionPixelSize(R.dimen.PX5x), getResources().getDimensionPixelSize(R.dimen.PX5x),
getResources().getDimensionPixelSize(R.dimen.PX5x), getResources().getDimensionPixelSize(R.dimen.PX5x)));
((DefaultItemAnimator) mRecycleView.getItemAnimator()).setSupportsChangeAnimations(false);
titleImgView = (TextView) findViewById(R.id.tv_subject_img);
if (title.equals("new_more")) {
titleImgView.setText("最新上架");
} else if (title.equals("recommend_more")) {
titleImgView.setText("热门推荐");
} else if (title.equals("top_special")) {
titleImgView.setText("专题推荐");
} else if (title.equals("top_brand")) {
titleImgView.setText("品牌推荐");
} else if (title.equals("search_result")) {
titleImgView.setText("搜索应用");
} else if (title.equals("all_apps")) {
titleImgView.setText("全部应用");
} else {
titleImgView.setText(title);
}
// mBackBtn = (ImageView) findViewById(R.id.iv_subject_back);
// mBackBtn.setOnClickListener(this);
mAdapter = new SubjectMoreAdapter(SubjectMoreActivity.this, allList, new MyItemClickListener() {
@Override
public void onItemClick(View view, int postion) {
sound.playSoundEffect();
AppDateInfo info = mAdapter.getData(postion);
if (info != null) {
getAppDetail(info.getApp_baoming());
}
}
});
}
AutoLoadListener.AutoLoadCallBack mCallBack = new AutoLoadListener.AutoLoadCallBack() {
@Override
public void execute() {
if (title.equals("new_more") || title.equals("recommend_more")) {
httpPostMethodHomePage(++page);
} else {
httpPostMethod(++page);
}
Log.e("mjsheng", "nextpage");
}
@Override
public void stopLoad() {
Glide.with(SubjectMoreActivity.this).pauseRequests();
}
@Override
public void startLoad() {
Glide.with(SubjectMoreActivity.this).resumeRequests();
}
};
@Override
public void run() {
if (mList != null && !mList.isEmpty()) {
setList(mList);
} else {
loadDatas();
}
}
private void setList(final List<AppDateInfo> mList) {
if (mList != null && !mList.isEmpty()) {
allList.clear();
allList.addAll(mList);
if (mAdapter != null) {
mRecycleView.setAdapter(mAdapter);
mAdapter.setmDatas(allList);
numberTV.setText(allList.size() + "款应用");
mVaryViewHelper.showDataView();
}
} else {
mVaryViewHelper.showEmptyView();
numberTV.setText("0款应用");
}
// runOnUiThread(new Runnable() {
// @Override
// public void run() {
// mRecycleView.setAdapter(mAdapter);
// if (allList != null && !allList.isEmpty()) {
// mVaryViewHelper.showDataView();
// } else {
// mVaryViewHelper.showEmptyView();
// numberTV.setText("0款应用");
// }
// }
// });
// mRecycleView.addOnScrollListener(new RecyclerView.OnScrollListener() {
// @Override
// public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
// switch (newState) {
// case RecyclerView.SCROLL_STATE_DRAGGING:
// case RecyclerView.SCROLL_STATE_SETTLING:
// // 当ListView处于滑动状态时停止加载图片保证操作界面流畅
// Glide.with(SubjectMoreActivity.this).pauseRequests();
// Log.e("msjheng","------------SCROLL_STATE_SETTLING");
// break;
// case RecyclerView.SCROLL_STATE_IDLE:
// // 当ListView处于静止状态时继续加载图片
// Glide.with(SubjectMoreActivity.this).resumeRequests();
// Log.e("msjheng","------------SCROLL_STATE_IDLE");
// break;
// }
// }
// });
}
private void loadDatas() {
// if (httpmethod == null || httpmethod.equals("")) {
// httpGetMethod();
// } else {
// httpPostMethod();
// }
if (title.equals("new_more") || title.equals("recommend_more")) {
httpPostMethodHomePage(page);
} else {
httpPostMethod(page);
}
lazyLoading();
}
private void httpPostMethod(int page) {
OkGo.post(url)
.tag(this)
.params("key", Configure.HTTP_KEY)
.params("sn", Utils.getSerial())
.params("page", page)
.params("id", id)
.cacheKey(url + id)
.cacheMode(CacheMode.REQUEST_FAILED_READ_CACHE)
.execute(new JsonCallback<LzyResponse<List<AppDateInfo>>>() {
@Override
public void onSuccess(LzyResponse<List<AppDateInfo>> listLzyResponse, Call call, Response response) {
Message msg = new Message();
msg.what = Configure.SUCCESS;
Bundle bundle = new Bundle();
bundle.putString("httpTag", Configure.RANKING_TYPE_MOREAPP);
msg.obj = listLzyResponse.data;
msg.setData(bundle);
mHandler.sendMessage(msg);
}
@Override
public void onCacheSuccess(LzyResponse<List<AppDateInfo>> listLzyResponse, Call call) {
onSuccess(listLzyResponse, call, null);
if (!Utils.isIntent(SubjectMoreActivity.this)) {
Utils.showToast(SubjectMoreActivity.this, "网络连接不稳定,请稍后重试!");
}
}
});
}
private void httpPostMethodHomePage(int page) {
//不需要按页数
OkGo.post(url)
.tag(this)
.params("key", Configure.HTTP_KEY)
.params("sn", Utils.getSerial())
// .params("page", page)
.cacheKey(url)
.cacheMode(CacheMode.REQUEST_FAILED_READ_CACHE)
.execute(new JsonCallback<LzyResponse<List<AppDateInfo>>>() {
@Override
public void onSuccess(LzyResponse<List<AppDateInfo>> listLzyResponse, Call call, Response response) {
Message msg = new Message();
msg.what = Configure.SUCCESS;
Bundle bundle = new Bundle();
bundle.putString("httpTag", Configure.RANKING_TYPE_MOREAPP);
msg.obj = listLzyResponse.data;
msg.setData(bundle);
mHandler.sendMessage(msg);
}
@Override
public void onCacheSuccess(LzyResponse<List<AppDateInfo>> listLzyResponse, Call call) {
onSuccess(listLzyResponse, call, null);
if (!Utils.isIntent(SubjectMoreActivity.this)) {
Utils.showToast(SubjectMoreActivity.this, "网络连接不稳定,请稍后重试!");
}
}
});
}
private void lazyLoading() {
Observable.timer(2000, TimeUnit.MILLISECONDS)
.observeOn(rx.android.schedulers.AndroidSchedulers.mainThread())
.subscribe(new Action1<Long>() {
@Override
public void call(Long aLong) {
getAppLimitApi();
}
});
}
private void getAppLimitApi() {
AppLimitApi appLimitApi = Network.getAppLimitApi();
appLimitApi.getAppLimitApi(Configure.HTTP_KEY, Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<ResponseBody>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(ResponseBody responseBody) {
try {
String responString = responseBody.string();
Log.e("mjhseng", responString);
JSONObject jsonObject = new JSONObject(responString);
Integer code = jsonObject.optInt("code");
switch (code) {
case 200:
JSONObject data = jsonObject.getJSONObject("data");
String result = data.optString("result");
writeAppPackageList(result);
break;
default:
Log.e("mjhseng", "getAppLimitApi---code is -200");
break;
}
} catch (Exception e) {
Log.e("mjhseng", "getAppLimitApi---woring----" + e.getMessage());
e.printStackTrace();
}
}
@Override
public void onError(Throwable e) {
Log.e("mjsheng", "getAppLimitApi=onError:");
}
@Override
public void onComplete() {
}
});
}
private void writeAppPackageList(String result) {
if (!TextUtils.isEmpty(result)) {
LogUtils.e(result);
Settings.System.putString(getContentResolver(), "qch_app_forbid", result);
} else {
Log.e("mjsheng", "writeAppPackageList is null:");
}
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.iv_subject_back:
sound.playSoundEffect();
finish();
break;
default:
break;
}
}
public void getAppDetail(String appBaoming) {
String detailTitle = new String();
if (title.equals("new_more")) {
detailTitle = "最新上架";
} else if (title.equals("recommend_more")) {
detailTitle = "热门推荐";
} else if (title.equals("top_special")) {
detailTitle = "应用专题";
} else if (title.equals("top_brand")) {
detailTitle = "应用品牌";
} else if (title.equals("search_result")) {
detailTitle = "搜索应用";
} else if (title.equals("all_apps")) {
detailTitle = "全部应用";
} else {
detailTitle = title;
}
Intent intent = new Intent(this, AppDetailDialog.class);
intent.putExtra("title", detailTitle);
intent.putExtra("appBaoming", appBaoming);
startActivity(intent);
}
@Override
protected void onDestroy() {
super.onDestroy();
if (mAdapter != null) {
mAdapter.UnregisterReceiver();
}
}
@Override
public void finish() {
super.finish();
if (mAdapter != null) {
mAdapter.UnregisterReceiver();
}
overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
}
private class ErrorClickListener implements View.OnClickListener {
@Override
public void onClick(View v) {
sound.playSoundEffect();
switch (v.getId()) {
case R.id.iv_errorview_layout:
if (url != null && !url.isEmpty()) {
loadDatas();
}
break;
case R.id.iv_emptyview_layout:
if (url != null && !url.isEmpty()) {
loadDatas();
}
break;
}
}
}
}