1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
try{
JSONArray jArray1 = new JSONArray(result1);
livreBdd.open();
for(int i=0;i<jArray1.length();i++){
JSONObject json_data1 = jArray1.getJSONObject(i);
String cate= json_data1.get("Souche").toString();
fichier= json_data1.get("Fichier_livre").toString();
image= json_data1.get("Image_livre").toString();
// Toast.makeText(getApplicationContext(),TITRE, Toast.LENGTH_SHORT).show();
//verification qu'il n'est pas inscrit
int test5= gr.toLowerCase().indexOf(cate.toLowerCase());
File f = new File("mnt/sdcard/pdf1/"+fichier);
if (f.exists()){
//Toast.makeText(getApplicationContext(),"fichier existe", Toast.LENGTH_SHORT).show();
}
else {
// Toast.makeText(getApplicationContext(),"fichier n'existe pas,telechargement en cour", Toast.LENGTH_SHORT).show();
//view1 = (ProgressBar) findViewById(R.id.progress);
// dl = new Download(this,"http://earthobservatory.nasa.gov/images/imagerecords/45000/45618/ISS024-E-012425_lrg.jpg","vetrimoxin.jpg",this);
//dl1=new Download(this,"http://www.spectrum.tn/"+image,image,this);
// dl.start();
// final LivresBDD livreBdd = new LivresBDD(this);
if( test5>-1){
Calendar now = Calendar.getInstance();
int day = now.get(Calendar.DATE);
int month = now.get(Calendar.MONTH);
int year = now.get(Calendar.YEAR);
int hour = now.get(Calendar.HOUR);
int minute = now.get(Calendar.MINUTE);
String date=""+day;
String date1=""+month;
String date2=""+year;
String date3=""+hour;
String date4=""+minute;
final LivreMain livre1 = new LivreMain(json_data1.get("Nom_auteur").toString(),json_data1.get("Version").toString(),json_data1.get("Categorie").toString(),json_data1.get("Animaux").toString(),json_data1.get("annee_pub").toString(),json_data1.get("Fichier_livre").toString(),json_data1.get("Image_livre").toString(),json_data1.get("Mots_clefs").toString(),cate,json_data1.get("Class").toString(),date2+date1+date+date3+date4);
//On insère le livre que l'on vient de créer
livreBdd.insertLivre(livre1);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String url = "****URL****"+fichier;
String url1 = "*****URL*****"+image;
new DownloadFileAsync().execute(url);
new DownloadFileAsyncImage().execute(url1);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
// startDownload();
/* String url = "http://www.spectrum.tn/vetrimoxin.pdf";
new DownloadFileAsync().execute(url);*/
}
livreBdd.close();
}catch(JSONException e){
Log.e("log_tag", "Error parsing data " + e.toString());
} |
Partager