Commit d485d773 by Arturo Montejo Ráez

Merge branch 'develop' of http://scm.ujaen.es/softuno/pictogram into develop

parents 5e5ea216 68db9ecf
...@@ -244,7 +244,7 @@ public class RestapiWrapper { ...@@ -244,7 +244,7 @@ public class RestapiWrapper {
@Override @Override
protected HttpAsyncTaskParams doInBackground(HttpAsyncTaskParams... params) { protected HttpAsyncTaskParams doInBackground(HttpAsyncTaskParams... params) {
try { try {
Log.i(com.yottacode.net.RestapiWrapper.class.getName(), " asking to the server for " + params[0].url+" params:"+params[0].url_params +" "+params[0].json_params); Log.i(com.yottacode.net.RestapiWrapper.class.getName(), " asking to the server for " + params[0].url+" params:"+params[0].url_params +" JSON?"+params[0].json_params);
JSONObject jresult = params[0].request_method.equalsIgnoreCase("GET") JSONObject jresult = params[0].request_method.equalsIgnoreCase("GET")
? GET(params[0].url, params[0].url_params) ? GET(params[0].url, params[0].url_params)
: POST(params[0].url, params[0].request_method, params[0].url_params, params[0].json_params); : POST(params[0].url, params[0].request_method, params[0].url_params, params[0].json_params);
......
...@@ -158,12 +158,12 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -158,12 +158,12 @@ public class Vocabulary implements Iterable<Picto> {
final String jexpression_text = "text"; final String jexpression_text = "text";
Picto[] pictos = new Picto[result.length()]; Picto[] pictos = new Picto[result.length()];
JSONObject picto = null; JSONObject picto = null, expression = null, attributes = null;
try { try {
for (int i = 0; i < result.length(); i++) { for (int i = 0; i < result.length(); i++) {
picto = result.getJSONObject(i).getJSONObject(jpicto); picto = result.getJSONObject(i).getJSONObject(jpicto);
JSONObject expression = result.getJSONObject(i).getJSONObject(jexpression); expression = result.getJSONObject(i).getJSONObject(jexpression);
JSONObject attributes = result.getJSONObject(i).getJSONObject(jattributes); attributes = result.getJSONObject(i).getJSONObject(jattributes);
pictos[i] = new Picto(picto.getInt(jid), pictos[i] = new Picto(picto.getInt(jid),
picto.getString(juri), picto.getString(juri),
expression.getString(jexpression_text), expression.getString(jexpression_text),
...@@ -173,8 +173,11 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -173,8 +173,11 @@ public class Vocabulary implements Iterable<Picto> {
PCBcontext.getPcbdb().setStudentVocabulary(Vocabulary.this); PCBcontext.getPcbdb().setStudentVocabulary(Vocabulary.this);
Log.i(this.getClass().getName(), " Pictos downloaded: " + result.length()); Log.i(this.getClass().getName(), " Pictos downloaded: " + result.length());
} catch (JSONException e) { } catch (JSONException e) {
Log.e(this.getClass().getName(), " Picto json error from server: " + picto.toString()); StackTraceElement traces[] = e.getStackTrace();
this.error(e); for (StackTraceElement s: traces)
Log.e(s.getClassName()+"."+s.getFileName()+"."+s.getLineNumber(),s.toString());
Log.e(this.getClass().getName(), " Picto json error from server: " + picto.toString()+" expression:"+expression.toString()+" attributes:"+attributes.toString());
this.error(e);
} }
} }
} }
......
...@@ -748,8 +748,13 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -748,8 +748,13 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
Intent intent = new Intent(Intent.ACTION_PICK); Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*"); intent.setType("image/*");
this.getIntent().putExtra(Picto.JSON_ATTTRS.ROW, row); if (PCBcontext.getPcbdb().getCurrentUser().has_categories()) {
this.getIntent().putExtra(Picto.JSON_ATTTRS.COLUMN, col); this.getIntent().putExtra(Picto.JSON_ATTTRS.ROW, row);
this.getIntent().putExtra(Picto.JSON_ATTTRS.COLUMN, col);
} else {
this.getIntent().putExtra(Picto.JSON_ATTTRS.FREE_ROW, row);
this.getIntent().putExtra(Picto.JSON_ATTTRS.FREE_COLUMN, col);
}
startActivityForResult(intent, SELECT_PICTURE); startActivityForResult(intent, SELECT_PICTURE);
...@@ -773,7 +778,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -773,7 +778,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
int cat = PictogramActivity.this.currentCategory != null || !PCBcontext.getPcbdb().getCurrentUser().has_categories() int cat = PictogramActivity.this.currentCategory != null
? PictogramActivity.this.currentCategory.get_id() ? PictogramActivity.this.currentCategory.get_id()
: Picto.NO_CATEGORY; : Picto.NO_CATEGORY;
PCBcontext.getVocabulary().saveLocalPicto( PCBcontext.getVocabulary().saveLocalPicto(
......
...@@ -98,11 +98,17 @@ public class PictoUploader { ...@@ -98,11 +98,17 @@ public class PictoUploader {
private void uploadAttributes(int id_picto) { private void uploadAttributes(int id_picto) {
Hashtable<String, String> params = new Hashtable<String, String>(4); Hashtable<String, String> params = new Hashtable<String, String>(4);
try { try {
params.put("json", new JSONObject().put("attributes", JSONObject json_attrs =new JSONObject().put("status",picto.get_status());
(new JSONObject().put("id_cat", picto.get_category()) if (PCBcontext.getPcbdb().getCurrentUser().has_categories())
.put("coord_x", picto.get_column()) json_attrs.put(Picto.JSON_ATTTRS.CATEGORY, picto.get_category())
.put("coord_y", picto.get_row()) .put(Picto.JSON_ATTTRS.COLUMN, picto.get_column())
.put("status",picto.get_status()))).toString()); .put(Picto.JSON_ATTTRS.ROW, picto.get_row());
else
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).toString());
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
Log.e(this.getClass().getCanonicalName(), " Error: " + e.getLocalizedMessage()); Log.e(this.getClass().getCanonicalName(), " Error: " + e.getLocalizedMessage());
...@@ -135,7 +141,7 @@ public class PictoUploader { ...@@ -135,7 +141,7 @@ public class PictoUploader {
*/ */
private void uploadTranslation( int id_picto) { private void uploadTranslation( int id_picto) {
Hashtable<String, String> params = new Hashtable<String, String>(3); final Hashtable<String, String> params = new Hashtable<String, String>(3);
params.put("picto", Integer.toString(id_picto)); params.put("picto", Integer.toString(id_picto));
params.put("lang", PCBcontext.getPcbdb().getCurrentUser().get_lang_stu()); params.put("lang", PCBcontext.getPcbdb().getCurrentUser().get_lang_stu());
params.put("text", picto.get_translation()); params.put("text", picto.get_translation());
...@@ -155,7 +161,7 @@ public class PictoUploader { ...@@ -155,7 +161,7 @@ public class PictoUploader {
@Override @Override
public void error(Exception e) { public void error(Exception e) {
Log.e(this.getClass().getCanonicalName(), "Error: " + e.getLocalizedMessage()); Log.e(this.getClass().getCanonicalName(), "Error uploading translation: " + e.getLocalizedMessage()+" Picto:"+params.get("picto")+" Lang:"+params.get("lang")+" Text:"+params.get("text"));
PCBcontext.getVocabulary().addPicto(picto, ImgDownloader.tsource.local); PCBcontext.getVocabulary().addPicto(picto, ImgDownloader.tsource.local);
} }
}); });
......
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