issue #209 closed

parent cc8d8aec
......@@ -11,7 +11,6 @@ import android.util.Log;
import com.yottacode.pictogram.R;
import com.yottacode.pictogram.tools.Img;
import com.yottacode.pictogram.tools.PCBcontext;
import org.json.JSONException;
......@@ -37,7 +36,7 @@ import java.util.Vector;
*/
public class Device extends SQLiteOpenHelper {
private static final String LOG_TAG = SQLiteOpenHelper.class.getCanonicalName();
private static final String LOG_TAG = Device.class.getCanonicalName();
Context context;
public static final String PREFS_NAME = "MyPrefsFile";
......
......@@ -2,7 +2,6 @@ package com.yottacode.pictogram.dao;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
......@@ -270,7 +269,7 @@ public class PCBDBHelper extends SQLiteOpenHelper {
values.put("translation",picto.get_translation());
values.put("attributes",picto.get_json_attrs());
db.insert("collection_detail", null, values);
Log.i(LOG_TAG,"Picto added:"+picto.get_translation());
Log.i(LOG_TAG,"Picto added:"+picto.get_translation()+" id:"+picto.get_id()+" stupicto_id:"+picto.get_stupicto_id()+" scene:"+PCBcontext.getPcbdb().getCurrentUser().get_active_scene());
//db.close(); <--no es necesario cerrar la bbdd https://groups.google.com/forum/#!msg/android-developers/NwDRpHUXt0U/jIam4Q8-cqQJ
}
......@@ -287,6 +286,9 @@ public class PCBDBHelper extends SQLiteOpenHelper {
new String[]{ Integer.toString(this.currentUser.get_id_stu()),
Integer.toString(picto_id),
Integer.toString(this.currentUser.get_active_scene())});
Log.i(LOG_TAG,"Local picto delete. Stu id:"+Integer.toString(this.currentUser.get_id_stu())+
"Picto id:"+Integer.toString(picto_id)+
"Scene id:"+Integer.toString(this.currentUser.get_active_scene()));
//db.close(); <--no es necesario cerrar la bbdd https://groups.google.com/forum/#!msg/android-developers/NwDRpHUXt0U/jIam4Q8-cqQJ
}
......@@ -306,7 +308,7 @@ public class PCBDBHelper extends SQLiteOpenHelper {
int updates=db.update("collection",values, "id_stu=? AND id_picto=? AND id_scene=?", new String[] {Integer.toString(id_stu),
Integer.toString(picto_id),
Integer.toString(id_scene)});
Log.i(this.getClass().getCanonicalName(),"Modify "+updates+" Picto, id. "+picto_id+" attributes="+attrs);//+ "::"+ Arrays.toString(Thread.currentThread().getStackTrace()));
Log.i(this.getClass().getCanonicalName(),"Modify "+updates+" Picto, id. "+picto_id+" scene id:"+id_scene+" Attributes="+attrs);//+ "::"+ Arrays.toString(Thread.currentThread().getStackTrace()));
//db.close(); <--no es necesario cerrar la bbdd https://groups.google.com/forum/#!msg/android-developers/NwDRpHUXt0U/jIam4Q8-cqQJ
}
......
......@@ -30,9 +30,11 @@ import java.util.concurrent.ExecutionException;
public class PictoUploader {
private static final String LOG_TAG = PictoUploader.class.getName();
Picto picto=null;
int local_picto_id;
public PictoUploader(Picto picto) {
this.picto=picto;
this.local_picto_id=local_picto_id;
}
private boolean uploadImg( Img img) throws UnsupportedEncodingException {
......@@ -143,7 +145,7 @@ public class PictoUploader {
/**
* if a picto was included from the PCB, the translation is uploaded to the server
*/
private void uploadAttributes(int id_picto, final iPictoUploaderListener listener) {
private void uploadAttributes(int id_picto) {
Hashtable<String, String> params = new Hashtable<String, String>(4);
try {
......@@ -158,13 +160,13 @@ public class PictoUploader {
json_attrs.put(Picto.JSON_ATTTRS.CATEGORY, picto.NO_CATEGORY)
.put(Picto.JSON_ATTTRS.FREE_COLUMN, picto.getFreeColumn())
.put(Picto.JSON_ATTTRS.FREE_ROW, picto.getFreeRow());
//params.put("json", new JSONObject().put("attributes",json_attrs).put("id_scene",PCBcontext.getPcbdb().getActiveSceneForStudent(PCBcontext.getPcbdb().getCurrentUser().get_id_stu())).toString());
params.put("id_scene", String.valueOf(PCBcontext.getPcbdb().getCurrentUser().get_active_scene()));
params.put("json", new JSONObject().put("attributes",json_attrs).put("id_scene",PCBcontext.getPcbdb().getCurrentUser().get_active_scene()).toString());
} catch (JSONException e) {
e.printStackTrace();
Log.e(LOG_TAG, " Error: " + e.getLocalizedMessage());
}
PictoUploader.this.picto.set_local_status(false);
PCBcontext.getRestapiWrapper().ask(PCBcontext.getPcbdb().getCurrentUser().get_restapi_operation_stu() + "/picto/"+id_picto, params, "post", true, new RestapiWrapper.iRestapiListener() {
@Override
public void preExecute() {
......@@ -185,26 +187,24 @@ public class PictoUploader {
try {
if(uploadSound(file)) {
Log.i(LOG_TAG,"Sound uploaded");
listener.success(true,result.toString());
success(result);
}else {
Log.e(LOG_TAG, "Uploading sound error");
listener.success(false,result.toString());
fail(result.toString());
}
} catch (UnsupportedEncodingException e) {
Log.e(LOG_TAG, "Uploading sound error");
listener.success(false,e.toString());
fail(e.toString());
}
}
else
listener.success(true,result.toString());
success(result);
}
@Override
public void error(RestapiWrapper.HTTPException e) {
Log.e(LOG_TAG, " Error uploading attributes: " + e.getLocalizedMessage());
PictoUploader.this.picto.set_local_status(true);
listener.success(false,e.getLocalizedMessage());
fail(e.getLocalizedMessage());
}
});
}
......@@ -212,7 +212,7 @@ public class PictoUploader {
/**
* if the a picto was included from the PCB, the translation is uploaded to the server
*/
private void uploadTranslation( int id_picto, final iPictoUploaderListener listener) {
private void uploadTranslation( int id_picto) {
final Hashtable<String, String> params = new Hashtable<String, String>(3);
params.put("picto", Integer.toString(id_picto));
......@@ -232,13 +232,13 @@ public class PictoUploader {
@Override
public void result(JSONObject result) {
Log.i(LOG_TAG, "Uploaded translation result: " + result.toString());
uploadAttributes(picto.get_id(), listener);
uploadAttributes(picto.get_id());
}
@Override
public void error(RestapiWrapper.HTTPException e) {
Log.e(LOG_TAG, "Error uploading translation: " + e.getLocalizedMessage()+" Picto:"+params.get("picto")+" Lang:"+params.get("lang")+" Text:"+params.get("text"));
listener.success(false,e.getMessage());
fail(e.getMessage());
}
});
}
......@@ -304,11 +304,10 @@ public class PictoUploader {
final int local_id = this.picto.get_id();
final boolean imgUpload_success = uploadImg(this.picto);
Log.i(LOG_TAG, "Local Picto to be uploaded:" + this.picto.get_translation() + "(localID:" + local_id + ", new remoteID:" + this.picto.get_id() );
iPictoUploaderListener listener = new PictoUploaderListener(local_id);
if (imgUpload_success)
uploadTranslation(picto.get_id(), listener);
uploadTranslation(picto.get_id());
else
listener.success(false, PCBcontext.getContext().getResources().getString(R.string.upload_error) + ":" + PictoUploader.this.picto.get_translation());
fail(PCBcontext.getContext().getResources().getString(R.string.upload_error) + ":" + PictoUploader.this.picto.get_translation());
}
......@@ -354,39 +353,34 @@ public class PictoUploader {
}
/**
* Created by Fernando on 28/07/2016.
*/
public static interface iPictoUploaderListener {
void success(boolean success, String s);
}
public class PictoUploaderListener implements iPictoUploaderListener {
int local_img_id;
PictoUploaderListener(int local_img_id) {
this.local_img_id=local_img_id;
private void fail(String msg) {
int errmsg =
msg.contains("Error: Picto already in student's vocabulary")
? R.string.upload_duplicated
: R.string.upload_error;
Toast.makeText(
PCBcontext.getActivityContext(),
(PCBcontext.getActivityContext().getResources().getString(errmsg)
+":"+PictoUploader.this.picto.get_translation()), Toast.LENGTH_LONG).show();
}
@Override
public void success(boolean success, String msg) {
if (!success) {
int errmsg =
msg.contains("Error: Picto already in student's vocabulary")
? R.string.upload_duplicated
: R.string.upload_error;
Toast.makeText(
PCBcontext.getActivityContext(),
(PCBcontext.getActivityContext().getResources().getString(errmsg)
+":"+PictoUploader.this.picto.get_translation()), Toast.LENGTH_LONG).show();
}
else {
PCBcontext.getVocabulary().addPicto(picto);
PCBcontext.getRoom().emit(new VocabularyAction(VocabularyAction.ADD, PictoUploader.this.picto));
Toast.makeText(
PCBcontext.getActivityContext(),
(PCBcontext.getActivityContext().getResources().getString(R.string.upload_ok)
+":"+PictoUploader.this.picto.get_translation()), Toast.LENGTH_LONG).show();
private void success(JSONObject server_response) {
int stupicto_id= 0;
try {
stupicto_id = server_response.getInt("id");
picto.set_stupicto_id(stupicto_id);
PCBcontext.getVocabulary().addPicto(picto);
PCBcontext.getPcbdb().deletePicto(this.local_picto_id);
PCBcontext.getPcbdb().savePicto(PictoUploader.this.picto);
PCBcontext.getRoom().emit(new VocabularyAction(VocabularyAction.ADD, this.picto));
Toast.makeText(
PCBcontext.getActivityContext(),
(PCBcontext.getActivityContext().getResources().getString(R.string.upload_ok)
+":"+this.picto.get_translation()), Toast.LENGTH_LONG).show();
} catch (JSONException e) {
fail(e.getMessage());
Log.e(LOG_TAG,"Error uploading picto when getting json from server:"+e.getMessage()+":"+server_response.toString());
}
}
};
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment