Atributo categories e id_scene añadidos a User, y cambiadas las llamadas que…

Atributo categories e id_scene añadidos a User, y cambiadas las llamadas que habia anteriormente en el código por las nuevas para saber si tiene o no categorias
parent 4748b817
......@@ -44,7 +44,6 @@ public class User {
public static String READ="read";
public static String HIGHLIGHT="highlight";
}
private String supervisors;
private Img img_stu;
private String nickname_stu, pwd_stu, name_stu, surname_stu, gender_stu, lang_stu;
private JSONObject attributes_stu;
......@@ -260,7 +259,7 @@ public class User {
*/
public void set_has_categories(boolean categories){
try {
this.attributes_stu.put(JSON_STUDENT_ATTTRS.CATEGORIES, true);
this.attributes_stu.put(JSON_STUDENT_ATTTRS.CATEGORIES, categories);
} catch (JSONException e) {
e.printStackTrace();
}
......@@ -277,13 +276,6 @@ public class User {
}
}
public String get_Supervisors(){
return this.supervisors;
}
public void set_Supervisors(String newSup) {
this.supervisors = newSup;
}
/**
*
* @return delivery method
......
......@@ -36,7 +36,8 @@ import java.util.Vector;
*/
public class Vocabulary implements Iterable<Picto> {
private boolean has_categories;
private int id_scene;
private static final String LOG_TAG = Vocabulary.class.getName();
Hashtable<Integer,LinkedList<Picto>> pictos;
static int DEFAULT_VOCABULARY_SIZE=200;
......@@ -94,7 +95,7 @@ public class Vocabulary implements Iterable<Picto> {
JSONObject attrs_picto = args.getJSONObject("attributes");
attrs_picto.put(Picto.JSON_ATTTRS.STUPICTO_ID,args.getInt("id"));
Picto newPicto=new Picto(picto_id, uri, attrs_picto);
Picto prev_picto=PCBcontext.getPcbdb().getCurrentUser().has_categories()
Picto prev_picto=/*PCBcontext.getPcbdb().getCurrentUser().has_categories()*/PCBcontext.getVocabulary().isHas_categories()
? find_picto(newPicto.get_category(), newPicto.get_row(),newPicto.get_column())
: find_picto(newPicto.getFreeRow(),newPicto.getFreeColumn());
......@@ -172,7 +173,6 @@ public class Vocabulary implements Iterable<Picto> {
// and (ii) downloading
if (!upload_pending) {
//final String picto_str = "/pictos";
final String picto_str = "/activeScene";
String operation = PCBcontext.getPcbdb().getCurrentUser().get_restapi_operation_stu() + picto_str;
PCBcontext.getRestapiWrapper().ask(operation, new RestapiWrapper.iRestapiListener() {
......@@ -189,16 +189,12 @@ public class Vocabulary implements Iterable<Picto> {
@Override
public void result(JSONObject result) {
if (result != null) {
//Log.i("TAG_PRUEBAS",result.toString());
/* final String jpicto = "picto";
final String jid = "id";
final String juri = "uri";
final String jattributes = "attributes";*/
JSONObject picto, attributes;
JSONObject stupicto = null;
try {
PCBcontext.getPcbdb().getCurrentUser().set_has_categories(result.getBoolean("categories"));
//PCBcontext.getPcbdb().getCurrentUser().set_has_categories(result.getBoolean("categories"));
setHas_categories(result.getBoolean("categories"));
setId_scene(result.getInt("id"));
JSONArray stu_pictos = result.getJSONArray("pictos"); //Obtengo el JSONArray de los pictos
Picto[] pictos = new Picto[stu_pictos.length()];
......@@ -212,13 +208,12 @@ public class Vocabulary implements Iterable<Picto> {
attributes);
}
synchronizeImgs(pictos);
//HASTA AQUI BIEN
if (PCBcontext.is_user_logged()) {
PCBcontext.getPcbdb().setStudentVocabulary(Vocabulary.this);
PCBcontext.getPcbdb().setActiveSceneForStudent(result); //Aqui inserto en scene los datos que llegan de la activa
}else
Log.i(this.getClass().getName(), "Downloaded images ended when the user comes to logout");
Log.i(this.getClass().getName(), " Pictos downloaded: " + result.length());
Log.i(this.getClass().getName(), " Pictos downloaded: " + result.getJSONArray("pictos").length());
} catch (JSONException e) {
StackTraceElement traces[] = e.getStackTrace();
for (StackTraceElement s : traces)
......@@ -231,10 +226,6 @@ public class Vocabulary implements Iterable<Picto> {
}
}
/*@Override
public void result(JSONObject result) {
}*/
@Override
public void error(RestapiWrapper.HTTPException e) {
Log.e(this.getClass().getName(), " Server RESTAPI error: " + e.getLocalizedMessage());
......@@ -408,7 +399,7 @@ public class Vocabulary implements Iterable<Picto> {
* @return list of pictos which should be selectable at the beginning of a sentence. Empty categories are removed
*/
public LinkedList<Picto> startSentence(){
if (PCBcontext.getPcbdb().getCurrentUser().has_categories()) {
if (/*PCBcontext.getPcbdb().getCurrentUser().has_categories()*/PCBcontext.getVocabulary().isHas_categories()) {
return this.pictos.get(new Integer(Picto.NO_CATEGORY));
} else {
LinkedList<Picto> freePictos = new LinkedList<>();
......@@ -447,7 +438,7 @@ public class Vocabulary implements Iterable<Picto> {
public void saveLocalPicto(String url, String exp, int cat, int coord_x, int coord_y, int free_category_coord_x, int free_category_coord_y,String user_avatar, String path_sound,final iLocalPicto listener) {
Picto prev_picto=PCBcontext.getPcbdb().getCurrentUser().has_categories() ? find_picto(cat, coord_x,coord_y) : find_picto(free_category_coord_x,free_category_coord_y); //¿estamos reemplazanddo un picto que ya existe?
Picto prev_picto=/*PCBcontext.getPcbdb().getCurrentUser().has_categories()*/PCBcontext.getVocabulary().isHas_categories() ? find_picto(cat, coord_x,coord_y) : find_picto(free_category_coord_x,free_category_coord_y); //¿estamos reemplazanddo un picto que ya existe?
if (prev_picto!=null) { //El picto ya existe
removePicto(prev_picto.get_category(),prev_picto.get_id()); //borramos el picto local actual
......@@ -516,4 +507,20 @@ public class Vocabulary implements Iterable<Picto> {
return vocabulary;
}
public boolean isHas_categories() {
return has_categories;
}
public void setHas_categories(boolean has_categories) {
this.has_categories = has_categories;
}
public int getId_scene() {
return id_scene;
}
public void setId_scene(int id_scene) {
this.id_scene = id_scene;
}
}
......@@ -151,7 +151,7 @@ public class PictoUploader {
if (picto.get_user_avatar()!=null) json_attrs.put(Picto.JSON_ATTTRS.USER_AVATAR,picto.get_user_avatar());
/*json_attrs.put("scene",picto.get_id_scene());*/
if (PCBcontext.getPcbdb().getCurrentUser().has_categories())
if (/*PCBcontext.getPcbdb().getCurrentUser().has_categories()*/PCBcontext.getVocabulary().isHas_categories())
json_attrs.put(Picto.JSON_ATTTRS.CATEGORY, picto.get_category())
.put(Picto.JSON_ATTTRS.COLUMN, picto.get_column())
.put(Picto.JSON_ATTTRS.ROW, picto.get_row());
......
......@@ -77,7 +77,8 @@ public final class PCBcontext {
@Override
public void change(User updatedStudent) {
PCBcontext.getDevice().insertUser(updatedStudent);
if (updatedStudent.is_picto_size_big()!=getPcbdb().getCurrentUser().is_picto_size_big() || updatedStudent.has_categories()!=getPcbdb().getCurrentUser().has_categories())
if (updatedStudent.is_picto_size_big()!=getPcbdb().getCurrentUser().is_picto_size_big() /*|| updatedStudent.has_categories()!=getPcbdb().getCurrentUser().has_categories()*/
|| PCBcontext.getVocabulary().isHas_categories() != vocabulary.isHas_categories() || PCBcontext.getVocabulary().getId_scene()!= vocabulary.getId_scene())
PCBcontext.getNetService().restart_app(false);
else {
PCBcontext.getPcbdb().setCurrentUser(updatedStudent);
......
......@@ -82,7 +82,7 @@ public class PictoMenu {
public void addPicto(int row, int col, int cat, int source) {
//Enviar al PictogramActivity los datos necesarios para crear el picto despues
if (PCBcontext.getPcbdb().getCurrentUser().has_categories()) {
if (/*PCBcontext.getPcbdb().getCurrentUser().has_categories()*/PCBcontext.getVocabulary().isHas_categories()) {
activity.getIntent().putExtra(Picto.JSON_ATTTRS.CATEGORY, cat);
activity.getIntent().putExtra(Picto.JSON_ATTTRS.ROW, row);
activity.getIntent().putExtra(Picto.JSON_ATTTRS.COLUMN, col);
......@@ -108,7 +108,7 @@ public class PictoMenu {
intent.putExtra(ID_PICTO_IMAGE,id_picto);
//Enviar al PictogramActivity los datos necesarios para editar el picto despues
if (PCBcontext.getPcbdb().getCurrentUser().has_categories()) {
if (/*PCBcontext.getPcbdb().getCurrentUser().has_categories()*/PCBcontext.getVocabulary().isHas_categories()) {
intent.putExtra(Picto.JSON_ATTTRS.CATEGORY, cat);
intent.putExtra(Picto.JSON_ATTTRS.ROW, row);
intent.putExtra(Picto.JSON_ATTTRS.COLUMN, col);
......
......@@ -562,7 +562,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
Iterator<Picto> pictos=list.iterator();
while (pictos.hasNext()) {
Picto p= pictos.next();
if (PCBcontext.getPcbdb().getCurrentUser().has_categories()) {
if (/*PCBcontext.getPcbdb().getCurrentUser().has_categories()*/PCBcontext.getVocabulary().isHas_categories()) {
if (p.get_column() != -1 && p.get_row() != -1
&& p.get_column() < maxRows && p.get_row() < maxColumns) {
mp[p.get_column()][p.get_row()] = p;
......@@ -905,7 +905,7 @@ Log.e(LOG_TAG,"AUDIO:"+(audioFile!=null)+":"+p.get_audioPath());
Picto p = getCurrentPictoGridAdapter().getItem(position);
if (p == null) {
// No tengo pictograma. Abro una nueva ventana de selección desde el Carrete del device si no es categoria
if (getCurrentCategory() != null || !PCBcontext.getPcbdb().getCurrentUser().has_categories()) {
if (getCurrentCategory() != null || /*!PCBcontext.getPcbdb().getCurrentUser().has_categories()*/!PCBcontext.getVocabulary().isHas_categories()) {
int cat = getCurrentCategory() != null ? currentCategory.get_id() : Picto.NO_CATEGORY;
new PictoMenu(PictogramActivity.this).createMenuForNewPicto(position % maxColumns, (int) (position / maxColumns), cat);
} else
......
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