pda/zhuike/.svn/pristine/5a/5a7fe3b7d393e704e83daaed2b7...

180 lines
5.2 KiB
Plaintext
Raw Normal View History

2024-02-06 22:23:29 +08:00
package com.novelbook.android;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.novelbook.android.db.DownloadTask;
import com.novelbook.android.netutils.NetUtil;
import com.novelbook.android.service.ServiceDownload;
import com.novelbook.android.utils.CommonUtil;
import com.novelbook.android.utils.Constants;
import com.novelbook.android.utils.FileUtils;
import com.novelbook.android.utils.Fileutil;
import org.litepal.LitePal;
import butterknife.BindView;
import butterknife.OnClick;
import static com.novelbook.android.utils.Constants.lstNt;
public class ActivitySetup extends Activity_base {
static final String TAG = ActivitySetup.class.getSimpleName();
@BindView(R.id.tvCache)
TextView tvCache;
@BindView(R.id.tvVersion)
TextView tvVersion;
String mVersion ="";
String mCacheSize ="";
@Override
public int getLayoutRes() {
return R.layout.activity_setup;
}
@Override
protected void initViews() {
new Thread() {
@Override
public void run() {
super.run();
mVersion =CommonUtil.getVersion(ActivitySetup.this);
mCacheSize =FileUtils.getFormatedCachedSize() ;
handler.sendEmptyMessage(1);
}
}.start() ;
}
@Override
protected void setTitle() {
}
@Override
protected void initData() {
}
@Override
public void fillData() {
tvVersion.setText(mVersion);
tvCache.setText(mCacheSize);
if(mCacheSize.equals("0.00B")){
tvCache.setText(R.string.noCache);
}
}
@OnClick({R.id.llAnouncement,R.id.llCache,R.id.llVersion})
void onSetupclick(View view){
switch (view.getId()) {
case R.id.llAnouncement:
Intent intent = new Intent(ActivitySetup.this, ActivityAnounce.class);
startActivity(intent);
break;
case R.id.llCache:
if(mCacheSize.equals("0.00B")){
return;
}
final AlertDialog.Builder normalDialog =
new AlertDialog.Builder(ActivitySetup.this);
normalDialog.setTitle("提示");
normalDialog.setMessage("是否清除所有缓存内容及下载任务?");
normalDialog.setPositiveButton("确定",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(ActivitySetup.this, ServiceDownload.class);
stopService(intent);
FileUtils.clearCache();
LitePal.deleteAll(DownloadTask.class);
mCacheSize="0.00B";
//tvCache.setText(FileUtils.getFormatedCachedSize());
tvCache.setText(R.string.noCache);
}
});
normalDialog.setNegativeButton("取消",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which)
{
}
});
normalDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
}
});
// 显示
normalDialog.show();
break;
case R.id.llVersion:
Constants.serverVersion =-1;
NetUtil.checkUpdate(false);
showProgressDialog(false,"正在检查版本...");
new Thread(){
@Override
public void run() {
Log.d(TAG, "prepare book to load options for search" );
int slept =0;
while( slept <100 && Constants.serverVersion ==-1){
try {
Thread.sleep(100);
slept++;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if( Constants.serverVersion <= Constants.version ){
handler.sendEmptyMessage(MSG_VERSION_LATEST);
}else if(Constants.serverVersion==-1){
handler.sendEmptyMessage(MSG_VERSION_LATEST);
}
handler.sendEmptyMessage(1000);
}
}.start();
break;
}
}
}