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

parent d5a684f4
...@@ -5,7 +5,7 @@ buildscript { ...@@ -5,7 +5,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { 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 // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
......
...@@ -129,7 +129,8 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -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. * 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 boolean synchronize_upload() {
boolean upload_pending=false;
try { try {
PCBcontext.getPcbdb().getStudentVocabulary(this); PCBcontext.getPcbdb().getStudentVocabulary(this);
} catch (JSONException e) { } catch (JSONException e) {
...@@ -137,12 +138,14 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -137,12 +138,14 @@ public class Vocabulary implements Iterable<Picto> {
} }
for (Picto picto: this) { for (Picto picto: this) {
if (picto.local_status()) { if (picto.local_status()) {
upload_pending=true;
new PictoUploader(picto).uploadState(); new PictoUploader(picto).uploadState();
Log.i(this.getClass().getCanonicalName(), "Picto status modified while offline. Picto translation: '" + Log.i(this.getClass().getCanonicalName(), "Picto status modified while offline. Picto translation: '" +
picto.get_translation() + "', id:" + picto.get_id() + " Local status?" + picto.local_status()); picto.get_translation() + "', id:" + picto.get_id() + " Local status?" + picto.local_status());
} }
if (picto.is_local()) if (picto.is_local())
try { try {
upload_pending=true;
Log.i(this.getClass().getCanonicalName(), "Picto added while offline. Picto translation: '" + Log.i(this.getClass().getCanonicalName(), "Picto added while offline. Picto translation: '" +
picto.get_translation() + "', id:" + picto.get_id() + " Local status?" + picto.local_status()); picto.get_translation() + "', id:" + picto.get_id() + " Local status?" + picto.local_status());
new PictoUploader(picto).upload(); new PictoUploader(picto).upload();
...@@ -152,6 +155,7 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -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. * the vocabulary is (i) updated to and (ii) downloaded from the server.
...@@ -159,65 +163,67 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -159,65 +163,67 @@ public class Vocabulary implements Iterable<Picto> {
public void synchronize() { public void synchronize() {
synchronize_upload(); // (i) uploading boolean upload_pending=synchronize_upload(); // (i) uploading
// and (ii) downloading // and (ii) downloading
final String picto_str="/pictos"; if (!upload_pending) {
String operation=PCBcontext.getPcbdb().getCurrentUser().get_restapi_operation_stu()+picto_str; final String picto_str = "/pictos";
PCBcontext.getRestapiWrapper().ask(operation, new RestapiWrapper.iRestapiListener() { String operation = PCBcontext.getPcbdb().getCurrentUser().get_restapi_operation_stu() + picto_str;
@Override PCBcontext.getRestapiWrapper().ask(operation, new RestapiWrapper.iRestapiListener() {
public void preExecute() { @Override
public void preExecute() {
} }
@Override @Override
public void result(JSONArray result) { public void result(JSONArray result) {
if (result != null) { if (result != null) {
final String jpicto = "picto"; final String jpicto = "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";
Picto[] pictos = new Picto[result.length()]; Picto[] pictos = new Picto[result.length()];
JSONObject picto, attributes ; JSONObject picto, attributes;
JSONObject stupicto=null; JSONObject stupicto = null;
try { try {
for (int i=0; i < result.length(); i++) { for (int i = 0; i < result.length(); i++) {
stupicto=result.getJSONObject(i); stupicto = result.getJSONObject(i);
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));
pictos[i] = new Picto(picto.getInt(jid), pictos[i] = new Picto(picto.getInt(jid),
picto.getString(juri), picto.getString(juri),
attributes); 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");
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());
Log.e(this.getClass().getName(), " Picto JSON error from server: " + stupicto.toString());
this.error(new RestapiWrapper.HTTPException("JSON Error:" + e.getMessage(), -1));
} }
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");
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());
Log.e(this.getClass().getName(), " Picto JSON error from server: " + stupicto.toString());
this.error(new RestapiWrapper.HTTPException("JSON Error:"+e.getMessage(),-1));
} }
} }
}
@Override
public void result(JSONObject result) {
}
@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);
}
});
@Override
public void result(JSONObject result) {
}
@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);
}
});
}
} }
......
...@@ -10,7 +10,6 @@ import android.content.DialogInterface; ...@@ -10,7 +10,6 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.PixelFormat; import android.graphics.PixelFormat;
import android.graphics.Point;
import android.media.Ringtone; import android.media.Ringtone;
import android.media.RingtoneManager; import android.media.RingtoneManager;
import android.net.Uri; import android.net.Uri;
...@@ -869,7 +868,8 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab ...@@ -869,7 +868,8 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
if (p == null) { if (p == null) {
// No tengo pictograma. Abro una nueva ventana de selección desde el Carrete del device si no es categoria // 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()) {
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 } else
Toast.makeText(PictogramActivity.this, PictogramActivity.this.getResources().getString(R.string.notNewCats), Toast.LENGTH_SHORT).show(); 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 ...@@ -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() { SessionWrapper.evaluateTry(currentMsgId, msg_pos==this.msgs.size()-1, evaluation_value, new SessionWrapper.iTryUpdated() {
@Override @Override
public void update(int next_try_id) { public void update(int next_try_id) {
addLogMsg("añadiendo "+ sessionFragment.get_current_msg_text()+".");
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),evaluation_bitmap); Bitmap bitmap = BitmapFactory.decodeResource(getResources(),evaluation_bitmap);
sessionFragment.evaluateMsg(bitmap,getString(evaluation_translation),msg_pos); sessionFragment.evaluateMsg(bitmap,getString(evaluation_translation),msg_pos);
addLogMsg("#"+(msg_pos<9 ? "0" : "")+(msg_pos+1)+sessionFragment.get_msg_text(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 { ...@@ -98,6 +98,6 @@ public class NetServiceTablet implements NetService.iNetServiceDevice {
} }
public void setPictogramActivity(PictogramActivity pictogramActivity) {this.pictogramActivity=pictogramActivity;} public void setPictogramActivity(PictogramActivity pictogramActivity) {this.pictogramActivity=pictogramActivity;}
public void updateUserConfig(User user) { 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