issue #946 closed

parent 70bb2d89
...@@ -215,7 +215,6 @@ public class RestapiWrapper { ...@@ -215,7 +215,6 @@ public class RestapiWrapper {
} }
} }
Log.e(this.getClass().getCanonicalName(),"POST-->"+surl+" "+request_method+" j"+json_params+" param"+sparams);
//Send request //Send request
DataOutputStream wr = new DataOutputStream ( DataOutputStream wr = new DataOutputStream (
urlConnection.getOutputStream ()); urlConnection.getOutputStream ());
......
...@@ -2,9 +2,8 @@ package com.yottacode.pictogram.action; ...@@ -2,9 +2,8 @@ package com.yottacode.pictogram.action;
import android.util.Log; import android.util.Log;
import com.yottacode.pictogram.net.websockets.Room;
import com.yottacode.pictogram.dao.Picto; import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.tools.PCBcontext; import com.yottacode.pictogram.net.websockets.Room;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -50,9 +49,7 @@ public abstract class PictoAction extends Action { ...@@ -50,9 +49,7 @@ public abstract class PictoAction extends Action {
public JSONObject get_json_picto() throws JSONException { public JSONObject get_json_picto() throws JSONException {
final String param_id_json="id"; final String param_id_json="id";
final String param_picto="picto"; final String param_picto="picto";
final String param_expression="expression";
final String param_expr_lang="lang";
final String param_expr_text="text";
final String param_attrs="attributes"; final String param_attrs="attributes";
final String param_picto_id="id"; final String param_picto_id="id";
final String param_picto_uri="uri"; final String param_picto_uri="uri";
...@@ -61,11 +58,8 @@ public abstract class PictoAction extends Action { ...@@ -61,11 +58,8 @@ public abstract class PictoAction extends Action {
.put(param_picto_uri, picto.get_url()) .put(param_picto_uri, picto.get_url())
.put(param_picto_cat, picto.get_category()); .put(param_picto_cat, picto.get_category());
JSONObject attributes = new JSONObject(picto.get_json_attrs()); JSONObject attributes = new JSONObject(picto.get_json_attrs());
JSONObject expression = new JSONObject().put(param_expr_lang,PCBcontext.getPcbdb().getCurrentUser().get_lang_stu())
.put(param_expr_text,picto.get_translation());
JSONObject subPicto = new JSONObject().put(param_id_json, 1470) JSONObject subPicto = new JSONObject().put(param_id_json, 1470)
.put(param_picto, subsubPicto) .put(param_picto, subsubPicto)
.put(param_expression,expression)
.put(param_attrs, attributes); .put(param_attrs, attributes);
return subPicto; return subPicto;
} }
......
...@@ -227,7 +227,6 @@ public class PCBDBHelper extends SQLiteOpenHelper { ...@@ -227,7 +227,6 @@ public class PCBDBHelper extends SQLiteOpenHelper {
* @see com.yottacode.pictogram.dao.Picto * @see com.yottacode.pictogram.dao.Picto
*/ */
public void deletePicto(int picto_id) { public void deletePicto(int picto_id) {
int id_stu = this.getCurrentUser().get_id_stu();
SQLiteDatabase db = this.getWritableDatabase(); SQLiteDatabase db = this.getWritableDatabase();
db.delete("collection","id_stu=? AND id_picto=?", db.delete("collection","id_stu=? AND id_picto=?",
......
...@@ -70,8 +70,7 @@ public class Picto extends Img { ...@@ -70,8 +70,7 @@ public class Picto extends Img {
private JSONObject attributes; private JSONObject attributes;
private String translation; private boolean is_mirror=false;
private boolean is_mirror=false;
private boolean highlight_background=false; private boolean highlight_background=false;
public boolean is_mirror() {return is_mirror;} public boolean is_mirror() {return is_mirror;}
...@@ -88,10 +87,9 @@ public class Picto extends Img { ...@@ -88,10 +87,9 @@ public class Picto extends Img {
} catch (JSONException e) { } catch (JSONException e) {
Log.e(LOG_TAG,e.getMessage()); Log.e(LOG_TAG,e.getMessage());
} }
translation=new String(p.get_translation());
} }
public Picto(int id, String url, String translation, int cat, int row, int column, int freeRow, int freeColumn, int stupicto_id) throws JSONException { public Picto(int id, String url, String translation, int cat, int row, int column, int freeRow, int freeColumn, int stupicto_id) throws JSONException {
this(id, url, translation, new JSONObject() this(id, url, new JSONObject()
.put(JSON_ATTTRS.CATEGORY, cat) .put(JSON_ATTTRS.CATEGORY, cat)
.put(JSON_ATTTRS.COLUMN, column) .put(JSON_ATTTRS.COLUMN, column)
.put(JSON_ATTTRS.ROW, row) .put(JSON_ATTTRS.ROW, row)
...@@ -99,16 +97,16 @@ public class Picto extends Img { ...@@ -99,16 +97,16 @@ public class Picto extends Img {
.put(JSON_ATTTRS.FREE_COLUMN, freeColumn) .put(JSON_ATTTRS.FREE_COLUMN, freeColumn)
.put(JSON_ATTTRS.STATUS, JSON_ATTTR_STATUS_VALUES.ENABLED) .put(JSON_ATTTRS.STATUS, JSON_ATTTR_STATUS_VALUES.ENABLED)
.put(JSON_ATTTRS.LEGEND,JSON_ATTTR_LEGEND_VALUES.NONE) .put(JSON_ATTTRS.LEGEND,JSON_ATTTR_LEGEND_VALUES.NONE)
.put(JSON_ATTTRS.STUPICTO_ID,stupicto_id)); .put(JSON_ATTTRS.STUPICTO_ID,stupicto_id)
.put(JSON_ATTTRS.EXPRESSION,translation));
} }
public Picto(int id, String url,String translation, String attributes) throws JSONException { public Picto(int id, String url,String translation, String attributes) throws JSONException {
this(id, url, translation, new JSONObject(attributes)); this(id, url, new JSONObject(attributes).put(JSON_ATTTRS.EXPRESSION,translation));
} }
public Picto(int id, String url,String translation, JSONObject attributes) { public Picto(int id, String url, JSONObject attributes) {
super(id,url,Img.VOCABULARY); super(id,url,Img.VOCABULARY);;
this.translation=translation;
this.attributes = attributes; this.attributes = attributes;
try { try {
if (this.attributes.get(JSON_ATTTRS.CATEGORY)==null) if (this.attributes.get(JSON_ATTTRS.CATEGORY)==null)
...@@ -131,18 +129,6 @@ public class Picto extends Img { ...@@ -131,18 +129,6 @@ public class Picto extends Img {
*/ */
public String get_url() {return this.url;} public String get_url() {return this.url;}
/**
*
* @param newTranslation
*/
public void set_translation(String newTranslation){
this.translation = newTranslation;
try {
this.attributes.put(JSON_ATTTRS.EXPRESSION,newTranslation);
} catch (JSONException e) {
e.printStackTrace();
}
}
/** /**
* *
...@@ -154,10 +140,10 @@ public class Picto extends Img { ...@@ -154,10 +140,10 @@ public class Picto extends Img {
translation=this.attributes.has(JSON_ATTTRS.EXPRESSION) && translation=this.attributes.has(JSON_ATTTRS.EXPRESSION) &&
this.attributes.getString(JSON_ATTTRS.EXPRESSION)!=null && !this.attributes.getString(JSON_ATTTRS.EXPRESSION).equals("null") this.attributes.getString(JSON_ATTTRS.EXPRESSION)!=null && !this.attributes.getString(JSON_ATTTRS.EXPRESSION).equals("null")
? this.attributes.getString(JSON_ATTTRS.EXPRESSION) ? this.attributes.getString(JSON_ATTTRS.EXPRESSION)
: this.translation; : "";
} catch (JSONException e) { } catch (JSONException e) {
translation=this.translation; translation="";
} }
return translation; return translation;
} }
......
...@@ -91,8 +91,14 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -91,8 +91,14 @@ public class Vocabulary implements Iterable<Picto> {
String uri=args.getJSONObject("picto").getString("uri"); String uri=args.getJSONObject("picto").getString("uri");
JSONObject attrs_picto = args.getJSONObject("attributes"); JSONObject attrs_picto = args.getJSONObject("attributes");
attrs_picto.put(Picto.JSON_ATTTRS.STUPICTO_ID,args.getInt("id")); attrs_picto.put(Picto.JSON_ATTTRS.STUPICTO_ID,args.getInt("id"));
String text= attrs_picto.getString("expression"); Picto newPicto=new Picto(picto_id, uri, attrs_picto);
addPicto(new Picto(picto_id, uri, text, attrs_picto),ImgDownloader.tsource.remote); Picto prev_picto=find_picto(newPicto.get_category(), newPicto.get_row(),newPicto.get_column());
if (prev_picto!=null) {
Log.i(LOG_TAG, "Pictogram "+prev_picto.get_translation()+":"+prev_picto.get_id()+" to be replaced by "+newPicto.get_translation()+":"+newPicto.get_id());
removePicto(prev_picto.get_category(), prev_picto.get_id());
}
if (find_picto_index(newPicto.get_category(),newPicto.get_id())==-1) addPicto(newPicto,ImgDownloader.tsource.remote);
} catch (JSONException e) { } catch (JSONException e) {
Log.e(this.getClass().getCanonicalName(), e.getClass().getCanonicalName() + "--" + e); Log.e(this.getClass().getCanonicalName(), e.getClass().getCanonicalName() + "--" + e);
...@@ -171,12 +177,10 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -171,12 +177,10 @@ public class Vocabulary implements Iterable<Picto> {
final String jid = "id"; final String jid = "id";
final String juri = "uri"; final String juri = "uri";
final String jattributes = "attributes"; final String jattributes = "attributes";
final String jexpression = "expression";
Picto[] pictos = new Picto[result.length()]; Picto[] pictos = new Picto[result.length()];
JSONObject picto, attributes ; JSONObject picto, attributes ;
String expression;
JSONObject stupicto=null; JSONObject stupicto=null;
try { try {
for (int i=0; i < result.length(); i++) { for (int i=0; i < result.length(); i++) {
...@@ -184,10 +188,8 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -184,10 +188,8 @@ public class Vocabulary implements Iterable<Picto> {
picto = stupicto.getJSONObject(jpicto); picto = stupicto.getJSONObject(jpicto);
attributes = stupicto.getJSONObject(jattributes); attributes = stupicto.getJSONObject(jattributes);
attributes.put(Picto.JSON_ATTTRS.STUPICTO_ID,stupicto.get(jid)); attributes.put(Picto.JSON_ATTTRS.STUPICTO_ID,stupicto.get(jid));
expression = attributes.getString(jexpression);
pictos[i] = new Picto(picto.getInt(jid), pictos[i] = new Picto(picto.getInt(jid),
picto.getString(juri), picto.getString(juri),
expression,
attributes); attributes);
} }
synchronizeImgs(pictos); synchronizeImgs(pictos);
......
...@@ -317,11 +317,11 @@ public class PictoUploader { ...@@ -317,11 +317,11 @@ public class PictoUploader {
GUITools.show_alert(PCBcontext.getActivityContext(), errmsg, PictoUploader.this.picto.get_translation()); GUITools.show_alert(PCBcontext.getActivityContext(), errmsg, PictoUploader.this.picto.get_translation());
} }
if (elements_uploaded == elements_to_be_uploaded) { if (elements_uploaded == elements_to_be_uploaded) {
PCBcontext.getPcbdb().deletePicto(local_img_id); PCBcontext.getVocabulary().removePicto(picto.get_category(), local_img_id);
PictoUploader.this.picto.delete_bitmap(PCBcontext.getContext()); PictoUploader.this.picto.delete_bitmap(PCBcontext.getContext());
PCBcontext.getVocabulary().addPicto(picto); PCBcontext.getVocabulary().addPicto(picto);
PCBcontext.getRoom().emit(new VocabularyAction(VocabularyAction.ADD, PictoUploader.this.picto)); PCBcontext.getRoom().emit(new VocabularyAction(VocabularyAction.ADD, PictoUploader.this.picto));
GUITools.show_alert(PCBcontext.getContext(), R.string.upload_ok,PictoUploader.this.picto.get_translation()); GUITools.show_alert(PCBcontext.getActivityContext(), R.string.upload_ok,PictoUploader.this.picto.get_translation());
} }
} }
}; };
......
...@@ -69,6 +69,7 @@ import java.io.ByteArrayOutputStream; ...@@ -69,6 +69,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
...@@ -505,8 +506,9 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab ...@@ -505,8 +506,9 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
// This is to show the pictos ordered in the 2D Array that represents the panel // This is to show the pictos ordered in the 2D Array that represents the panel
Picto[][] mp = new Picto[maxRows][maxColumns]; Picto[][] mp = new Picto[maxRows][maxColumns];
Iterator<Picto> pictos=list.iterator();
for (Picto p : list) { while (pictos.hasNext()) {
Picto p= pictos.next();
if (PCBcontext.getPcbdb().getCurrentUser().has_categories()) { if (PCBcontext.getPcbdb().getCurrentUser().has_categories()) {
if (p.get_column() != -1 && p.get_row() != -1 if (p.get_column() != -1 && p.get_row() != -1
&& p.get_column() < maxRows && p.get_row() < maxColumns) { && p.get_column() < maxRows && p.get_row() < maxColumns) {
......
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