Pictogram 1.6, Beta 4, issue #431, #421, chivato de conexion en tablet supervisor incluido

parent 0e023f96
Showing with 98 additions and 27 deletions
...@@ -15,14 +15,17 @@ public class TransactionMonitor { ...@@ -15,14 +15,17 @@ public class TransactionMonitor {
return db; return db;
} }
static public void startTransaction(SQLiteOpenHelper helper) { static public void startTransaction(SQLiteOpenHelper helper) {
if (getDBOnTransaction()==null) {
db = helper.getWritableDatabase(); db = helper.getWritableDatabase();
db.enableWriteAheadLogging(); db.enableWriteAheadLogging();
db.beginTransactionNonExclusive(); db.beginTransactionNonExclusive();
Log.i(LOG_TAG,"Transaction begins"); Log.i(LOG_TAG,"Transaction begins ");
} else
Log.e(LOG_TAG,"*********************Transaction is previously started and not finished");
} }
static public void endTransaction(boolean succesfull) { static public void endTransaction(boolean succesfull) {
if (succesfull && db.inTransaction()) {//puede ocurrir que no haya nada if (db.inTransaction()) {//puede ocurrir que no haya nada
db.setTransactionSuccessful(); if (succesfull) db.setTransactionSuccessful();
Log.i(LOG_TAG, "Transaction ends. Successfully? " + succesfull); Log.i(LOG_TAG, "Transaction ends. Successfully? " + succesfull);
db.endTransaction(); db.endTransaction();
} }
......
...@@ -63,12 +63,20 @@ public class Device extends SQLiteOpenHelper { ...@@ -63,12 +63,20 @@ public class Device extends SQLiteOpenHelper {
} }
} }
@Override
public SQLiteDatabase getWritableDatabase() {
SQLiteDatabase db = TransactionMonitor.getDBOnTransaction();
if (db == null)
db = super.getWritableDatabase();
return db;
}
/** /**
* Set the value of a param. * Set the value of a param.
* *
*/ */
private void setParam(String param, String value) { private void setParam(String param, String value) {
setParam(this.getWritableDatabase(),param,value); setParam(this.getWritableDatabase(), param, value);
} }
/** /**
...@@ -315,9 +323,7 @@ public class Device extends SQLiteOpenHelper { ...@@ -315,9 +323,7 @@ public class Device extends SQLiteOpenHelper {
public void insertUser(User user) { public void insertUser(User user) {
SQLiteDatabase db = TransactionMonitor.getDBOnTransaction(); SQLiteDatabase db = this.getWritableDatabase();
if (db==null)
db=this.getWritableDatabase();
String sentence = "INSERT INTO users_detail values (" + String sentence = "INSERT INTO users_detail values (" +
user.get_id_stu() + ", " + user.get_id_stu() + ", " +
......
...@@ -263,7 +263,7 @@ public class PCBDBHelper extends SQLiteOpenHelper { ...@@ -263,7 +263,7 @@ public class PCBDBHelper extends SQLiteOpenHelper {
values.put("url", picto.get_url()); values.put("url", picto.get_url());
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.insert("collection_detail", null, values); db.insertWithOnConflict("collection_detail", null, values,SQLiteDatabase.CONFLICT_REPLACE);
} }
Log.i(LOG_TAG,"Storage "+n+" pictos for student "+id_stu); Log.i(LOG_TAG,"Storage "+n+" pictos for student "+id_stu);
//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
......
...@@ -266,6 +266,7 @@ public class UserLogin { ...@@ -266,6 +266,7 @@ public class UserLogin {
} }
public void login(String username, String password, Activity activity, Class activityAfterLogin) { public void login(String username, String password, Activity activity, Class activityAfterLogin) {
if (PCBcontext.is_user_logged()) PCBcontext.unset_user(); if (PCBcontext.is_user_logged()) PCBcontext.unset_user();
boolean online = RestapiWrapper.ping(activity.getResources().getString(R.string.server), "server/ping"); boolean online = RestapiWrapper.ping(activity.getResources().getString(R.string.server), "server/ping");
if (isSupervisorLoginPattern(username)) if (isSupervisorLoginPattern(username))
......
...@@ -270,6 +270,7 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -270,6 +270,7 @@ public class Vocabulary implements Iterable<Picto> {
else { else {
startpictos = new LinkedList<>(); startpictos = new LinkedList<>();
LinkedList<Picto> pictos = this.pictos.get(PCBcontext.getPcbdb().getCurrentUser().get_active_grid()); LinkedList<Picto> pictos = this.pictos.get(PCBcontext.getPcbdb().getCurrentUser().get_active_grid());
if (pictos!=null && pictos.size()>0)
for (Picto picto : pictos) { for (Picto picto : pictos) {
startpictos.add(picto); startpictos.add(picto);
} }
......
...@@ -134,7 +134,10 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin { ...@@ -134,7 +134,10 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
public void restart_app(boolean resetPrevLogin) { public void restart_app(boolean resetPrevLogin) {
for (iNetServiceStatus listener: listeners) for (iNetServiceStatus listener: listeners)
if (listener instanceof iNetServiceDevice) ((iNetServiceDevice)listener).restart_app(resetPrevLogin); if (listener instanceof iNetServiceDevice) {
((iNetServiceDevice) listener).restart_app(resetPrevLogin);
break;
}
} }
...@@ -253,7 +256,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin { ...@@ -253,7 +256,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
try { try {
objects = new Object[]{new JSONObject().put("student",result)}; objects = new Object[]{new JSONObject().put("student",result)};
PCBcontext.getStudentTalk().call(objects); PCBcontext.getStudentTalk().call(objects);
Log.i(LOG_TAG,"Student attributes synchronized"); Log.i(LOG_TAG,"Student attributes synchronizing");
PCBcontext.getVocabulary().synchronize(); PCBcontext.getVocabulary().synchronize();
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
...@@ -300,6 +303,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin { ...@@ -300,6 +303,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
} }
} }
/** /**
* Created by Fernando on 12/08/2016. * Created by Fernando on 12/08/2016.
*/ */
......
...@@ -17,6 +17,8 @@ import java.util.Hashtable; ...@@ -17,6 +17,8 @@ import java.util.Hashtable;
*/ */
public class ServerLogin { public class ServerLogin {
private static final String LOG_TAG =ServerLogin.class.getSimpleName();
public static void login_student(String username, String password, RestapiWrapper.iRestapiListener listener) { public static void login_student(String username, String password, RestapiWrapper.iRestapiListener listener) {
login("stu/login", null, username, password, listener); login("stu/login", null, username, password, listener);
} }
......
...@@ -18,7 +18,7 @@ public class StudentTalk implements Emitter.Listener { ...@@ -18,7 +18,7 @@ public class StudentTalk implements Emitter.Listener {
private static final String URL ="updateStudent"; private static final String URL ="updateStudent";
private static final String LOG_TAG = StudentTalk.class.getCanonicalName(); private static final String LOG_TAG = StudentTalk.class.getCanonicalName();
private String lastTalk=null;
private final iStudentListener[] listeners; private final iStudentListener[] listeners;
...@@ -32,7 +32,12 @@ public class StudentTalk implements Emitter.Listener { ...@@ -32,7 +32,12 @@ public class StudentTalk implements Emitter.Listener {
if (PCBcontext.getPcbdb()!=null) if (PCBcontext.getPcbdb()!=null)
try { try {
JSONObject msg=((JSONObject) args[0]).getJSONObject("student"); JSONObject msg=((JSONObject) args[0]).getJSONObject("student");
Log.d(this.getClass().getName(), "Raw message: " +msg.toString()); if (lastTalk!=null && lastTalk.equals(msg.toString())) {
Log.e(LOG_TAG, "********************************Message from server duplicated!");
return;
}
lastTalk=msg.toString();
int id=msg.getInt("id"); int id=msg.getInt("id");
String username=msg.getString("username"); String username=msg.getString("username");
String name=msg.getString("name"); String name=msg.getString("name");
...@@ -46,7 +51,7 @@ public class StudentTalk implements Emitter.Listener { ...@@ -46,7 +51,7 @@ public class StudentTalk implements Emitter.Listener {
JSONObject license= msg.getJSONObject("license"); JSONObject license= msg.getJSONObject("license");
Log.i(LOG_TAG, "raw Received message " +msg.toString());
User user=PCBcontext.getPcbdb().getCurrentUser(); User user=PCBcontext.getPcbdb().getCurrentUser();
User updatedUser=new User(id, username, user.get_pwd_stu(), name, surname, id_active_scene, pic, gender, lang, attributes, User updatedUser=new User(id, username, user.get_pwd_stu(), name, surname, id_active_scene, pic, gender, lang, attributes,
user.get_id_sup(), user.get_email_sup(), user.get_pwd_sup(), user.get_name_sup(), user.get_surname_sup(), user.get_url_img_sup(), user.get_gender_sup(), user.get_id_sup(), user.get_email_sup(), user.get_pwd_sup(), user.get_name_sup(), user.get_surname_sup(), user.get_url_img_sup(), user.get_gender_sup(),
......
...@@ -7,6 +7,7 @@ import android.util.Log; ...@@ -7,6 +7,7 @@ import android.util.Log;
import com.yottacode.net.RestapiWrapper; import com.yottacode.net.RestapiWrapper;
import com.yottacode.net.SSLDummyContext; import com.yottacode.net.SSLDummyContext;
import com.yottacode.net.TransactionMonitor;
import com.yottacode.pictogram.commonlibrary.R; import com.yottacode.pictogram.commonlibrary.R;
import com.yottacode.pictogram.action.ActionLog; import com.yottacode.pictogram.action.ActionLog;
import com.yottacode.pictogram.dao.Device; import com.yottacode.pictogram.dao.Device;
...@@ -109,7 +110,7 @@ public final class PCBcontext { ...@@ -109,7 +110,7 @@ public final class PCBcontext {
if (updatedStudent.is_picto_size_big()!=getPcbdb().getCurrentUser().is_picto_size_big() if (updatedStudent.is_picto_size_big()!=getPcbdb().getCurrentUser().is_picto_size_big()
|| updatedStudent.get_active_grid() != PCBcontext.getPcbdb().getCurrentUser().get_active_grid()) { || updatedStudent.get_active_grid() != PCBcontext.getPcbdb().getCurrentUser().get_active_grid()) {
Log.e(LOG_TAG, "Major config modification. Restarting is mandatory"); Log.i(LOG_TAG, "Major config modification. Restarting is mandatory");
PCBcontext.getNetService().restart_app(false); PCBcontext.getNetService().restart_app(false);
} }
else { else {
...@@ -125,6 +126,10 @@ public final class PCBcontext { ...@@ -125,6 +126,10 @@ public final class PCBcontext {
public static void unset_user() { public static void unset_user() {
Log.e(PCBcontext.class.getCanonicalName(), "User unset. Student " + getPcbdb().getCurrentUser().get_name_stu()); Log.e(PCBcontext.class.getCanonicalName(), "User unset. Student " + getPcbdb().getCurrentUser().get_name_stu());
if (room!=null) room.exit(); if (room!=null) room.exit();
if (TransactionMonitor.getDBOnTransaction()!=null) {
Log.e(LOG_TAG, "Unset when transaction is active, aborting transaction");
TransactionMonitor.endTransaction(false);
}
pcbdb = null; pcbdb = null;
room = null; room = null;
vocabulary = null; vocabulary = null;
......
...@@ -258,8 +258,20 @@ public class VocabularyManager extends Activity implements VocabularyTalk.iVocab ...@@ -258,8 +258,20 @@ public class VocabularyManager extends Activity implements VocabularyTalk.iVocab
PCBcontext.getNetService().restart_app(false); PCBcontext.getNetService().restart_app(false);
} }
}); });
((NetServiceTablet)PCBcontext.getNetService().getNetServiceDevice()).setInternetConnectionListener(new NetServiceTablet.iInternetConnectionListener() {
@Override
public void update(final boolean online) {
runOnUiThread(new Runnable() {
@Override
public void run() {
((ImageView) findViewById(R.id.imageConnectionOnOff)).setImageDrawable(online ? getDrawable(R.drawable.application_online) : getDrawable(R.drawable.application_offline));
}
});
} }
});
}
@Override @Override
protected void onResume() { protected void onResume() {
......
...@@ -15,6 +15,7 @@ import android.widget.TextView; ...@@ -15,6 +15,7 @@ import android.widget.TextView;
import com.yottacode.pictogram.net.ImgDownloader; import com.yottacode.pictogram.net.ImgDownloader;
import com.yottacode.pictogram.supervisor.R; import com.yottacode.pictogram.supervisor.R;
import com.yottacode.pictogram.tabletlibrary.net.NetServiceTablet;
import com.yottacode.pictogram.tools.Img; import com.yottacode.pictogram.tools.Img;
import com.yottacode.pictogram.tools.PCBcontext; import com.yottacode.pictogram.tools.PCBcontext;
import com.yottacode.tools.GUITools; import com.yottacode.tools.GUITools;
...@@ -58,6 +59,19 @@ public class LoginActivity extends FragmentActivity { ...@@ -58,6 +59,19 @@ public class LoginActivity extends FragmentActivity {
startActivity(serialActivity); startActivity(serialActivity);
} }
}); });
((NetServiceTablet)PCBcontext.getNetService().getNetServiceDevice()).setInternetConnectionListener(new NetServiceTablet.iInternetConnectionListener() {
@Override
public void update(final boolean online) {
runOnUiThread(new Runnable() {
@Override
public void run() {
((ImageView) findViewById(R.id.imageConnectionOnOff_login)).setImageDrawable(online ? getDrawable(R.drawable.application_online) : getDrawable(R.drawable.application_offline));
}
});
}
});
} }
@Override @Override
......
...@@ -41,7 +41,13 @@ ...@@ -41,7 +41,13 @@
android:textColor="@color/BlancoApp" /> android:textColor="@color/BlancoApp" />
</LinearLayout> </LinearLayout>
<ImageView
android:id="@+id/imageConnectionOnOff_login"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_toLeftOf="@+id/loginTopbarLogout"
android:layout_centerVertical="true"
android:src="@drawable/application_online" />
<Button <Button
android:id="@+id/loginTopbarLogout" android:id="@+id/loginTopbarLogout"
style="@android:style/Widget.Holo.Light.Button" style="@android:style/Widget.Holo.Light.Button"
......
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
...@@ -50,7 +51,13 @@ ...@@ -50,7 +51,13 @@
android:textColor="@color/BlancoApp" /> android:textColor="@color/BlancoApp" />
</LinearLayout> </LinearLayout>
<ImageView
android:id="@+id/imageConnectionOnOff"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_toLeftOf="@+id/vmTopbarToUserListBtn"
android:layout_alignParentTop="true"
android:src="@drawable/application_online" />
<Button <Button
android:id="@+id/vmTopbarToUserListBtn" android:id="@+id/vmTopbarToUserListBtn"
style="@android:style/Widget.Holo.Light.Button" style="@android:style/Widget.Holo.Light.Button"
...@@ -105,13 +112,6 @@ ...@@ -105,13 +112,6 @@
</RelativeLayout> </RelativeLayout>
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="horizontal">
</FrameLayout>
</FrameLayout> </FrameLayout>
...@@ -50,7 +50,13 @@ ...@@ -50,7 +50,13 @@
android:textAppearance="?android:attr/textAppearanceMedium" /> android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout> </LinearLayout>
<ImageView
android:id="@+id/imageConnectionOnOff"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_toLeftOf="@+id/vmTopbarToUserListBtn"
android:layout_centerVertical="true"
android:src="@drawable/application_online" />
<Button <Button
android:id="@+id/vmTopbarToUserListBtn" android:id="@+id/vmTopbarToUserListBtn"
style="@android:style/Widget.Holo.Light.Button" style="@android:style/Widget.Holo.Light.Button"
......
...@@ -137,12 +137,12 @@ public class SerialActivity extends Activity { ...@@ -137,12 +137,12 @@ public class SerialActivity extends Activity {
editor.putString("username", username); editor.putString("username", username);
editor.putString("password", password); editor.putString("password", password);
editor.commit(); editor.commit();
if (!username.equals("") && !password.equals("")) /*if (!username.equals("") && !password.equals(""))
try { try {
new UserLogin().login(username, password, SerialActivity.this, Class.forName(getString(R.string.activityAfterLogin))); new UserLogin().login(username, password, SerialActivity.this, Class.forName(getString(R.string.activityAfterLogin)));
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
Log.e(LOG_TAG,e.toString()); Log.e(LOG_TAG,e.toString());
} }*/
} }
}); });
......
...@@ -22,12 +22,16 @@ import com.yottacode.pictogram.tools.PCBcontext; ...@@ -22,12 +22,16 @@ import com.yottacode.pictogram.tools.PCBcontext;
*/ */
public class NetServiceTablet implements NetService.iNetServiceDevice { public class NetServiceTablet implements NetService.iNetServiceDevice {
public interface iInternetConnectionListener {
public void update(boolean online);
}
private static final String LOG_TAG = NetServiceTablet.class.getName(); private static final String LOG_TAG = NetServiceTablet.class.getName();
private static NotificationCompat.Builder builder; private static NotificationCompat.Builder builder;
private VOCA VOCA; private VOCA VOCA;
int notifyID = 666; int notifyID = 666;
private iInternetConnectionListener internetConnectionListener=null;
public void setInternetConnectionListener(iInternetConnectionListener listener) {this.internetConnectionListener=listener;}
public void build() { public void build() {
this.builder = new NotificationCompat.Builder(PCBcontext.getContext()).setAutoCancel(true).setOngoing(PCBcontext.getContext().getResources().getBoolean(R.bool.NotifyAllwaysVisible)); this.builder = new NotificationCompat.Builder(PCBcontext.getContext()).setAutoCancel(true).setOngoing(PCBcontext.getContext().getResources().getBoolean(R.bool.NotifyAllwaysVisible));
...@@ -66,6 +70,8 @@ public class NetServiceTablet implements NetService.iNetServiceDevice { ...@@ -66,6 +70,8 @@ public class NetServiceTablet implements NetService.iNetServiceDevice {
(NotificationManager) PCBcontext.getContext().getSystemService(PCBcontext.getContext().NOTIFICATION_SERVICE); (NotificationManager) PCBcontext.getContext().getSystemService(PCBcontext.getContext().NOTIFICATION_SERVICE);
mNotificationManager.notify(notifyID, builder.build()); mNotificationManager.notify(notifyID, builder.build());
} }
if (internetConnectionListener!=null)
internetConnectionListener.update(updated);
} }
public void closeNotifyStatus(){ public void closeNotifyStatus(){
NotificationManager mNotificationManager = NotificationManager mNotificationManager =
......
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