Solucionado problema de primera carga de pictogramas usando inner clases

parent 9239a071
......@@ -302,7 +302,7 @@ public class Device extends SQLiteOpenHelper {
for (User user : prev_users)
db.execSQL("DELETE FROM users_detail WHERE id_stu=" + user.get_id_stu() + " AND id_sup=" + user.get_id_sup());
ImgDownloader downloader = new ImgDownloader(this.context, imgListener, this.getClass().getSimpleName());
ImgDownloader downloader = new ImgDownloader(this.context, imgListener);
downloader.execute(imgs);
db.close();
......
......@@ -54,7 +54,7 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular
try {
Log.i(this.getClass().getName(), "local vocabulary");
PCBcontext.getPcbdb().getStudentVocabulary(this);
listener.loadComplete(this.getClass().getSimpleName());
listener.loadComplete();
} catch (JSONException e) {
Log.e(this.getClass().getName(),"Local vocabulary recover failed: "+e.getMessage());
}
......@@ -102,7 +102,7 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular
imgs.add(new Img(picto.get_id(), picto.get_url(), Img.VOCABULARY));
}
ImgDownloader downloader = new ImgDownloader(PCBcontext.getContext(), imgListener, this.getClass().getSimpleName());
ImgDownloader downloader = new ImgDownloader(PCBcontext.getContext(), imgListener);
downloader.execute(imgs);
PCBcontext.getPcbdb().setStudentVocabulary(this);
}
......@@ -116,7 +116,7 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular
Vector<Img> imgs=new Vector<Img>(1);
imgs.add(new Img(pic.get_id(), pic.get_url(), Img.VOCABULARY));
ImgDownloader downloader = new ImgDownloader(PCBcontext.getContext(), imgListener, this.getClass().getSimpleName());
ImgDownloader downloader = new ImgDownloader(PCBcontext.getContext(), imgListener);
downloader.execute(imgs);
loadPicto(pic);
......
......@@ -42,7 +42,7 @@ import java.util.Vector;
* @version 1.0
*/
public class LoginActivity extends FragmentActivity implements iRestapiListener, iImgDownloaderListener {
public class LoginActivity extends FragmentActivity implements iRestapiListener {
private static final String TAG_ID = "id";
private static final String TAG_NAME = "name";
......@@ -206,28 +206,63 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener,
}
// Si sólo hay 1 estudiante, cargo el st_id
if (students_supervisors.length() == 1){
//User student = PCBcontext.getDevice().findUser(st_id_int, sup_id);
PCBcontext.set_user(student, token, this);
} else{
if (students_supervisors.length() == 1)
PCBcontext.set_user(student, token, new iImgDownloaderListener() {
@Override
public void loadComplete() {
Log.d(LOG_TAG, "Images: Load images complete");
progressDialog.dismiss();
setContentView(R.layout.activity_login);
}
// De la interfaz iImgDownloaderListener
@Override
public void loadImg(Img img) {
}
}); else{
student = new User(-1, "", "", "", "M", "es-es", "",
sup_id, "", "", "", "M", "es-es", "");
PCBcontext.set_user(student, token, this);
PCBcontext.set_user(student, token, null);
}
//Device device = new Device(getApplicationContext(), null, 1);
if (users.size() > 0){
PCBcontext.getDevice().synchronizeUsers(users, this);
PCBcontext.getDevice().synchronizeUsers(users, new iImgDownloaderListener() {
@Override
public void loadComplete() {
}
@Override
public void loadImg(Img img) {
Log.d(LOG_TAG, "Load a single image with ID: " + img.get_id());
// Aquí filtro si sólo tiene un único usuario o varios
Vector<User> users = null;
try {
users = PCBcontext.getDevice().getUsers();
if (users.size() > 1) {
setContentView(R.layout.activity_login);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
PCBcontext.getDevice().deleteDeprecatedImgs();
// Si sólo hay 1 estudiante paso a Pictogram
if (users.size() == 1){
//close the progress dialog
progressDialog.dismiss();
// Si sólo hay 1 estudiante paso a Pictogram
if(users.size()==1)
Intent pictogramActivity = new Intent(this, PictogramActivity.class);
startActivity(pictogramActivity);
}
} else{
{
//close the progress dialog
progressDialog.dismiss();
Intent pictogramActivity = new Intent(this, PictogramActivity.class);
startActivity(pictogramActivity);
}
}else{
AlertDialog.Builder builder =
new AlertDialog.Builder(this);
......@@ -254,44 +289,6 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener,
public void result(JSONObject result) {
}
@Override
public void loadComplete(String name) {
Log.d(LOG_TAG, "Images: Load images " + name + " complete");
try {
// Aquí filtro si sólo tiene un único usuario o varios
Vector<User> users = PCBcontext.getDevice().getUsers();
if (users.size()>1){
//close the progress dialog
progressDialog.dismiss();
setContentView(R.layout.activity_login);
}
}catch(NullPointerException e){
e.printStackTrace();
Log.e(LOG_TAG, "Las imágenes de usuarios todavía no se han cargado o fallo en los fragments");
} catch(JSONException e){
e.printStackTrace();
Log.e(LOG_TAG, "Fallo al procesar JSON");
}
}
// De la interfaz iImgDownloaderListener
@Override
public void loadImg(Img img) {
Log.d(LOG_TAG, "Load a single image with ID: " + img.get_id());
// Aquí filtro si sólo tiene un único usuario o varios
Vector<User> users = null;
try {
users = PCBcontext.getDevice().getUsers();
if (users.size()>1){
setContentView(R.layout.activity_login);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override protected void onResume() {
super.onResume();
......
......@@ -55,7 +55,7 @@ import com.yottacode.pictogram.tools.PCBcontext;
/**
* A login screen that offers login via email/password.
*/
public class SerialActivity extends Activity implements iRestapiListener, iImgDownloaderListener {
public class SerialActivity extends Activity implements iRestapiListener {
// UI references.
private EditText mSerialViewMail;
......@@ -278,9 +278,32 @@ public class SerialActivity extends Activity implements iRestapiListener, iImgDo
//User student = PCBcontext.getDevice().findUser(st_id_int, -1);
//Log.d(LOG_TAG, "student id:" + student.get_id_stu());
PCBcontext.set_user(student, jsonToken, this);
PCBcontext.set_user(student, jsonToken, new iImgDownloaderListener() {
@Override
public void loadComplete() {
progressDialog.dismiss();
Intent pictogramActivity = new Intent(SerialActivity.this, PictogramActivity.class);
startActivity(pictogramActivity);
}
PCBcontext.getDevice().synchronizeUsers(users, this);
@Override
public void loadImg(Img image) {
}
});
PCBcontext.getDevice().synchronizeUsers(users, new iImgDownloaderListener() {
@Override
public void loadComplete() {
}
@Override
public void loadImg(Img image) {
Log.d(LOG_TAG, "Load a single image with ID: " + image.get_id());
setContentView(R.layout.activity_serial);
}
});
PCBcontext.getDevice().deleteDeprecatedImgs();
} else{
......@@ -327,30 +350,6 @@ public class SerialActivity extends Activity implements iRestapiListener, iImgDo
AlertDialog alert = builder.create();
alert.show();
}
@Override
public void loadComplete(String collection) {
Log.d(LOG_TAG, "Images: load " + collection + " images collection complete."+ " Waiting for "+com.yottacode.pictogram.grammar.Vocabulary.class.getSimpleName()+" collection");
if (collection.equalsIgnoreCase(com.yottacode.pictogram.grammar.Vocabulary.class.getSimpleName())) {
/*
User student = PCBcontext.getDevice().findUser(st_id, -1);
Log.d(LOG_TAG, "student:" + student.get_name_stu());
PCBcontext.set_user(student, jsonToken, null);
*/
//close the progress dialog
progressDialog.dismiss();
// Entro directamente a Pictogram con ese alumno
Intent pictogramActivity = new Intent(this, PictogramActivity.class);
startActivity(pictogramActivity);
}
}
@Override
public void loadImg(Img image) {
Log.d(LOG_TAG, "Load a single image with ID: " + image.get_id());
setContentView(R.layout.activity_serial);
}
}
......
......@@ -141,7 +141,7 @@ public class StudentFragmentGrid extends Fragment{
PCBcontext.set_user(student, jsonToken, new iImgDownloaderListener() {
@Override
public void loadComplete(String collection ) {
public void loadComplete( ) {
//Vocabulary vocabulary = PCBcontext.getVocabulary();
//Log.d(LOG_TAG, "Vocabulario de tam:" + vocabulary.size());
progressDialog.dismiss();
......
......@@ -32,10 +32,9 @@ public class ImgDownloader extends AsyncTask<Vector<Img>, Void, Img> {
Context context;
ActivityManager.MemoryInfo mi;
ActivityManager activityManager;
String collection;
public ImgDownloader(Context context, iImgDownloaderListener listener, String collection) {
this.collection=collection;
public ImgDownloader(Context context, iImgDownloaderListener listener) {
this.imgListener = listener;
this.context=context;
this.mi = new ActivityManager.MemoryInfo();
......@@ -100,9 +99,9 @@ public class ImgDownloader extends AsyncTask<Vector<Img>, Void, Img> {
@Override
protected void onPostExecute(Img img) {
Log.d(this.getClass().getCanonicalName(), "Images: Inside OnPostExecute() Collection: "+ this.collection);
Log.d(this.getClass().getCanonicalName(), "Images: Inside OnPostExecute()");
if (imgListener!=null)
if(img == null) imgListener.loadComplete(this.collection);
if(img == null) imgListener.loadComplete();
else imgListener.loadImg(img);
}
......
......@@ -9,6 +9,6 @@ import java.util.LinkedList;
* Created by emblanco on 24/09/15.
*/
public interface iImgDownloaderListener {
public void loadComplete(String collection); // for loading the vocabulary
public void loadComplete(); // for loading the vocabulary
public void loadImg(Img image); // for loading one image
}
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