From 3c6d37efd1f33965eb97f00bab18491254cfbfa5 Mon Sep 17 00:00:00 2001 From: Schoumi Date: Sun, 6 Nov 2016 20:44:14 +0100 Subject: [PATCH] Fix Downloaded binaries --- .../fr/mobdev/lpcprog/fragment/DeviceFragment.java | 2 +- .../fr/mobdev/lpcprog/fragment/ServersFragment.java | 2 +- .../fr/mobdev/lpcprog/managers/DatabaseManager.java | 10 ++++++---- .../fr/mobdev/lpcprog/managers/NetworkManager.java | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/fr/mobdev/lpcprog/fragment/DeviceFragment.java b/app/src/main/java/fr/mobdev/lpcprog/fragment/DeviceFragment.java index 3e4c708..c1989a6 100644 --- a/app/src/main/java/fr/mobdev/lpcprog/fragment/DeviceFragment.java +++ b/app/src/main/java/fr/mobdev/lpcprog/fragment/DeviceFragment.java @@ -345,7 +345,7 @@ public class DeviceFragment extends Fragment { } }); msg.show(); - List> localServers = DatabaseManager.getInstance(getActivity()).getServers(); + List> localServers = DatabaseManager.getInstance(getActivity()).getServers(getActivity()); servers.addAll(localServers.get(0)); servers.addAll(localServers.get(1)); servers.addAll(localServers.get(2)); diff --git a/app/src/main/java/fr/mobdev/lpcprog/fragment/ServersFragment.java b/app/src/main/java/fr/mobdev/lpcprog/fragment/ServersFragment.java index d83211b..06768be 100644 --- a/app/src/main/java/fr/mobdev/lpcprog/fragment/ServersFragment.java +++ b/app/src/main/java/fr/mobdev/lpcprog/fragment/ServersFragment.java @@ -84,7 +84,7 @@ public class ServersFragment extends Fragment { public void updateServers(View v) { // build the view with server list in database - List> dbServers = DatabaseManager.getInstance(getActivity()).getServers(); + List> dbServers = DatabaseManager.getInstance(getActivity()).getServers(getActivity()); List namesList = new ArrayList<>(); namesList.add(getString(R.string.active_section)); namesList.add(getString(R.string.inactive_section)); diff --git a/app/src/main/java/fr/mobdev/lpcprog/managers/DatabaseManager.java b/app/src/main/java/fr/mobdev/lpcprog/managers/DatabaseManager.java index feada8e..0d16ccc 100644 --- a/app/src/main/java/fr/mobdev/lpcprog/managers/DatabaseManager.java +++ b/app/src/main/java/fr/mobdev/lpcprog/managers/DatabaseManager.java @@ -24,6 +24,7 @@ import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; +import java.io.File; import java.net.URL; import java.util.ArrayList; import java.util.List; @@ -167,7 +168,7 @@ public class DatabaseManager extends SQLiteOpenHelper { getWritableDatabase().delete("servers",where,whereArgs); } - public List> getServers() { + public List> getServers(Context context) { List> list = new ArrayList<>(); List active = new ArrayList<>(); List inactive = new ArrayList<>(); @@ -185,7 +186,7 @@ public class DatabaseManager extends SQLiteOpenHelper { int isActive = cursor.getInt(col++); server.isActive = isActive != 0; server.attempted = cursor.getInt(col); - server.binaries = getBinaries(server.id); + server.binaries = getBinaries(context, server.id); if (server.isActive && server.attempted == 0) active.add(server); else if (server.isActive && server.attempted != 0) @@ -200,7 +201,7 @@ public class DatabaseManager extends SQLiteOpenHelper { return list; } - private List getBinaries(long id) { + private List getBinaries(Context context, long id) { List binaries = new ArrayList<>(); String whereClause = "server_id = ?"; String[] whereArgs = new String[1]; @@ -217,7 +218,8 @@ public class DatabaseManager extends SQLiteOpenHelper { b.version = cursor.getInt(col++); b.path = cursor.getString(col++); b.sha1 = cursor.getString(col); - b.isDownloaded = true; + File file = new File(context.getApplicationInfo().dataDir+"/"+id+"/"+b.path+b.filename); + b.isDownloaded = file.exists(); b.progress = 0; b.isDownloading = false; binaries.add(b); diff --git a/app/src/main/java/fr/mobdev/lpcprog/managers/NetworkManager.java b/app/src/main/java/fr/mobdev/lpcprog/managers/NetworkManager.java index fbc9884..b7a9b3a 100644 --- a/app/src/main/java/fr/mobdev/lpcprog/managers/NetworkManager.java +++ b/app/src/main/java/fr/mobdev/lpcprog/managers/NetworkManager.java @@ -104,7 +104,7 @@ public class NetworkManager { } private void getBinariesList(){ - List> servers = DatabaseManager.getInstance(context).getServers(); + List> servers = DatabaseManager.getInstance(context).getServers(context); List serversAvailable = new ArrayList<>(); for(Server server : servers.get(0)){ serversAvailable.add(server);