From 6194d1c46fa3c0e2ec01de5913638d23ed985d55 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Mon, 7 May 2018 15:22:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=87=E4=BB=BD=EF=BC=8C=E5=87=86=E5=A4=87?= =?UTF-8?q?=E5=9B=9E=E6=BB=9A=E4=B8=BA=E6=97=A0=E6=8F=92=E4=BB=B6=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/caches/build_file_checksums.ser | Bin 906 -> 906 bytes .idea/misc.xml | 2 +- .../jianrmg_v2/basemodel/Network/HttpApi.java | 3 +- .../basemodel/Network/HttpUtils.java | 4 +- .../basemodel/Tools/ActivitysManager.java | 2 + .../jianrmg_v2/basemodel/Tools/ModUtils.java | 312 ++++++++++-------- .../basemodel/services/DownloadService.java | 2 +- .../res/layout/activity_download_list.xml | 5 +- ResModl/src/main/res/layout/item_download.xml | 32 ++ .../src/main/res/layout/item_my_gridview.xml | 5 +- .../Adapters/DownloadItemAdapter.java | 54 +++ .../usermodel/Views/DownloadListActivity.java | 64 +++- build.gradle | 2 +- 13 files changed, 331 insertions(+), 156 deletions(-) create mode 100644 ResModl/src/main/res/layout/item_download.xml create mode 100644 UserModel/src/main/java/com/jianrmg_v2/usermodel/Adapters/DownloadItemAdapter.java diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 8d922115bbf729290ed6d4a2ab54946f68c7b6db..da7a4db26268b730416db8c72ba6c79edfa5b397 100644 GIT binary patch delta 66 zcmV-I0KNZ;2Z{%fmjz=a3>|EdobCk{RdZ!>lQ04tljs2wlZpX8lPm% - + diff --git a/BaseModel/src/main/java/com/yutou/jianrmg_v2/basemodel/Network/HttpApi.java b/BaseModel/src/main/java/com/yutou/jianrmg_v2/basemodel/Network/HttpApi.java index 70f0b37..f4a8bff 100644 --- a/BaseModel/src/main/java/com/yutou/jianrmg_v2/basemodel/Network/HttpApi.java +++ b/BaseModel/src/main/java/com/yutou/jianrmg_v2/basemodel/Network/HttpApi.java @@ -5,11 +5,12 @@ package com.yutou.jianrmg_v2.basemodel.Network; */ public class HttpApi { - // public static final String HOME_URL="http://192.168.31.240:8088/android/"; //zzz_gz wifi + // public static final String HOME_URL="http://192.168.31.240:8088/android/"; //zzz_gz wifi public static final String HOME_URL="http://192.168.137.1:8088/android/"; //笔记本本身WIFI // public static final String HOME_URL="http://game.yutou233.cn/android/"; //服务器 public static final String MOD_ALL="mod/all.do"; + public static final String MOD_MODS="mod/getMods.do"; public static final String MOD_TYPE="mod/getType.do"; public static final String MOD_REMOD="mod/remod.do"; public static final String MOD_USER_LIST="mod/user.do"; diff --git a/BaseModel/src/main/java/com/yutou/jianrmg_v2/basemodel/Network/HttpUtils.java b/BaseModel/src/main/java/com/yutou/jianrmg_v2/basemodel/Network/HttpUtils.java index 61527f5..b5d8766 100644 --- a/BaseModel/src/main/java/com/yutou/jianrmg_v2/basemodel/Network/HttpUtils.java +++ b/BaseModel/src/main/java/com/yutou/jianrmg_v2/basemodel/Network/HttpUtils.java @@ -126,9 +126,9 @@ public class HttpUtils { sum += len; int progress = (int) (sum * 1.0f / total * 100); // 下载中 - while (!downloadFileInerface.downloading(getNameFromUrl(url),progress,total)){ + /* while (!downloadFileInerface.downloading(getNameFromUrl(url),progress,total)){ Thread.sleep(10); - } + }*/ } fos.flush(); diff --git a/BaseModel/src/main/java/com/yutou/jianrmg_v2/basemodel/Tools/ActivitysManager.java b/BaseModel/src/main/java/com/yutou/jianrmg_v2/basemodel/Tools/ActivitysManager.java index 7c908f2..275b9e4 100644 --- a/BaseModel/src/main/java/com/yutou/jianrmg_v2/basemodel/Tools/ActivitysManager.java +++ b/BaseModel/src/main/java/com/yutou/jianrmg_v2/basemodel/Tools/ActivitysManager.java @@ -1,5 +1,6 @@ package com.yutou.jianrmg_v2.basemodel.Tools; +import android.annotation.SuppressLint; import android.app.Activity; import android.app.ActivityManager; import android.content.Context; @@ -78,6 +79,7 @@ public class ActivitysManager { /** * 退出应用程序 */ + @SuppressLint("MissingPermission") public static void AppExit(Context context) { try { finishAllActivity(); diff --git a/BaseModel/src/main/java/com/yutou/jianrmg_v2/basemodel/Tools/ModUtils.java b/BaseModel/src/main/java/com/yutou/jianrmg_v2/basemodel/Tools/ModUtils.java index d998635..ce8d408 100644 --- a/BaseModel/src/main/java/com/yutou/jianrmg_v2/basemodel/Tools/ModUtils.java +++ b/BaseModel/src/main/java/com/yutou/jianrmg_v2/basemodel/Tools/ModUtils.java @@ -14,6 +14,7 @@ import android.widget.Toast; import com.alibaba.fastjson.JSON; import com.kaopiz.kprogresshud.KProgressHUD; +import com.yutou.jianrmg_v2.basemodel.Application; import com.yutou.jianrmg_v2.basemodel.Data.AppData; import com.yutou.jianrmg_v2.basemodel.Data.MGamePackname; import com.yutou.jianrmg_v2.basemodel.Data.TMod; @@ -46,43 +47,50 @@ public class ModUtils { private List modfiles; private KProgressHUD hud; private TMod mod; - public static ModUtils init(Context context){ - if(modUtils==null){ - modUtils=new ModUtils(); + + public static ModUtils init(Context context) { + if (modUtils == null) { + modUtils = new ModUtils(); } modUtils.setContext(context); - return modUtils; + return modUtils; } - private void setContext(Context context){ - this.context=context; - hud=Utils.showLoading(context,"安装中","请稍后"); + + private void setContext(Context context) { + this.context = context; + hud = Utils.showLoading(context, "安装中", "请稍后"); } - private ModUtils(){ - handler=new Handler(); + + private ModUtils() { + handler = new Handler(); } - public void setMod(TMod mod){ - this.mod=mod; + + public void setMod(TMod mod) { + this.mod = mod; getModDownloadInfo(); } - public List getModfiles(){ + + public List getModfiles() { return modfiles; } - public void installMod(TMod mod){ - this.mod=mod; + + public void installMod(TMod mod) { + this.mod = mod; install(); } - private void install(){ - if(modfiles==null){ - Toast.makeText(context,"正在加载数据,请稍后再试",Toast.LENGTH_LONG).show(); + + private void install() { + if (modfiles == null) { + Toast.makeText(context, "正在加载数据,请稍后再试", Toast.LENGTH_LONG).show(); getModDownloadInfo(); return; } - Log.i("安装mod",changeMod(mod,modfiles)+""); - if(!isInstallMod(mod)&&changeMod(mod,modfiles)){ + Log.i("安装mod", (!isInstallMod(mod)) + " " + changeMod(mod, modfiles) + ""); + if (!isInstallMod(mod) && changeMod(mod, modfiles)) { install(mod); - }else{ - if(getModPath(mod).listFiles().length>0&&!changeMod(mod,modfiles)){ - final MaterialDialog dialog=new MaterialDialog(context); + } else { + if (getModPath(mod).listFiles().length > 0 && !changeMod(mod, modfiles)) { + final MaterialDialog dialog = new MaterialDialog(context); dialog.setTitle("mod已损失"); dialog.setMessage("当前mod文件有缺失,是否重新下载?"); dialog.setPositiveButton("确定", new View.OnClickListener() { @@ -99,42 +107,43 @@ public class ModUtils { } }); dialog.show(); - }else { + } else { downloadMod(); } } } - private void install(final TMod mod){ - List clientList=new ArrayList<>(); + + private void install(final TMod mod) { + List clientList = new ArrayList<>(); for (MGamePackname packname : AppData.packnames) { - clientList.add(packname.getZhname()+"("+packname.getPackname()+")"); + clientList.add(packname.getZhname() + "(" + packname.getPackname() + ")"); } - final MaterialDialog dialog=new MaterialDialog(context); + final MaterialDialog dialog = new MaterialDialog(context); dialog.setTitle("选择安装客户端"); - ListView listView=new ListView(context); - listView.setAdapter(new ArrayAdapter(context,android.R.layout.simple_list_item_1,clientList)); + ListView listView = new ListView(context); + listView.setAdapter(new ArrayAdapter(context, android.R.layout.simple_list_item_1, clientList)); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView adapterView, View view, int i, long l) { - MGamePackname packname=AppData.packnames.get(i); + MGamePackname packname = AppData.packnames.get(i); hud.show(); for (TModfile modfile : modfiles) { - File file=getModPath(mod,modfile.getFilename()); - if(packname.getZhname().contains("[ROOT]")){ - backupOrRoot(file,"/data/data/"+packname.getPackname()+modfile.getInstallpathid(),packname.getPackname(),mod); - rootInstall(file,"/data/data/"+packname.getPackname()+modfile.getInstallpathid()); - }else{ + File file = getModPath(mod, modfile.getFilename()); + if (packname.getZhname().contains("[ROOT]")) { + backupOrRoot(file, "/data/data/" + packname.getPackname() + modfile.getInstallpathid(), packname.getPackname(), mod); + rootInstall(file, "/data/data/" + packname.getPackname() + modfile.getInstallpathid()); + } else { } } try { - new File(getModInstallPath(mod)+packname.getPackname()+".lock").createNewFile(); + new File(getModInstallPath(mod) + packname.getPackname() + ".lock").createNewFile(); } catch (IOException e) { e.printStackTrace(); } hud.dismiss(); dialog.dismiss(); - Toast.makeText(context,"安装成功,重启游戏生效",Toast.LENGTH_LONG).show(); + Toast.makeText(context, "安装成功,重启游戏生效", Toast.LENGTH_LONG).show(); } }); dialog.setContentView(listView); @@ -147,48 +156,51 @@ public class ModUtils { dialog.show(); } - private void notRootInstall(File src,String path){ + + private void notRootInstall(File src, String path) { } - private void rootInstall(File src,String path){ - RootUtils root=RootUtils.init(context); - if(RootUtils.su()){ - root.exec("\\cp -f "+src.getAbsolutePath()+" "+path); - root.exec("chmod 777 "+src.getAbsolutePath()+" "+path+src.getName()); - }else { - final MaterialDialog dialog=new MaterialDialog(context); - dialog.setTitle("错误"); - dialog.setMessage("未获取到ROOT权限\n提示:魔改专用端可免ROOT使用魔改,以及更多功能"); - dialog.setPositiveButton("确定", new View.OnClickListener() { - @Override - public void onClick(View view) { - dialog.dismiss(); - } - }); - dialog.setNegativeButton("下载魔改专用客户端", new View.OnClickListener() { - @Override - public void onClick(View view) { - dialog.dismiss(); - } - }); - dialog.show(); - } + + private void rootInstall(File src, String path) { + RootUtils root = RootUtils.init(context); + if (RootUtils.su()) { + root.exec("\\cp -f " + src.getAbsolutePath() + " " + path); + root.exec("chmod 777 " + src.getAbsolutePath() + " " + path + src.getName()); + } else { + final MaterialDialog dialog = new MaterialDialog(context); + dialog.setTitle("错误"); + dialog.setMessage("未获取到ROOT权限\n提示:魔改专用端可免ROOT使用魔改,以及更多功能"); + dialog.setPositiveButton("确定", new View.OnClickListener() { + @Override + public void onClick(View view) { + dialog.dismiss(); + } + }); + dialog.setNegativeButton("下载魔改专用客户端", new View.OnClickListener() { + @Override + public void onClick(View view) { + dialog.dismiss(); + } + }); + dialog.show(); + } } + public void reBackMod(TMod tMod) { - final MaterialDialog dialog=new MaterialDialog(context); - dialog.setTitle("将还原 "+tMod.getTitle()); - final List clientList=getInstallClens(); - ListView listView=new ListView(context); - listView.setAdapter(new ArrayAdapter(context,android.R.layout.simple_list_item_1,clientList)); + final MaterialDialog dialog = new MaterialDialog(context); + dialog.setTitle("将还原 " + tMod.getTitle()); + final List clientList = getInstallClens(); + ListView listView = new ListView(context); + listView.setAdapter(new ArrayAdapter(context, android.R.layout.simple_list_item_1, clientList)); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView adapterView, View view, int i, long l) { - RootUtils root=RootUtils.init(context); + RootUtils root = RootUtils.init(context); for (TModfile modfile : modfiles) { - if(getModPath(mod,"backup/"+clientList.get(i)+"/"+modfile.getFilename()).exists()){ - root.exec("\\cp -f "+getModInstallPath(mod)+"backup/"+clientList.get(i)+"/"+modfile.getFilename()+" "+"/data/data/"+clientList.get(i)+modfile.getInstallpathid()); - }else{ - root.exec("rm -f "+"/data/data/"+clientList.get(i)+modfile.getInstallpathid()+modfile.getFilename()); + if (getModPath(mod, "backup/" + clientList.get(i) + "/" + modfile.getFilename()).exists()) { + root.exec("\\cp -f " + getModInstallPath(mod) + "backup/" + clientList.get(i) + "/" + modfile.getFilename() + " " + "/data/data/" + clientList.get(i) + modfile.getInstallpathid()); + } else { + root.exec("rm -f " + "/data/data/" + clientList.get(i) + modfile.getInstallpathid() + modfile.getFilename()); } } dialog.dismiss(); @@ -198,94 +210,98 @@ public class ModUtils { dialog.setNegativeButton("放弃", new View.OnClickListener() { @Override public void onClick(View view) { - dialog.dismiss();; + dialog.dismiss(); + ; } }); dialog.show(); } - private void backupOrRoot(File srcFile,String srcPath,String backupClient,TMod mod){ + + private void backupOrRoot(File srcFile, String srcPath, String backupClient, TMod mod) { RootUtils root = RootUtils.init(context); - if(RootUtils.su()) { - File backup = getModPath(mod, "backup/"+backupClient); - File file=new File(backup.getAbsolutePath()+"/"+srcFile.getName()); - if(file.exists()){ + if (RootUtils.su()) { + File backup = getModPath(mod, "backup/" + backupClient); + File file = new File(backup.getAbsolutePath() + "/" + srcFile.getName()); + if (file.exists()) { return; } if (!backup.exists()) { - Log.i("获取ROOT","2"); + Log.i("获取ROOT", "2"); backup.mkdirs(); } - root.exec("chmod 777 "+srcPath+srcFile.getName()); - root.exec("\\cp -f"+srcPath+srcFile.getName()+" "+backup+"/"); - }else{ + root.exec("chmod 777 " + srcPath + srcFile.getName()); + root.exec("\\cp -f" + srcPath + srcFile.getName() + " " + backup + "/"); + } else { } } - private void downloadMod(){ - Toast.makeText(context,"开始下载",Toast.LENGTH_LONG).show(); - Intent intent=new Intent(context.getApplicationContext(), DownloadService.class); + + private void downloadMod() { + Toast.makeText(context, "开始下载", Toast.LENGTH_LONG).show(); + Intent intent = new Intent(context.getApplicationContext(), DownloadService.class); intent.setPackage(context.getPackageName()); - boolean isBindService=context.getApplicationContext().bindService(intent, new ServiceConnection() { + boolean isBindService = context.getApplicationContext().bindService(intent, new ServiceConnection() { @Override public void onServiceConnected(ComponentName componentName, IBinder iBinder) { - DownloadService.ServiceBinder binder=(DownloadService.ServiceBinder)iBinder; - DownloadService service=binder.getService(new DownloadInterface() { - @Override - public void getDownloadList(int size) { + DownloadService.ServiceBinder binder = (DownloadService.ServiceBinder) iBinder; + DownloadService service = binder.getService(new DownloadInterface() { + @Override + public void getDownloadList(int size) { - } + } - @Override - public void getDownloadFile(TModfile modfile) { + @Override + public void getDownloadFile(TModfile modfile) { - } + } - @Override - public void getDownloadFileSize(int size) { + @Override + public void getDownloadFileSize(int size) { - } + } - @Override - public void getCurrent(int current) { + @Override + public void getCurrent(int current) { - } + } - @Override - public void over() { + @Override + public void over() { + Utils.toast(context, "下载完成"); + } - } - - @Override - public void start() { - - } - }); - service.start(modfiles); + @Override + public void start() { + Utils.toast(context, "开始下载"); + } + }); + service.start(modfiles); } @Override public void onServiceDisconnected(ComponentName componentName) { - Log.i("下载服务","绑定失败:"+componentName); + Log.i("下载服务", "绑定失败:" + componentName); } - },Context.BIND_AUTO_CREATE); - Log.i("绑定下载:",isBindService+""); + }, Context.BIND_AUTO_CREATE); + Log.i("绑定下载:", isBindService + ""); } - private void getModDownloadInfo(){ - modfiles=null; - try{ - JSONObject json=new JSONObject(); - json.put("mid",mod.getId()); + + private void getModDownloadInfo() { + modfiles = null; + try { + JSONObject json = new JSONObject(); + json.put("mid", mod.getId()); json.put("uid", AppData.user.getId()); HttpUtils.post(HttpApi.HOME_URL + HttpApi.MOD_DOWNLOAD, json, new HttpInterface() { @Override public void httpGetData(String string, int code) { - try{ - JSONObject json=new JSONObject(string); - if(json.getInt("code")==100){ - modfiles= JSON.parseArray(json.getJSONArray("data").toString(),TModfile.class); + try { + JSONObject json = new JSONObject(string); + if (json.getInt("code") == 100) { + modfiles = JSON.parseArray(json.getJSONArray("data").toString(), TModfile.class); } - }catch (Exception e){ + } catch (Exception e) { } } @@ -295,53 +311,59 @@ public class ModUtils { } }); - }catch (Exception e){ + } catch (Exception e) { } } - public static String getModInstallPath(TMod mod){ - return Utils.getSDCardPath()+"/"+mod.getId()+"/"; + public static String getModInstallPath(TMod mod) { + return Utils.getSDCardPath() + "/" + mod.getId() + "/"; } - public static boolean isInstallMod(TMod mod){ - File modPath=new File(Utils.getSDCardPath()+"/"+mod.getId()+"/"); + + public static boolean isInstallMod(TMod mod) { + File modPath = new File(Utils.getSDCardPath() + "/" + mod.getId() + "/"); for (int i = 0; i < modPath.listFiles().length; i++) { - Log.i("检测mod是否安装","位置:"+modPath.listFiles()[i].getAbsolutePath()+" exists:"+modPath.listFiles()[i].exists()+" .lock="+(modPath.listFiles()[i].getName().contains(".lock"))); - if(modPath.listFiles()[i].getName().contains(".lock")){ + Log.i("检测mod是否安装", "位置:" + modPath.listFiles()[i].getAbsolutePath() + " exists:" + modPath.listFiles()[i].exists() + " .lock=" + (modPath.listFiles()[i].getName().contains(".lock"))); + if (modPath.listFiles()[i].getName().contains(".lock")) { return true; } } return false; } - public static boolean changeMod(TMod mod, List modfiles){ - File modPath=new File(Utils.getSDCardPath()+"/"+mod.getId()+"/"); - Log.i("检测mod是否完整","位置:"+Utils.getSDCardPath()+"/"+mod.getId()+"/"+" exists:"+modPath.exists()); + + public static boolean changeMod(TMod mod, List modfiles) { + File modPath = new File(Utils.getSDCardPath() + "/" + mod.getId() + "/"); + Log.i("检测mod是否完整", "位置:" + Utils.getSDCardPath() + "/" + mod.getId() + "/" + " exists:" + modPath.exists()); for (TModfile modfile : modfiles) { - if(!new File(Utils.getSDCardPath()+"/"+mod.getId()+"/"+modfile.getFilename()).exists()){ - return false; - } + if (new File(Utils.getSDCardPath() + "/" + mod.getId() + "/" + modfile.getFilename()).isFile()) + if (!new File(Utils.getSDCardPath() + "/" + mod.getId() + "/" + modfile.getFilename()).exists()) { + Log.i("不完整的", "位置:" + Utils.getSDCardPath() + "/" + mod.getId() + "/" + " exists:" + modPath.exists()); + return false; + } } return true; } - public static File getModPath(TMod mod){ - return getModPath(mod,""); + + public static File getModPath(TMod mod) { + return getModPath(mod, ""); } - public static File getModPath(TMod mod,String name){ - File path=new File(Utils.getSDCardPath()+"/"+mod.getId()+"/"+name); - if(!path.exists()){ + + public static File getModPath(TMod mod, String name) { + File path = new File(Utils.getSDCardPath() + "/" + mod.getId() + "/" + name); + if (!path.exists()) { path.mkdirs(); } - return path; + return path; } public List getInstallClens() { - List installClens=new ArrayList<>(); - File modPath=getModPath(mod); - if(modPath.exists()){ + List installClens = new ArrayList<>(); + File modPath = getModPath(mod); + if (modPath.exists()) { for (int i = 0; i < modPath.listFiles().length; i++) { - if(modPath.listFiles()[i].getName().contains(".lock")){ + if (modPath.listFiles()[i].getName().contains(".lock")) { installClens.add(modPath.listFiles()[i].getName().split("\\.")[0]); } } diff --git a/BaseModel/src/main/java/com/yutou/jianrmg_v2/basemodel/services/DownloadService.java b/BaseModel/src/main/java/com/yutou/jianrmg_v2/basemodel/services/DownloadService.java index ec577e8..c90fb04 100644 --- a/BaseModel/src/main/java/com/yutou/jianrmg_v2/basemodel/services/DownloadService.java +++ b/BaseModel/src/main/java/com/yutou/jianrmg_v2/basemodel/services/DownloadService.java @@ -68,6 +68,7 @@ public class DownloadService extends Service { puase=false; list.addAll(addList); downloadInterface.start(); + startNotification(); download= new Download(this); } @@ -126,7 +127,6 @@ public class DownloadService extends Service { if(!download.isAlive||!download.isAlive()||!download.isInterrupted()) { this.service=service; - service.startNotification(); start(); } } diff --git a/ResModl/src/main/res/layout/activity_download_list.xml b/ResModl/src/main/res/layout/activity_download_list.xml index 3509b84..ea23492 100644 --- a/ResModl/src/main/res/layout/activity_download_list.xml +++ b/ResModl/src/main/res/layout/activity_download_list.xml @@ -2,5 +2,8 @@ - + \ No newline at end of file diff --git a/ResModl/src/main/res/layout/item_download.xml b/ResModl/src/main/res/layout/item_download.xml new file mode 100644 index 0000000..3d4ba3f --- /dev/null +++ b/ResModl/src/main/res/layout/item_download.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/ResModl/src/main/res/layout/item_my_gridview.xml b/ResModl/src/main/res/layout/item_my_gridview.xml index 7355375..cf9e6ce 100644 --- a/ResModl/src/main/res/layout/item_my_gridview.xml +++ b/ResModl/src/main/res/layout/item_my_gridview.xml @@ -1,14 +1,15 @@ + android:layout_height="80dp" + android:layout_marginTop="20dp"> diff --git a/UserModel/src/main/java/com/jianrmg_v2/usermodel/Adapters/DownloadItemAdapter.java b/UserModel/src/main/java/com/jianrmg_v2/usermodel/Adapters/DownloadItemAdapter.java new file mode 100644 index 0000000..4fa5031 --- /dev/null +++ b/UserModel/src/main/java/com/jianrmg_v2/usermodel/Adapters/DownloadItemAdapter.java @@ -0,0 +1,54 @@ +package com.jianrmg_v2.usermodel.Adapters; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.ImageView; +import android.widget.TextView; + +import java.util.List; + +public class DownloadItemAdapter extends BaseAdapter { + private Context context; + private List list; + + public DownloadItemAdapter(Context context, List list) { + this.context = context; + this.list = list; + } + + @Override + public int getCount() { + return list.size(); + } + + @Override + public Object getItem(int i) { + return list.get(i); + } + + @Override + public long getItemId(int i) { + return i; + } + + @Override + public View getView(int i, View view, ViewGroup viewGroup) { + Items items; + if(view==null){ + view= LayoutInflater.from(context).inflate(com.yutou.jianrmg_v2.resmodl.R.layout.item_download,null); + items=new Items(); + + view.setTag(items); + }else{ + items= (Items) view.getTag(); + } + return view; + } + private class Items{ + ImageView icon; + TextView title; + } +} diff --git a/UserModel/src/main/java/com/jianrmg_v2/usermodel/Views/DownloadListActivity.java b/UserModel/src/main/java/com/jianrmg_v2/usermodel/Views/DownloadListActivity.java index 495d8fe..e209147 100644 --- a/UserModel/src/main/java/com/jianrmg_v2/usermodel/Views/DownloadListActivity.java +++ b/UserModel/src/main/java/com/jianrmg_v2/usermodel/Views/DownloadListActivity.java @@ -4,20 +4,80 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.KeyEvent; +import android.view.LayoutInflater; import android.view.MotionEvent; +import android.view.View; import android.widget.LinearLayout; +import android.widget.ListView; +import com.yutou.jianrmg_v2.basemodel.Interfaces.HttpInterface; +import com.yutou.jianrmg_v2.basemodel.Network.HttpApi; +import com.yutou.jianrmg_v2.basemodel.Network.HttpUtils; +import com.yutou.jianrmg_v2.basemodel.Tools.Utils; +import com.yutou.jianrmg_v2.resmodl.R; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.File; import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; import Interfaces.BaseActivityInterface; public class DownloadListActivity implements BaseActivityInterface ,Serializable { private Context context; - private LinearLayout layout; + private View view; + private ListView listView; @Override public void onCreate(Bundle savedInstanceState, LinearLayout layout, Context context, Intent intent) { this.context=context; - this.layout=layout; + this.view= LayoutInflater.from(context).inflate(R.layout.activity_download_list,null); + getDownloadFileList(); + initViews(); + layout.addView(view); + } + private void getDownloadFileList(){ + JSONObject json=new JSONObject(); + File rootPath=new File(Utils.getSDCardPath()); + try{ + JSONArray array=new JSONArray(); + for (File path : rootPath.listFiles()) { + if (path.isDirectory()){ + try { + array.put(Integer.valueOf(path.getName())+""); + }catch (Exception e){} + } + } + json.put("ids",array); + HttpUtils.post(HttpApi.HOME_URL + HttpApi.MOD_MODS, json, new HttpInterface() { + @Override + public void httpGetData(String string, int code) { + try { + JSONObject json=new JSONObject(string); + if(json.getInt("code")!=100){ + return; + } + JSONArray dataList=json.getJSONArray("data"); + + } catch (JSONException e) { + e.printStackTrace(); + } + } + + @Override + public void httpError(Exception e) { + + } + }); + }catch (Exception e){} + return; + } + private void initViews(){ + listView=view.findViewById(R.id.listView); + } @Override diff --git a/build.gradle b/build.gradle index e339c82..dba29f5 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.1' + classpath 'com.android.tools.build:gradle:3.1.2' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0"