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

parent 0e023f96
Showing with 102 additions and 31 deletions
......@@ -15,14 +15,17 @@ public class TransactionMonitor {
return db;
}
static public void startTransaction(SQLiteOpenHelper helper) {
db = helper.getWritableDatabase();
db.enableWriteAheadLogging();
db.beginTransactionNonExclusive();
Log.i(LOG_TAG,"Transaction begins");
if (getDBOnTransaction()==null) {
db = helper.getWritableDatabase();
db.enableWriteAheadLogging();
db.beginTransactionNonExclusive();
Log.i(LOG_TAG,"Transaction begins ");
} else
Log.e(LOG_TAG,"*********************Transaction is previously started and not finished");
}
static public void endTransaction(boolean succesfull) {
if (succesfull && db.inTransaction()) {//puede ocurrir que no haya nada
db.setTransactionSuccessful();
if (db.inTransaction()) {//puede ocurrir que no haya nada
if (succesfull) db.setTransactionSuccessful();
Log.i(LOG_TAG, "Transaction ends. Successfully? " + succesfull);
db.endTransaction();
}
......
......@@ -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.
*
*/
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 {
public void insertUser(User user) {
SQLiteDatabase db = TransactionMonitor.getDBOnTransaction();
if (db==null)
db=this.getWritableDatabase();
SQLiteDatabase db = this.getWritableDatabase();
String sentence = "INSERT INTO users_detail values (" +
user.get_id_stu() + ", " +
......
......@@ -263,7 +263,7 @@ public class PCBDBHelper extends SQLiteOpenHelper {
values.put("url", picto.get_url());
values.put("translation",picto.get_translation());
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);
//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 {
}
public void login(String username, String password, Activity activity, Class activityAfterLogin) {
if (PCBcontext.is_user_logged()) PCBcontext.unset_user();
boolean online = RestapiWrapper.ping(activity.getResources().getString(R.string.server), "server/ping");
if (isSupervisorLoginPattern(username))
......
......@@ -270,6 +270,7 @@ public class Vocabulary implements Iterable<Picto> {
else {
startpictos = new LinkedList<>();
LinkedList<Picto> pictos = this.pictos.get(PCBcontext.getPcbdb().getCurrentUser().get_active_grid());
if (pictos!=null && pictos.size()>0)
for (Picto picto : pictos) {
startpictos.add(picto);
}
......
......@@ -134,7 +134,10 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
public void restart_app(boolean resetPrevLogin) {
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 {
try {
objects = new Object[]{new JSONObject().put("student",result)};
PCBcontext.getStudentTalk().call(objects);
Log.i(LOG_TAG,"Student attributes synchronized");
Log.i(LOG_TAG,"Student attributes synchronizing");
PCBcontext.getVocabulary().synchronize();
} catch (JSONException e) {
e.printStackTrace();
......@@ -300,6 +303,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
}
}
/**
* Created by Fernando on 12/08/2016.
*/
......
......@@ -17,6 +17,8 @@ import java.util.Hashtable;
*/
public class ServerLogin {
private static final String LOG_TAG =ServerLogin.class.getSimpleName();
public static void login_student(String username, String password, RestapiWrapper.iRestapiListener listener) {
login("stu/login", null, username, password, listener);
}
......
......@@ -18,7 +18,7 @@ public class StudentTalk implements Emitter.Listener {
private static final String URL ="updateStudent";
private static final String LOG_TAG = StudentTalk.class.getCanonicalName();
private String lastTalk=null;
private final iStudentListener[] listeners;
......@@ -32,7 +32,12 @@ public class StudentTalk implements Emitter.Listener {
if (PCBcontext.getPcbdb()!=null)
try {
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");
String username=msg.getString("username");
String name=msg.getString("name");
......@@ -46,7 +51,7 @@ public class StudentTalk implements Emitter.Listener {
JSONObject license= msg.getJSONObject("license");
Log.i(LOG_TAG, "raw Received message " +msg.toString());
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.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;
import com.yottacode.net.RestapiWrapper;
import com.yottacode.net.SSLDummyContext;
import com.yottacode.net.TransactionMonitor;
import com.yottacode.pictogram.commonlibrary.R;
import com.yottacode.pictogram.action.ActionLog;
import com.yottacode.pictogram.dao.Device;
......@@ -109,7 +110,7 @@ public final class PCBcontext {
if (updatedStudent.is_picto_size_big()!=getPcbdb().getCurrentUser().is_picto_size_big()
|| 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);
}
else {
......@@ -125,6 +126,10 @@ public final class PCBcontext {
public static void unset_user() {
Log.e(PCBcontext.class.getCanonicalName(), "User unset. Student " + getPcbdb().getCurrentUser().get_name_stu());
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;
room = null;
vocabulary = null;
......
......@@ -258,7 +258,19 @@ public class VocabularyManager extends Activity implements VocabularyTalk.iVocab
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
......
......@@ -15,6 +15,7 @@ import android.widget.TextView;
import com.yottacode.pictogram.net.ImgDownloader;
import com.yottacode.pictogram.supervisor.R;
import com.yottacode.pictogram.tabletlibrary.net.NetServiceTablet;
import com.yottacode.pictogram.tools.Img;
import com.yottacode.pictogram.tools.PCBcontext;
import com.yottacode.tools.GUITools;
......@@ -58,6 +59,19 @@ public class LoginActivity extends FragmentActivity {
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
......
......@@ -41,7 +41,13 @@
android:textColor="@color/BlancoApp" />
</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
android:id="@+id/loginTopbarLogout"
style="@android:style/Widget.Holo.Light.Button"
......
<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"
android:layout_width="match_parent"
android:layout_height="match_parent"
......@@ -50,7 +51,13 @@
android:textColor="@color/BlancoApp" />
</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
android:id="@+id/vmTopbarToUserListBtn"
style="@android:style/Widget.Holo.Light.Button"
......@@ -105,13 +112,6 @@
</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>
......@@ -50,7 +50,13 @@
android:textAppearance="?android:attr/textAppearanceMedium" />
</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
android:id="@+id/vmTopbarToUserListBtn"
style="@android:style/Widget.Holo.Light.Button"
......
......@@ -137,12 +137,12 @@ public class SerialActivity extends Activity {
editor.putString("username", username);
editor.putString("password", password);
editor.commit();
if (!username.equals("") && !password.equals(""))
/*if (!username.equals("") && !password.equals(""))
try {
new UserLogin().login(username, password, SerialActivity.this, Class.forName(getString(R.string.activityAfterLogin)));
} catch (ClassNotFoundException e) {
Log.e(LOG_TAG,e.toString());
}
}*/
}
});
......
......@@ -22,13 +22,17 @@ import com.yottacode.pictogram.tools.PCBcontext;
*/
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 NotificationCompat.Builder builder;
private VOCA VOCA;
int notifyID = 666;
private iInternetConnectionListener internetConnectionListener=null;
public void build() {
public void setInternetConnectionListener(iInternetConnectionListener listener) {this.internetConnectionListener=listener;}
public void build() {
this.builder = new NotificationCompat.Builder(PCBcontext.getContext()).setAutoCancel(true).setOngoing(PCBcontext.getContext().getResources().getBoolean(R.bool.NotifyAllwaysVisible));
if (this.VOCA!=null) {
......@@ -66,6 +70,8 @@ public class NetServiceTablet implements NetService.iNetServiceDevice {
(NotificationManager) PCBcontext.getContext().getSystemService(PCBcontext.getContext().NOTIFICATION_SERVICE);
mNotificationManager.notify(notifyID, builder.build());
}
if (internetConnectionListener!=null)
internetConnectionListener.update(updated);
}
public void closeNotifyStatus(){
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