Pictogram 1.6, Beta 3, issue #423, varios problemas solucionados relativos a:

- grids vacios
- pérdida de conexión justo entre el login de supervisor y la selección de alumnos
- borrado de pictos online/offline
parent dbbe1c3b
...@@ -166,12 +166,9 @@ public class RestapiWrapper { ...@@ -166,12 +166,9 @@ public class RestapiWrapper {
JSONresponse = new JSONObject("{ "+SERVER_RESULT+": " + response + (responseCode == HttpURLConnection.HTTP_OK JSONresponse = new JSONObject("{ "+SERVER_RESULT+": " + response + (responseCode == HttpURLConnection.HTTP_OK
? "}" ? "}"
: ", "+SERVER_ERROR+": " + responseCode +"}")); : ", "+SERVER_ERROR+": " + responseCode +"}"));
int i=0;
String sresponse=JSONresponse.toString(); Log.i(LOG_TAG, "Server answer:" + JSONresponse.toString());
do {
Log.i(LOG_TAG, "Server answer("+i+"):" + sresponse.substring(i*1000,((i+1)*1000)>sresponse.length() ? sresponse.length() : (i+1)*1000));
i++;
}while (i*1000<sresponse.length());
} catch (JSONException e) { } catch (JSONException e) {
JSONresponse = null; JSONresponse = null;
Log.e(RestapiWrapper.class.getCanonicalName(),e.getMessage()); Log.e(RestapiWrapper.class.getCanonicalName(),e.getMessage());
...@@ -225,6 +222,7 @@ public class RestapiWrapper { ...@@ -225,6 +222,7 @@ public class RestapiWrapper {
params.remove("json"); params.remove("json");
} else } else
sparams=""; sparams="";
for (String param : params.keySet()) { for (String param : params.keySet()) {
String value = params.get(param); String value = params.get(param);
if (param.equals("token")) if (param.equals("token"))
......
...@@ -180,6 +180,7 @@ public class PCBDBHelper extends SQLiteOpenHelper { ...@@ -180,6 +180,7 @@ public class PCBDBHelper extends SQLiteOpenHelper {
Picto picto = new Picto(cursor.getInt(1), cursor.getString(5),cursor.getInt(4),cursor.getInt(2),cursor.getInt(3),new JSONObject(cursor.getString(7))); Picto picto = new Picto(cursor.getInt(1), cursor.getString(5),cursor.getInt(4),cursor.getInt(2),cursor.getInt(3),new JSONObject(cursor.getString(7)));
vocabulary.addPicto(picto); vocabulary.addPicto(picto);
}while (cursor.moveToNext()); }while (cursor.moveToNext());
cursor.close(); cursor.close();
//db.close(); <--no es necesario cerrar la bbdd https://groups.google.com/forum/#!msg/android-developers/NwDRpHUXt0U/jIam4Q8-cqQJ //db.close(); <--no es necesario cerrar la bbdd https://groups.google.com/forum/#!msg/android-developers/NwDRpHUXt0U/jIam4Q8-cqQJ
...@@ -287,7 +288,7 @@ public class PCBDBHelper extends SQLiteOpenHelper { ...@@ -287,7 +288,7 @@ public class PCBDBHelper extends SQLiteOpenHelper {
values.put("translation",picto.get_translation()); values.put("translation",picto.get_translation());
values.put("attributes",picto.get_json_attrs()); values.put("attributes",picto.get_json_attrs());
db.insertWithOnConflict("collection_detail", null, values,SQLiteDatabase.CONFLICT_REPLACE); db.insertWithOnConflict("collection_detail", null, values,SQLiteDatabase.CONFLICT_REPLACE);
Log.i(LOG_TAG,"Picto added:"+picto.get_translation()+" id:"+picto.get_ImgId()+" stupicto_id:"+picto.get_stupicto_id()+" grid:"+picto.get_grid() Log.i(LOG_TAG,"Picto added/updated:"+picto.get_translation()+" id:"+picto.get_ImgId()+" stupicto_id:"+picto.get_stupicto_id()+" grid:"+picto.get_grid()
+". Attributes:"+picto.get_json_attrs()+". Local:"+picto.local_status()+". Local Updated:"+picto.local_update()); +". Attributes:"+picto.get_json_attrs()+". Local:"+picto.local_status()+". Local Updated:"+picto.local_update());
//db.close(); <--no es necesario cerrar la bbdd https://groups.google.com/forum/#!msg/android-developers/NwDRpHUXt0U/jIam4Q8-cqQJ //db.close(); <--no es necesario cerrar la bbdd https://groups.google.com/forum/#!msg/android-developers/NwDRpHUXt0U/jIam4Q8-cqQJ
} }
......
...@@ -307,7 +307,7 @@ public class Picto extends Img { ...@@ -307,7 +307,7 @@ public class Picto extends Img {
} }
public boolean is_invisible1() { public boolean is_invisible1() {
try { try {
return this.attributes.getString(JSON_ATTTRS.STATUS).equals(JSON_ATTTR_STATUS_VALUES.INVISIBLE); return this.attributes.getString(JSON_ATTTRS.STATUS).equals(JSON_ATTTR_STATUS_VALUES.INVISIBLE) || this.attributes.getString(JSON_ATTTRS.STATUS).equals(JSON_ATTTR_STATUS_VALUES.DELETED);
} catch (JSONException e) { } catch (JSONException e) {
Log.e(LOG_TAG,e.getMessage()); Log.e(LOG_TAG,e.getMessage());
return false; return false;
...@@ -338,7 +338,7 @@ public class Picto extends Img { ...@@ -338,7 +338,7 @@ public class Picto extends Img {
} }
public void set_visible(boolean visible) { public void set_visible(boolean visible) {
try { if (!is_deleted()) try {
this.attributes.put(JSON_ATTTRS.STATUS, visible ? JSON_ATTTR_STATUS_VALUES.ENABLED : JSON_ATTTR_STATUS_VALUES.INVISIBLE); this.attributes.put(JSON_ATTTRS.STATUS, visible ? JSON_ATTTR_STATUS_VALUES.ENABLED : JSON_ATTTR_STATUS_VALUES.INVISIBLE);
} catch (JSONException e) { } catch (JSONException e) {
...@@ -367,7 +367,7 @@ public class Picto extends Img { ...@@ -367,7 +367,7 @@ public class Picto extends Img {
? JSON_ATTTR_STATUS_VALUES.ENABLED ? JSON_ATTTR_STATUS_VALUES.ENABLED
: this.attributes.getString(JSON_ATTTRS.STATUS); : this.attributes.getString(JSON_ATTTRS.STATUS);
} catch (JSONException e) { } catch (JSONException e) {
return "enabled"; // By default return JSON_ATTTR_STATUS_VALUES.ENABLED; // By default
} }
} }
...@@ -492,7 +492,7 @@ public class Picto extends Img { ...@@ -492,7 +492,7 @@ public class Picto extends Img {
try { try {
this.attributes.put(JSON_ATTTRS.STATUS, status); this.attributes.put(JSON_ATTTRS.STATUS, status);
set_local_status(true); set_local_status(true);
if (!is_local()) { if (!is_local() && !is_deleted() && PCBcontext.is_user_online() ) {
new PictoUploader(this).uploadState(); new PictoUploader(this).uploadState();
PCBcontext.getActionLog().log(new VocabularyAction(VocabularyAction.ALTERATTRS, this)); PCBcontext.getActionLog().log(new VocabularyAction(VocabularyAction.ALTERATTRS, this));
} }
...@@ -512,7 +512,7 @@ public class Picto extends Img { ...@@ -512,7 +512,7 @@ public class Picto extends Img {
} }
public boolean is_deleted() { public boolean is_deleted() {
return this.attributes.optString(JSON_ATTTRS.PCB_STATUS_MODIFICATION,"").equals(JSON_ATTTR_STATUS_VALUES.DELETED); return this.attributes.optString(JSON_ATTTRS.STATUS,"").equals(JSON_ATTTR_STATUS_VALUES.DELETED);
} }
/** /**
......
...@@ -51,7 +51,6 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -51,7 +51,6 @@ public class Vocabulary implements Iterable<Picto> {
}else }else
try { try {
PCBcontext.getPcbdb().getStudentVocabulary(this); PCBcontext.getPcbdb().getStudentVocabulary(this);
deleteLocallyDeletedPictos();
if (listener!=null) if (listener!=null)
listener.loadComplete(); listener.loadComplete();
} catch (JSONException e) { } catch (JSONException e) {
...@@ -59,16 +58,7 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -59,16 +58,7 @@ public class Vocabulary implements Iterable<Picto> {
listener.error(e); listener.error(e);
} }
} }
private void deleteLocallyDeletedPictos() {
Vector<Picto> pictos_to_be_removed=new Vector<>(3);
for (Picto picto: this)
if (picto.local_status()) {
if (picto.is_deleted())
pictos_to_be_removed.add(picto);
}
for (Picto deleted_picto:pictos_to_be_removed)
this.logicalDeletePicto(deleted_picto.get_grid(),deleted_picto.get_ImgId());
}
public void listen(Room room, VocabularyTalk.iVocabularyListener listener, ActionTalk.iActionListener action_listener) { public void listen(Room room, VocabularyTalk.iVocabularyListener listener, ActionTalk.iActionListener action_listener) {
VocabularyTalk.iVocabularyListener vocabulary_listeners[] = {new VocabularyTalk.iVocabularyListener() { VocabularyTalk.iVocabularyListener vocabulary_listeners[] = {new VocabularyTalk.iVocabularyListener() {
@Override @Override
...@@ -163,6 +153,7 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -163,6 +153,7 @@ public class Vocabulary implements Iterable<Picto> {
private int find_picto_index(int grid_id,int pic_id) { private int find_picto_index(int grid_id,int pic_id) {
LinkedList<Picto> pictos_cat = this.pictos.get(grid_id); LinkedList<Picto> pictos_cat = this.pictos.get(grid_id);
int index=-1; int index=-1;
if (pictos_cat!=null)
for (int i=0; i<pictos_cat.size() && index==-1; i++) for (int i=0; i<pictos_cat.size() && index==-1; i++)
if (pictos_cat.get(i).get_ImgId()==pic_id) index=i; if (pictos_cat.get(i).get_ImgId()==pic_id) index=i;
return index; return index;
...@@ -172,6 +163,7 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -172,6 +163,7 @@ public class Vocabulary implements Iterable<Picto> {
private Picto find_picto(int id_grid, int row, int column) { private Picto find_picto(int id_grid, int row, int column) {
LinkedList<Picto> pictos_cat=this.pictos.get(id_grid); LinkedList<Picto> pictos_cat=this.pictos.get(id_grid);
Picto picto=null; Picto picto=null;
if (pictos_cat!=null)
for (int i=0; i<pictos_cat.size() && picto==null; i++) for (int i=0; i<pictos_cat.size() && picto==null; i++)
if (pictos_cat.get(i).get_column()==column && pictos_cat.get(i).get_row()==row) picto=pictos_cat.get(i); if (pictos_cat.get(i).get_column()==column && pictos_cat.get(i).get_row()==row) picto=pictos_cat.get(i);
return picto; return picto;
...@@ -187,19 +179,13 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -187,19 +179,13 @@ public class Vocabulary implements Iterable<Picto> {
public Picto get_picto(int pic_grid,int pic_id) { public Picto get_picto(int pic_grid,int pic_id) {
Picto picto=null; Picto picto=null;
LinkedList<Picto> pictos_grid=this.pictos.get(pic_grid); LinkedList<Picto> pictos_grid=this.pictos.get(pic_grid);
if (pictos_grid!=null)
for (int i=0; i<pictos_grid.size() && picto==null; i++) for (int i=0; i<pictos_grid.size() && picto==null; i++)
if (pictos_grid.get(i).get_ImgId()==pic_id) picto=pictos_grid.get(i); if (pictos_grid.get(i).get_ImgId()==pic_id) picto=pictos_grid.get(i);
return picto; return picto;
} }
public Picto get_stupicto(int stupicto_id) {
for (Picto picto:this)
if (picto.get_stupicto_id()==stupicto_id)
return picto;
return null;
}
/** /**
...@@ -207,19 +193,21 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -207,19 +193,21 @@ public class Vocabulary implements Iterable<Picto> {
* @param pic_id * @param pic_id
*/ */
public void removePicto(int pic_grid,int pic_id){ public void removePicto(int pic_grid,int pic_id){
int index = find_picto_index(pic_grid, pic_id);
if (logicalDeletePicto(pic_grid,pic_id)) boolean legal_delete=index>=0;
PCBcontext.getPcbdb().deletePicto(pic_grid,pic_id); if (legal_delete) {//puede ocurrir que se intente borrar un pictograma dos veces
else pictos.get(new Integer(pic_grid)).remove(index);
Log.i(this.getClass().getCanonicalName(),"Trying to delete an unregistered picto:"+pic_id+" cat:"+pic_grid); PCBcontext.getPcbdb().deletePicto(pic_grid, pic_id);
for (Picto p2:pictos.get(new Integer(pic_grid))) {
Log.e(LOG_TAG,"COJONES VOCABULA_>"+p2.get_translation());
}
}
} }
public boolean logicalDeletePicto(int pic_grid, int pic_id){ public boolean logicalDeletePicto(int pic_grid, int pic_id){
LinkedList<Picto> pictos_grid=this.pictos.get(pic_grid); LinkedList<Picto> pictos_grid=this.pictos.get(pic_grid);
int index = find_picto_index(pic_grid, pic_id); int index = find_picto_index(pic_grid, pic_id);
boolean legal_delete=index>0; boolean legal_delete=index>=0;
if (legal_delete) { //puede ocurrir que se intente borrar un pictograma dos veces if (legal_delete) { //puede ocurrir que se intente borrar un pictograma dos veces
Picto p = pictos_grid.get(index); Picto p = pictos_grid.get(index);
p.alter_status(Picto.JSON_ATTTR_STATUS_VALUES.DELETED); p.alter_status(Picto.JSON_ATTTR_STATUS_VALUES.DELETED);
......
...@@ -6,6 +6,7 @@ import java.util.Enumeration; ...@@ -6,6 +6,7 @@ import java.util.Enumeration;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Vector;
/** /**
* PCB Vocabulary manager * PCB Vocabulary manager
...@@ -18,7 +19,11 @@ public class VocabularyIterator implements Iterator<Picto> { ...@@ -18,7 +19,11 @@ public class VocabularyIterator implements Iterator<Picto> {
Integer child_grid; Integer child_grid;
int location; int location;
VocabularyIterator(Hashtable<Integer,LinkedList<Picto>> pictos) { VocabularyIterator(Hashtable<Integer,LinkedList<Picto>> pictos) {
this.keys = pictos.keys(); Vector<Integer> vkeys=new Vector(pictos.size());
for (Integer key:pictos.keySet())
if (pictos.get(key).size()>0)
vkeys.add(key);
this.keys=vkeys.elements();
if (pictos.size()>=1) { if (pictos.size()>=1) {
this.pictos=pictos; this.pictos=pictos;
this.child_grid = this.keys.nextElement(); this.child_grid = this.keys.nextElement();
...@@ -43,9 +48,7 @@ public class VocabularyIterator implements Iterator<Picto> { ...@@ -43,9 +48,7 @@ public class VocabularyIterator implements Iterator<Picto> {
if ( this.location==pictos.get(child_grid).size()) { if ( this.location==pictos.get(child_grid).size()) {
this.location = 0; this.location = 0;
this.child_grid = this.keys.nextElement(); this.child_grid = this.keys.nextElement();
} }
picto=pictos.get(child_grid).get(location++); picto=pictos.get(child_grid).get(location++);
return picto; return picto;
} }
......
...@@ -155,14 +155,16 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin { ...@@ -155,14 +155,16 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
public void result(JSONArray result) { public void result(JSONArray result) {
} }
@Override @Override
public void result(JSONObject result) { public void result(final JSONObject result) {
ConnectivityManager cm = ConnectivityManager cm =
(ConnectivityManager)PCBcontext.getContext().getSystemService(Context.CONNECTIVITY_SERVICE); (ConnectivityManager)PCBcontext.getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
if (!isConnected) if (!isConnected) {
setOffline(new NetworkErrorException("No Internet access")); setOffline(new NetworkErrorException("No Internet access"));
return;
}
try { try {
final float version = ((float)(Float.valueOf(result.getString("version")).intValue()*10))/10; final float version = ((float)(Float.valueOf(result.getString("version")).intValue()*10))/10;
...@@ -176,17 +178,24 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin { ...@@ -176,17 +178,24 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
if (!updated) { if (!updated) {
nextRestfullSynchro = new Date().getTime(); nextRestfullSynchro = new Date().getTime();
updated = true; updated = true;
String TAG_TOKEN="token";
try {
PCBcontext.getRestapiWrapper().setToken(result.getString(TAG_TOKEN));
Log.e(LOG_TAG,"AAAAAAAAAAAAAAAAAAAAAAAAAAAATOken:"+result.getString(TAG_TOKEN));
} catch (JSONException e) {
Log.e(LOG_TAG,"Error when getting token:"+e.getMessage()+" res:"+result.toString());
}
if (PCBcontext.is_user_logged()) //si el usuario aun no hizo login, en realidad no es necesario hacer nada if (PCBcontext.is_user_logged()) //si el usuario aun no hizo login, en realidad no es necesario hacer nada
// Comprobar si hay usuario offline, para hacer login transparente // Comprobar si hay usuario offline, para hacer login transparente
if (PCBcontext.is_user_offline()) { if (PCBcontext.is_user_offline()) {
Log.i(LOG_TAG, "PCB online login from offline login"); Log.e(LOG_TAG, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPCB online login from offline login");
login(); login();
} else if (PCBcontext.is_user_online()) { } else if (PCBcontext.is_user_online()) {
Log.i(LOG_TAG, "PCB reconnect"); Log.e(LOG_TAG, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPCB reconnect");
PCBcontext.getRoom().connect(); PCBcontext.getRoom().connect();
synchronizeStuData(); synchronizeStuData();
PCBcontext.getActionLog().batch(); PCBcontext.getActionLog().batch();
} } else Log.e(LOG_TAG,"AAAAAAAAAAAAAAAAAAAAAAAAAAAATOkener:"+result.toString());
} else { } else {
//cada restfullSynchroTimming aprox. se fuerza sincronización de vocabulario y configuración de usuario //cada restfullSynchroTimming aprox. se fuerza sincronización de vocabulario y configuración de usuario
......
...@@ -28,9 +28,14 @@ import java.util.concurrent.ExecutionException; ...@@ -28,9 +28,14 @@ import java.util.concurrent.ExecutionException;
* Created by Fernando on 02/03/2016. * Created by Fernando on 02/03/2016.
*/ */
public class PictoUploader { public class PictoUploader {
public interface iDeletedOnServer {
void ok(int npictos);
void fail();
}
private static final String LOG_TAG = PictoUploader.class.getName(); private static final String LOG_TAG = PictoUploader.class.getName();
Picto picto=null; Picto picto=null;
private int local_img_id=Picto.STUPICTO_NULL; private int local_img_id;
private boolean exists_local_img=false;
public PictoUploader(Picto picto) { public PictoUploader(Picto picto) {
this.picto=picto; this.picto=picto;
...@@ -67,7 +72,8 @@ public class PictoUploader { ...@@ -67,7 +72,8 @@ public class PictoUploader {
int img_id=response.getResult().get("id").getAsInt(); int img_id=response.getResult().get("id").getAsInt();
String img_uri=response.getResult().get("uri").getAsString(); String img_uri=response.getResult().get("uri").getAsString();
img.set_url(img_uri); img.set_url(img_uri);
local_img_id =img.get_ImgId(); local_img_id=img.get_ImgId();
exists_local_img=true;
img.update_id(img_id); img.update_id(img_id);
} else { } else {
Log.i(LOG_TAG, "Uploaded image failed "); Log.i(LOG_TAG, "Uploaded image failed ");
...@@ -337,22 +343,18 @@ public class PictoUploader { ...@@ -337,22 +343,18 @@ public class PictoUploader {
if (picto.local_update()) if (picto.local_update())
picto.set_local_update(false); picto.set_local_update(false);
if (local_img_id!=Picto.STUPICTO_NULL) { if (exists_local_img) {
picto.set_local_status(false); picto.set_local_status(false);
Log.i(LOG_TAG, "Deleting local picto " + picto.get_ImgId() + " ");
PCBcontext.getPcbdb().deletePicto(picto.get_grid(), local_img_id); PCBcontext.getPcbdb().deletePicto(picto.get_grid(), local_img_id);
try { try {
int stupicto_id = server_response.getInt("id"); int stupicto_id = server_response.getInt("id");
picto.set_stupicto_id(stupicto_id); picto.set_stupicto_id(stupicto_id);
PCBcontext.getVocabulary().addPicto(picto);
} catch (JSONException e) { } catch (JSONException e) {
fail(e.getMessage()); fail(e.getMessage());
Log.e(LOG_TAG, "Error uploading picto when getting json from server:" + e.getMessage() + ":" + server_response.toString()); Log.e(LOG_TAG, "Error uploading picto when getting json from server:" + e.getMessage() + ":" + server_response.toString());
} }
exists_local_img=false;
PCBcontext.getPcbdb().savePicto(this.picto); PCBcontext.getPcbdb().savePicto(this.picto);
PCBcontext.getRoom().emit(new VocabularyAction(VocabularyAction.ADD, this.picto)); PCBcontext.getRoom().emit(new VocabularyAction(VocabularyAction.ADD, this.picto));
} }
...@@ -368,7 +370,7 @@ public class PictoUploader { ...@@ -368,7 +370,7 @@ public class PictoUploader {
uploadAttributes(); uploadAttributes();
} }
public void deletePicto() { public void deletePicto(final iDeletedOnServer listener) {
PCBcontext.getRestapiWrapper().ask( PCBcontext.getRestapiWrapper().ask(
PCBcontext.getPcbdb().getCurrentUser().get_restapi_operation_stu() + "/picto/"+picto.get_stupicto_id(), PCBcontext.getPcbdb().getCurrentUser().get_restapi_operation_stu() + "/picto/"+picto.get_stupicto_id(),
...@@ -384,22 +386,18 @@ public class PictoUploader { ...@@ -384,22 +386,18 @@ public class PictoUploader {
@Override @Override
public void result(JSONObject result) { public void result(JSONObject result) {
Log.i(PictoUploader.LOG_TAG, "Delete Picto ok" + PictoUploader.this.picto.get_stupicto_id()); Log.i(PictoUploader.LOG_TAG, "Delete Picto ok: " + PictoUploader.this.picto.get_translation());
PCBcontext.getRoom().emit(new VocabularyAction(VocabularyAction.DELETE, PictoUploader.this.picto)); PCBcontext.getRoom().emit(new VocabularyAction(VocabularyAction.DELETE, PictoUploader.this.picto));
PCBcontext.getVocabulary().removePicto(picto.get_grid(),picto.get_ImgId()); PCBcontext.getVocabulary().removePicto(picto.get_grid(),picto.get_ImgId());
Toast.makeText( if (listener!=null)
PCBcontext.getActivityContext(), listener.ok(1);
(PCBcontext.getActivityContext().getResources().getString(R.string.picto_delete_ok)
+":"+PictoUploader.this.picto.get_translation()), Toast.LENGTH_LONG).show();
} }
@Override @Override
public void error(RestapiWrapper.HTTPException e) { public void error(RestapiWrapper.HTTPException e) {
Log.e(LOG_TAG, "Error when deleting picto: " + e.getLocalizedMessage()); Log.e(LOG_TAG, "Error when deleting picto: " + e.getLocalizedMessage());
Toast.makeText( if (listener!=null)
PCBcontext.getActivityContext(), listener.fail();
(PCBcontext.getActivityContext().getResources().getString(R.string.picto_delete_fail)
+":"+PictoUploader.this.picto.get_translation()), Toast.LENGTH_LONG).show();
} }
} }
); );
......
...@@ -2,9 +2,11 @@ package com.yottacode.pictogram.net; ...@@ -2,9 +2,11 @@ package com.yottacode.pictogram.net;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.util.Log; import android.util.Log;
import android.widget.Toast;
import com.yottacode.net.RestapiWrapper; import com.yottacode.net.RestapiWrapper;
import com.yottacode.net.TransactionMonitor; import com.yottacode.net.TransactionMonitor;
import com.yottacode.pictogram.commonlibrary.R;
import com.yottacode.pictogram.dao.Picto; import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.grammar.Vocabulary; import com.yottacode.pictogram.grammar.Vocabulary;
import com.yottacode.pictogram.tools.Img; import com.yottacode.pictogram.tools.Img;
...@@ -35,13 +37,32 @@ public class VocabularyDownloader { ...@@ -35,13 +37,32 @@ public class VocabularyDownloader {
this.imgListener=imgListener; this.imgListener=imgListener;
} }
public void synchronize() { public void synchronize() {
synchronize_upload(); synchronize_upload(new PictoUploader.iDeletedOnServer() {
@Override
public void ok(int npictos) {
pictos.clear(); pictos.clear();
TransactionMonitor.startTransaction(PCBcontext.getPcbdb()); TransactionMonitor.startTransaction(PCBcontext.getPcbdb());
PCBcontext.getPcbdb().deleteVocabulary(TransactionMonitor.getDBOnTransaction()); PCBcontext.getPcbdb().deleteVocabulary(TransactionMonitor.getDBOnTransaction());
if (npictos>0)
Toast.makeText(
PCBcontext.getActivityContext(),
PCBcontext.getActivityContext().getResources().getString(R.string.picto_delete_ok)+" "+npictos+ " pictos"
, Toast.LENGTH_LONG).show();
synchronize(Picto.ACTIVE_GRID); synchronize(Picto.ACTIVE_GRID);
} }
@Override
public void fail() {
Log.e(LOG_TAG,"error uploading deleted pictos");
Toast.makeText(
PCBcontext.getActivityContext(),
PCBcontext.getActivityContext().getResources().getString(com.yottacode.pictogram.commonlibrary.R.string.picto_delete_fail)
, Toast.LENGTH_LONG).show();
}
});
}
private void synchronize(final int id_grid) { private void synchronize(final int id_grid) {
synchronize(id_grid, new Vector<Integer>(30), new Vector<Integer>(30)); synchronize(id_grid, new Vector<Integer>(30), new Vector<Integer>(30));
} }
...@@ -173,7 +194,7 @@ public class VocabularyDownloader { ...@@ -173,7 +194,7 @@ public class VocabularyDownloader {
* The only issue is: what happens whether the upload fails? --> The image will be lost. * The only issue is: what happens whether the upload fails? --> The image will be lost.
* TODO: keep record of failed uploaded images to re-include as local pictos * TODO: keep record of failed uploaded images to re-include as local pictos
*/ */
private void synchronize_upload() { private void synchronize_upload(final PictoUploader.iDeletedOnServer deleted_pictos) {
try { try {
if (this.pictos.isEmpty()) if (this.pictos.isEmpty())
...@@ -183,15 +204,9 @@ public class VocabularyDownloader { ...@@ -183,15 +204,9 @@ public class VocabularyDownloader {
} }
Vector<Picto> pictos_to_be_removed=new Vector<>(3); Vector<Picto> pictos_to_be_removed=new Vector<>(3);
for (Picto picto: vocabulary) { for (Picto picto: vocabulary) {
if (picto.local_status()) {
if (picto.is_deleted()) if (picto.is_deleted())
pictos_to_be_removed.add(picto); pictos_to_be_removed.add(picto);
else { else
new PictoUploader(picto).uploadState();
Log.i(this.getClass().getCanonicalName(), "Picto status modified while offline. Picto translation: '" +
picto.get_translation() + "', id:" + picto.get_ImgId() + " Local status?" + picto.local_status());
}
}
if (picto.is_local()) if (picto.is_local())
try { try {
...@@ -201,7 +216,12 @@ public class VocabularyDownloader { ...@@ -201,7 +216,12 @@ public class VocabularyDownloader {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
Log.e(this.getClass().getName(), " Picto json error from server when uploading: " + picto.toString()+" Message:"+e.getMessage()); Log.e(this.getClass().getName(), " Picto json error from server when uploading: " + picto.toString()+" Message:"+e.getMessage());
}
else {
if (picto.local_status()) {
new PictoUploader(picto).uploadState();
Log.i(this.getClass().getCanonicalName(), "Picto status modified while offline. Picto translation: '" +
picto.get_translation() + "', id:" + picto.get_ImgId() + " Local status?" + picto.local_status());
} }
if (picto.local_update()) { if (picto.local_update()) {
new PictoUploader(picto).uploadUpdate(); new PictoUploader(picto).uploadUpdate();
...@@ -209,9 +229,30 @@ public class VocabularyDownloader { ...@@ -209,9 +229,30 @@ public class VocabularyDownloader {
picto.get_translation() + "', id:" + picto.get_ImgId() + " Local status?" + picto.local_status()); picto.get_translation() + "', id:" + picto.get_ImgId() + " Local status?" + picto.local_status());
} }
} }
}
if (pictos_to_be_removed.size()>0) {
final int npictos = pictos_to_be_removed.size();
PictoUploader.iDeletedOnServer listener1 = new PictoUploader.iDeletedOnServer() {
int deleted = 0;
for (Picto deleted_picto:pictos_to_be_removed) @Override
new PictoUploader(deleted_picto).deletePicto(); public void ok(int n) {
deleted++;
if (deleted == npictos)
deleted_pictos.ok(npictos);
}
@Override
public void fail() {
deleted_pictos.fail();
}
};
for (Picto deleted_picto : pictos_to_be_removed) {
new PictoUploader(deleted_picto).deletePicto(listener1);
}
}
else deleted_pictos.ok(0);
} }
......
...@@ -30,7 +30,8 @@ public class PictoGridAdapter extends ArrayAdapter { ...@@ -30,7 +30,8 @@ public class PictoGridAdapter extends ArrayAdapter {
@Override @Override
public Picto getItem(int position) { public Picto getItem(int position) {
return this.pictoLinkedList.get(position); Picto item= this.pictoLinkedList.get(position);
return item!=null && !item.is_deleted() ? item : null;
} }
@Override @Override
......
...@@ -126,7 +126,7 @@ public class PictoItemViewGenerator { ...@@ -126,7 +126,7 @@ public class PictoItemViewGenerator {
pictoImage.setImageBitmap(null); pictoImage.setImageBitmap(null);
layoutWrapper.setAlpha(1f); layoutWrapper.setAlpha(1f);
boolean onVocabularyManager=PCBcontext.getActivityContext().getClass().getSimpleName().equals(VocabularyManager.class.getSimpleName()); boolean onVocabularyManager=PCBcontext.getActivityContext().getClass().getSimpleName().equals(VocabularyManager.class.getSimpleName()) ;
// Picto visibility // Picto visibility
if ( onVocabularyManager || (picto != null && !picto.is_invisible())) { if ( onVocabularyManager || (picto != null && !picto.is_invisible())) {
...@@ -138,7 +138,7 @@ public class PictoItemViewGenerator { ...@@ -138,7 +138,7 @@ public class PictoItemViewGenerator {
if (picto!=null) { if (picto!=null) {
micro_icon.setVisibility(picto.getUriSound() == null || !onVocabularyManager ? View.GONE : View.VISIBLE); micro_icon.setVisibility(picto.getUriSound() == null || !onVocabularyManager ? View.GONE : View.VISIBLE);
layoutWrapper.setAlpha(!picto.is_invisible() || (onVocabularyManager && !picto.is_invisible1()) ? 1.00f : onVocabularyManager ? 0.25f : 0f); layoutWrapper.setAlpha(!picto.is_invisible() || (onVocabularyManager && !picto.is_invisible1()) ? 1.00f : onVocabularyManager && !picto.is_deleted() ? 0.25f : 0f);
try { try {
Bitmap bm = picto.get_bitmap(PCBcontext.getContext()); Bitmap bm = picto.get_bitmap(PCBcontext.getContext());
......
...@@ -4,6 +4,7 @@ import android.content.Intent; ...@@ -4,6 +4,7 @@ import android.content.Intent;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.Toast;
import com.yottacode.pictogram.dao.Picto; import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.net.PictoUploader; import com.yottacode.pictogram.net.PictoUploader;
...@@ -235,11 +236,32 @@ public class PictoMenu { ...@@ -235,11 +236,32 @@ public class PictoMenu {
public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return null; } public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return null; }
public void menuActiviated() public void menuActiviated()
{ {
PCBcontext.getVocabulary().logicalDeletePicto(p.get_grid(),p.get_ImgId()); final PictoGridAdapter adapter=activity.getCurrentPictoGridAdapter();
if (PCBcontext.getNetService().online()) if (PCBcontext.getNetService().online())
new PictoUploader(p).deletePicto(); //delete on server side new PictoUploader(p).deletePicto(new PictoUploader.iDeletedOnServer() {
activity.getCurrentPictoGridAdapter().notifyDataSetChanged(); @Override
public void ok(int npictos) {
Toast.makeText(
activity,
(PCBcontext.getActivityContext().getResources().getString(com.yottacode.pictogram.commonlibrary.R.string.picto_delete_ok)
+":"+p.get_translation()), Toast.LENGTH_LONG).show();
adapter.notifyDataSetChanged();
activity.refresh();
}
@Override
public void fail() {
Toast.makeText(
activity,
(PCBcontext.getActivityContext().getResources().getString(com.yottacode.pictogram.commonlibrary.R.string.picto_delete_fail)
+":"+p.get_translation()), Toast.LENGTH_LONG).show();
}
}); //delete on server side
else {
PCBcontext.getVocabulary().logicalDeletePicto(p.get_grid(), p.get_ImgId());
adapter.notifyDataSetChanged();
activity.refresh(); activity.refresh();
}
ll.setVisibility(View.GONE); ll.setVisibility(View.GONE);
((RelativeLayout)PieMenu.getParent()).removeView(PieMenu); ((RelativeLayout)PieMenu.getParent()).removeView(PieMenu);
......
...@@ -6,15 +6,12 @@ import android.app.AlertDialog; ...@@ -6,15 +6,12 @@ import android.app.AlertDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.view.HapticFeedbackConstants;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
...@@ -98,14 +95,12 @@ public class VocabularyManager extends Activity implements VocabularyTalk.iVocab ...@@ -98,14 +95,12 @@ public class VocabularyManager extends Activity implements VocabularyTalk.iVocab
int maxColumns, maxRows, maxInTape; int maxColumns, maxRows, maxInTape;
ScheduledThreadPoolExecutor exec_mirror = null; ScheduledThreadPoolExecutor exec_mirror = null;
Picto prev_picto = null; Picto prev_picto = null;
private boolean feedback_read; ;
private boolean feedback_highlight;
protected boolean deleting;
protected boolean tape_delivered = false; ;
float firstTouchX = -1; float firstTouchX = -1;
public boolean inserting = false;
@TargetApi(Build.VERSION_CODES.M) @TargetApi(Build.VERSION_CODES.M)
@Override @Override
...@@ -275,59 +270,6 @@ public class VocabularyManager extends Activity implements VocabularyTalk.iVocab ...@@ -275,59 +270,6 @@ public class VocabularyManager extends Activity implements VocabularyTalk.iVocab
} }
private void setFeedback(View views[]) {
boolean vibration = PCBcontext.getPcbdb().getCurrentUser().input_feedback_on(User.JSON_STUDENT_INPUT_FEEDBACK.VIBRATION);
boolean click = PCBcontext.getPcbdb().getCurrentUser().input_feedback_on(User.JSON_STUDENT_INPUT_FEEDBACK.BEEP);
this.feedback_read = PCBcontext.getPcbdb().getCurrentUser().input_feedback_on(User.JSON_STUDENT_INPUT_FEEDBACK.READ);
this.feedback_highlight = PCBcontext.getPcbdb().getCurrentUser().input_feedback_on(User.JSON_STUDENT_INPUT_FEEDBACK.HIGHLIGHT);
Log.i(this.getClass().getCanonicalName(), "Feedback:" + " vibration:" + vibration + " Beep:" + click + " Read:" + feedback_read + " Highlight:" + feedback_highlight);
View.OnTouchListener touchListener;
touchListener =
vibration ? new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
boolean enable_haptic;
enable_haptic = !(v instanceof GridView);
if (!enable_haptic) {
int x = Math.round(event.getX());
int y = Math.round(event.getY());
int position = ((GridView) v).pointToPosition(x, y);
Picto p = position > -1 ? (Picto) ((GridView) v).getItemAtPosition(position) : null;
enable_haptic = (p != null && p.get_ImgId() != 0 && !p.is_invisible() && p.is_enabled());
}
if (enable_haptic)
v.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
return false;
}
}
: click
? new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
try {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}
: new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return false;
}
};
for (View view : views)
view.setOnTouchListener(touchListener);
}
@Override @Override
protected void onPause() { protected void onPause() {
...@@ -426,7 +368,7 @@ public class VocabularyManager extends Activity implements VocabularyTalk.iVocab ...@@ -426,7 +368,7 @@ public class VocabularyManager extends Activity implements VocabularyTalk.iVocab
this.pictoCategoryGridAdapter.clear(); this.pictoCategoryGridAdapter.clear();
this.pictoCategoryGridAdapter.addAll(this.sort(this.vocabulary.next(this.currentGrid))); this.pictoCategoryGridAdapter.addAll(this.sort(this.vocabulary.next(this.currentGrid)));
this.pictoCategoryGridAdapter.notifyDataSetChanged(); this.pictoCategoryGridAdapter.notifyDataSetChanged();
Log.e(LOG_TAG,"Grid color:"+PCBcontext.getPcbdb().getGridColor(currentGrid));
this.pictoCategoryGridView.setBackgroundColor(PCBcontext.getPcbdb().getGridColor(currentGrid)); this.pictoCategoryGridView.setBackgroundColor(PCBcontext.getPcbdb().getGridColor(currentGrid));
this.pictoMainGridView.setEnabled(false); this.pictoMainGridView.setEnabled(false);
...@@ -538,7 +480,7 @@ public class VocabularyManager extends Activity implements VocabularyTalk.iVocab ...@@ -538,7 +480,7 @@ public class VocabularyManager extends Activity implements VocabularyTalk.iVocab
private class OnPictoClickListener implements AdapterView.OnItemClickListener { private class OnPictoClickListener implements AdapterView.OnItemClickListener {
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (inserting) return;
Picto p = getCurrentPictoGridAdapter().getItem(position); Picto p = getCurrentPictoGridAdapter().getItem(position);
if (p != null && p.get_ImgId() != 0 ) { if (p != null && p.get_ImgId() != 0 ) {
...@@ -602,7 +544,7 @@ public class VocabularyManager extends Activity implements VocabularyTalk.iVocab ...@@ -602,7 +544,7 @@ public class VocabularyManager extends Activity implements VocabularyTalk.iVocab
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
// Si es supervisor al hacer longClick deshabilito ese pictograma o lo habilito // Si es supervisor al hacer longClick deshabilito ese pictograma o lo habilito
Picto p = getCurrentPictoGridAdapter().getItem(position); Picto p = getCurrentPictoGridAdapter().getItem(position);
Log.e(LOG_TAG,"PREV:"+p+(p!=null ? p.get_legend() : "->nulo"));
if (p == null) { if (p == null) {
// No tengo pictograma. Abro una nueva ventana de selección desde el Carrete // No tengo pictograma. Abro una nueva ventana de selección desde el Carrete
...@@ -665,7 +607,7 @@ public class VocabularyManager extends Activity implements VocabularyTalk.iVocab ...@@ -665,7 +607,7 @@ public class VocabularyManager extends Activity implements VocabularyTalk.iVocab
} }
if (nextActivity != null) { if (nextActivity != null) {
tape_delivered = false;
finish(); finish();
startActivity(nextActivity); startActivity(nextActivity);
overridePendingTransition(in, out); overridePendingTransition(in, out);
......
...@@ -84,6 +84,11 @@ public class StudentFragmentGrid extends Fragment { ...@@ -84,6 +84,11 @@ public class StudentFragmentGrid extends Fragment {
private void set_user(int i) { private void set_user(int i) {
Boolean offline = getActivity().getIntent().getBooleanExtra("offline", false); Boolean offline = getActivity().getIntent().getBooleanExtra("offline", false);
if (offline) { if (offline) {
Log.e(LOG_TAG,"COJONES"+PCBcontext.getNetService().online());
if (PCBcontext.getNetService().online()) {
PCBcontext.getNetService().restart_app(false);
return;
}
User currentUser = null; User currentUser = null;
try { try {
currentUser = PCBcontext.getDevice().findUser(idStudents.get(i), getActivity().getIntent().getIntExtra("sup_id", 0)); currentUser = PCBcontext.getDevice().findUser(idStudents.get(i), getActivity().getIntent().getIntExtra("sup_id", 0));
......
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