Issue #133,#134,#137,#138,#140 closed

parent d5a684f4
......@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.android.tools.build:gradle:2.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
......
......@@ -129,7 +129,8 @@ public class Vocabulary implements Iterable<Picto> {
* 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
*/
private void synchronize_upload() {
private boolean synchronize_upload() {
boolean upload_pending=false;
try {
PCBcontext.getPcbdb().getStudentVocabulary(this);
} catch (JSONException e) {
......@@ -137,12 +138,14 @@ public class Vocabulary implements Iterable<Picto> {
}
for (Picto picto: this) {
if (picto.local_status()) {
upload_pending=true;
new PictoUploader(picto).uploadState();
Log.i(this.getClass().getCanonicalName(), "Picto status modified while offline. Picto translation: '" +
picto.get_translation() + "', id:" + picto.get_id() + " Local status?" + picto.local_status());
}
if (picto.is_local())
try {
upload_pending=true;
Log.i(this.getClass().getCanonicalName(), "Picto added while offline. Picto translation: '" +
picto.get_translation() + "', id:" + picto.get_id() + " Local status?" + picto.local_status());
new PictoUploader(picto).upload();
......@@ -152,6 +155,7 @@ public class Vocabulary implements Iterable<Picto> {
}
}
return upload_pending;
}
/**
* the vocabulary is (i) updated to and (ii) downloaded from the server.
......@@ -159,11 +163,12 @@ public class Vocabulary implements Iterable<Picto> {
public void synchronize() {
synchronize_upload(); // (i) uploading
boolean upload_pending=synchronize_upload(); // (i) uploading
// and (ii) downloading
final String picto_str="/pictos";
String operation=PCBcontext.getPcbdb().getCurrentUser().get_restapi_operation_stu()+picto_str;
if (!upload_pending) {
final String picto_str = "/pictos";
String operation = PCBcontext.getPcbdb().getCurrentUser().get_restapi_operation_stu() + picto_str;
PCBcontext.getRestapiWrapper().ask(operation, new RestapiWrapper.iRestapiListener() {
@Override
public void preExecute() {
......@@ -179,29 +184,31 @@ public class Vocabulary implements Iterable<Picto> {
final String jattributes = "attributes";
Picto[] pictos = new Picto[result.length()];
JSONObject picto, attributes ;
JSONObject picto, attributes;
JSONObject stupicto=null;
JSONObject stupicto = null;
try {
for (int i=0; i < result.length(); i++) {
stupicto=result.getJSONObject(i);
for (int i = 0; i < result.length(); i++) {
stupicto = result.getJSONObject(i);
picto = stupicto.getJSONObject(jpicto);
attributes = stupicto.getJSONObject(jattributes);
attributes.put(Picto.JSON_ATTTRS.STUPICTO_ID,stupicto.get(jid));
attributes.put(Picto.JSON_ATTTRS.STUPICTO_ID, stupicto.get(jid));
pictos[i] = new Picto(picto.getInt(jid),
picto.getString(juri),
attributes);
}
synchronizeImgs(pictos);
if (PCBcontext.is_user_logged()) PCBcontext.getPcbdb().setStudentVocabulary(Vocabulary.this);
else Log.i(this.getClass().getName(),"Downloaded images ended when the user comes to logout");
if (PCBcontext.is_user_logged())
PCBcontext.getPcbdb().setStudentVocabulary(Vocabulary.this);
else
Log.i(this.getClass().getName(), "Downloaded images ended when the user comes to logout");
Log.i(this.getClass().getName(), " Pictos downloaded: " + result.length());
} catch (JSONException e) {
StackTraceElement traces[] = e.getStackTrace();
for (StackTraceElement s: traces)
Log.e(s.getClassName()+"."+s.getFileName()+"."+s.getLineNumber(),s.toString());
for (StackTraceElement s : traces)
Log.e(s.getClassName() + "." + s.getFileName() + "." + s.getLineNumber(), s.toString());
Log.e(this.getClass().getName(), " Picto JSON error from server: " + stupicto.toString());
this.error(new RestapiWrapper.HTTPException("JSON Error:"+e.getMessage(),-1));
this.error(new RestapiWrapper.HTTPException("JSON Error:" + e.getMessage(), -1));
}
}
}
......@@ -213,11 +220,10 @@ public class Vocabulary implements Iterable<Picto> {
@Override
public void error(RestapiWrapper.HTTPException e) {
Log.e(this.getClass().getName(), " Server RESTAPI error: " + e.getLocalizedMessage());
if (Vocabulary.this.imgListener!=null) Vocabulary.this.imgListener.error(e);
if (Vocabulary.this.imgListener != null) Vocabulary.this.imgListener.error(e);
}
});
}
}
......
......@@ -10,7 +10,6 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
......@@ -869,7 +868,8 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
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()) {
new PictoMenu(PictogramActivity.this).createMenuForNewPicto(position % maxColumns, (int) (position / maxColumns), currentCategory.get_id());
int cat = getCurrentCategory() != null ? currentCategory.get_id() : Picto.NO_CATEGORY;
new PictoMenu(PictogramActivity.this).createMenuForNewPicto(position % maxColumns, (int) (position / maxColumns), cat);
} else
Toast.makeText(PictogramActivity.this, PictogramActivity.this.getResources().getString(R.string.notNewCats), Toast.LENGTH_SHORT).show();
......
......@@ -76,6 +76,7 @@ public class SessionActivity extends FragmentActivity implements ListInstruction
SessionWrapper.evaluateTry(currentMsgId, msg_pos==this.msgs.size()-1, evaluation_value, new SessionWrapper.iTryUpdated() {
@Override
public void update(int next_try_id) {
addLogMsg("añadiendo "+ sessionFragment.get_current_msg_text()+".");
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),evaluation_bitmap);
sessionFragment.evaluateMsg(bitmap,getString(evaluation_translation),msg_pos);
addLogMsg("#"+(msg_pos<9 ? "0" : "")+(msg_pos+1)+sessionFragment.get_msg_text(msg_pos));
......
......@@ -98,6 +98,6 @@ public class NetServiceTablet implements NetService.iNetServiceDevice {
}
public void setPictogramActivity(PictogramActivity pictogramActivity) {this.pictogramActivity=pictogramActivity;}
public void updateUserConfig(User user) {
this.pictogramActivity.setConfig();
if (this.pictogramActivity!=null) this.pictogramActivity.setConfig();
}
}
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