Commit a24dc8cb authored by Christof Wolke's avatar Christof Wolke

DB helper to save the event and new Projectstructure

parent 2d731ef3
...@@ -2,39 +2,67 @@ ...@@ -2,39 +2,67 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.uni_oldenburg.bidl"> package="de.uni_oldenburg.bidl">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application <application
android:name="de.uni_oldenburg.bidl.AppClass"
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<!--
Don't increase version on every single DB model change, use Rush_debug instead (see below).
de.uni_oldenburg.bidl.AppClass also contains code to allow dropping the database
-->
<meta-data
android:name="Rush_classes_package"
android:value="de.uni_oldenburg.bidl.classes" />
<meta-data
android:name="Rush_db_version"
android:value="2" />
<meta-data
android:name="Rush_db_name"
android:value="bidl.db" />
<!--
Setting this to true will cause a migration to happen every launch,
this is very handy during development although could cause data loss
-->
<meta-data
android:name="Rush_debug"
android:value="false" />
<meta-data
android:name="Rush_requires_table_annotation"
android:value="false" />
<meta-data
android:name="Rush_log"
android:value="false" />
<activity <activity
android:name=".base_view.MainActivity" android:name="de.uni_oldenburg.bidl.base_view.MainActivity"
android:label="Home" android:label="Bidl"
android:screenOrientation="sensorPortrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name=".base_view.SplashActivity"
android:parentActivityName=".base_view.SplashActivity"
android:screenOrientation="sensorPortrait"> android:screenOrientation="sensorPortrait">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".guest_view.LoginActivity" /> <activity android:name="de.uni_oldenburg.bidl.guest_view.LoginActivity"
<activity android:name=".guest_view.RegisterActivity"></activity> android:screenOrientation="sensorPortrait"/>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
<activity android:name="de.uni_oldenburg.bidl.guest_view.RegisterActivity"
android:parentActivityName=".guest_view.LoginActivity"
android:screenOrientation="sensorPortrait"/>
</application> </application>
</manifest> </manifest>
\ No newline at end of file
...@@ -3,11 +3,17 @@ package classes; ...@@ -3,11 +3,17 @@ package classes;
import com.bluelinelabs.logansquare.annotation.JsonField; import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject; import com.bluelinelabs.logansquare.annotation.JsonObject;
import java.io.Serializable;
import classes.apps.AppContainer;
import co.uk.rushorm.core.RushObject;
import co.uk.rushorm.core.annotations.RushClassSerializationName;
/** /**
* Created by Christof on 23.08.2016. * Created by Christof on 23.08.2016.
*/ */
@JsonObject @JsonObject
public class Event { public class Event extends RushObject implements Serializable {
@JsonField(name = "id") @JsonField(name = "id")
private int eventId; private int eventId;
...@@ -15,6 +21,7 @@ public class Event { ...@@ -15,6 +21,7 @@ public class Event {
@JsonField(name = "name") @JsonField(name = "name")
private String name; private String name;
@JsonField(name = "appContainer") @JsonField(name = "appContainer")
private AppContainer appContainer; private AppContainer appContainer;
...@@ -27,6 +34,7 @@ public class Event { ...@@ -27,6 +34,7 @@ public class Event {
this.appContainer = appContainer; this.appContainer = appContainer;
} }
public int getEventId() { public int getEventId() {
return eventId; return eventId;
} }
......
package classes;
import android.content.Context;
import android.content.SharedPreferences;
/**
* Created by Christof on 25.08.2016.
*/
public class LocalStorage {
public static final String SP_NAME = "userDetails";
private SharedPreferences userLocalDatabase;
/**
*
* @param context App-context zum Zugriff auf die SharedPreference API
*/
public LocalStorage(Context context){
this.userLocalDatabase = context.getSharedPreferences(SP_NAME, 0);
}
/**
* Speichert Userdaten in SharedPreference
* @param user User Object, welches gespeichert werden soll
*/
public void storeUserData(User user){
SharedPreferences.Editor spEditor = this.userLocalDatabase.edit();
spEditor.putString("username", user.getUsername());
spEditor.putString("email", user.getEmail());
spEditor.putLong("id", user.getUserId());
spEditor.putString("image", user.getImagePath());
spEditor.apply();
}
/**
* Löscht alle Userdaten aus dem Storage
*/
public void deleteUserData(){
SharedPreferences.Editor spEditor = userLocalDatabase.edit();
spEditor.remove("username");
spEditor.remove("email");
spEditor.remove("id");
spEditor.remove("image");
spEditor.remove("loggedIn");
spEditor.apply();
}
/**
*
* @return derzeit gespeicherter (eingeloggter) User
*/
public User getLoggedInUser(){
String username = this.userLocalDatabase.getString("username","");
String email = this.userLocalDatabase.getString("email", "");
Long id = this.userLocalDatabase.getLong("id", 0);
String image = this.userLocalDatabase.getString("image", "");
return new User(username, email, id, image);
}
/**
* Ändert, ob ein User eingeloggt ist
* @param loggedIn true = eingeloggt, false = nicht eingeloggt
*/
public void setLoggedIn(boolean loggedIn){
SharedPreferences.Editor spEditor = this.userLocalDatabase.edit();
spEditor.putBoolean("loggedIn", loggedIn);
spEditor.apply();
}
/**
* Liefert zurück, ob derzeit ein User eingeloggt ist.
* @return true = User eingeloggt, false = kein User eingeloggt
*/
public Boolean isLoggedIn(){
return this.userLocalDatabase.getBoolean("loggedIn", false);
}
/**
* Liefert den Pfad zum Profilbild des Nutzers
* @return Pfad zum Profilbild des Nutzers
*/
public String getUserImage() {
return this.userLocalDatabase.getString("image", "");
}
/**
* Ändert den Pfad zum Profilbild des Nutzers
* @param image neuen Pfad zum Profilbild des Nutzers
*/
public void setUserImage(String image) {
SharedPreferences.Editor spEditor = this.userLocalDatabase.edit();
spEditor.putString("image", image);
spEditor.apply();
}
/**
* Löscht alle Datena us dem SharedPreference
*/
public void clearData() {
SharedPreferences.Editor spEditor = this.userLocalDatabase.edit();
spEditor.clear();
spEditor.apply();
}
/**
* Setz einen neuen Nutzernamen für den eingeloggten Nutzer
* @param userName neuer Nutzername
*/
public void setUserName(String userName) {
SharedPreferences.Editor spEditor = this.userLocalDatabase.edit();
spEditor.putString("username", userName);
spEditor.apply();
}
/**
* Setz einen neue Email-Adresse für den eingeloggten Nutzer
* @param userEmail neue Email-Adresse
*/
public void setUserEmail(String userEmail) {
SharedPreferences.Editor spEditor = this.userLocalDatabase.edit();
spEditor.putString("email", userEmail);
spEditor.apply();
}
}
package classes; package classes.apps;
import com.bluelinelabs.logansquare.annotation.JsonField; import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject; import com.bluelinelabs.logansquare.annotation.JsonObject;
import java.io.Serializable;
import co.uk.rushorm.core.RushObject;
/** /**
* Created by Christof on 23.08.2016. * Created by Christof on 23.08.2016.
*/ */
@JsonObject @JsonObject
public class AppContainer { public class AppContainer extends RushObject implements Serializable{
@JsonField(name = "id") @JsonField(name = "id")
private int appContainerId; private int appContainerId;
......
package classes; package classes.apps;
import com.bluelinelabs.logansquare.annotation.JsonField; import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject; import com.bluelinelabs.logansquare.annotation.JsonObject;
import java.io.Serializable;
import java.util.Date; import java.util.Date;
import co.uk.rushorm.core.RushObject;
/** /**
* Created by Christof on 23.08.2016. * Created by Christof on 23.08.2016.
*/ */
@JsonObject @JsonObject
public class Comment { public class Comment extends RushObject implements Serializable {
@JsonField(name = "id") @JsonField(name = "id")
private int commentID; private int commentID;
......
package classes; package classes.apps;
import com.bluelinelabs.logansquare.annotation.JsonField; import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject; import com.bluelinelabs.logansquare.annotation.JsonObject;
import java.io.Serializable;
import co.uk.rushorm.core.RushObject;
/** /**
* Created by Christof on 23.08.2016. * Created by Christof on 23.08.2016.
*/ */
@JsonObject @JsonObject
public class Feedback { public class Feedback extends RushObject implements Serializable {
@JsonField(name = "id") @JsonField(name = "id")
private int feedbackId; private int feedbackId;
......
package classes; package classes.apps;
import com.bluelinelabs.logansquare.annotation.JsonField; import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject; import com.bluelinelabs.logansquare.annotation.JsonObject;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import classes.Comment; import co.uk.rushorm.core.RushObject;
import co.uk.rushorm.core.annotations.RushList;
/** /**
* Created by Christof on 23.08.2016. * Created by Christof on 23.08.2016.
*/ */
@JsonObject @JsonObject
public class Forum { public class Forum extends RushObject implements Serializable {
@JsonField(name = "id") @JsonField(name = "id")
private int forumId; private int forumId;
@RushList(classType = Comment.class)
@JsonField(name = "comments") @JsonField(name = "comments")
private ArrayList<Comment>comments; private ArrayList<Comment>comments;
......
package classes; package classes.apps;
import com.bluelinelabs.logansquare.annotation.JsonField; import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject; import com.bluelinelabs.logansquare.annotation.JsonObject;
import java.io.Serializable;
import co.uk.rushorm.core.RushObject;
/** /**
* Created by Christof on 23.08.2016. * Created by Christof on 23.08.2016.
*/ */
@JsonObject @JsonObject
public class Materials { public class Materials extends RushObject implements Serializable {
@JsonField(name = "id") @JsonField(name = "id")
private int materialsId; private int materialsId;
......
package de.uni_oldenburg.bidl;
import android.app.Application;
import co.uk.rushorm.android.AndroidInitializeConfig;
import co.uk.rushorm.core.RushCore;
/**
* Superklasse
* @author Christof
*/
public class AppClass extends Application {
@Override
public void onCreate() {
super.onCreate();
/**
* Uncomment this to drop the whole database (version mismatch during review / testing)
* don't increment database version during basic feature-branching to prevent!
* */
//this.deleteDatabase("bidl.db");
AndroidInitializeConfig config = new AndroidInitializeConfig(getApplicationContext());
RushCore.initialize(config);
}
}
package de.uni_oldenburg.bidl.base_view; package de.uni_oldenburg.bidl.base_view;
import android.os.Handler; import android.content.Intent;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
...@@ -16,17 +17,21 @@ import java.util.List; ...@@ -16,17 +17,21 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
import classes.Event; import classes.Event;
import classes.LocalStorage;
import classes.User;
import de.uni_oldenburg.bidl.R; import de.uni_oldenburg.bidl.R;
import de.uni_oldenburg.bidl.guest_view.LoginActivity;
import services.servercommunication.NetworkService; import services.servercommunication.NetworkService;
import static de.uni_oldenburg.bidl.R.string.noBeaconFound;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
/** Tag for Logging **/ /** Tag for Logging **/
private static final String TAG = MainActivity.class.getSimpleName(); private static final String TAG = MainActivity.class.getSimpleName();
/** Soll nach Beacons gesucht werden? **/
private static final Boolean RANGING = true;
/** Estimote Beacon UUID **/ /** Estimote Beacon UUID **/
private static final UUID PROXIMITY_UUID = UUID.fromString("B9407F30-F5F8-466E-AFF9-25556B57FE6D"); private static final UUID PROXIMITY_UUID = UUID.fromString("B9407F30-F5F8-466E-AFF9-25556B57FE6D");
...@@ -34,10 +39,12 @@ public class MainActivity extends AppCompatActivity { ...@@ -34,10 +39,12 @@ public class MainActivity extends AppCompatActivity {
private TextView beaconID; private TextView beaconID;
/** values **/ /** values **/
boolean doubleBackToExitPressedOnce = false;
private Region region; private Region region;
private BeaconManager beaconManager; private BeaconManager beaconManager;
private Beacon nearestBeacon; private Beacon nearestBeacon;
private Event event;
protected LocalStorage localStorage;
...@@ -45,32 +52,44 @@ public class MainActivity extends AppCompatActivity { ...@@ -45,32 +52,44 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
/** init **/ /** init **/
beaconID = (TextView) findViewById(R.id.BeaconID); beaconID = (TextView) findViewById(R.id.BeaconID);
this.localStorage = new LocalStorage(this);
/*Weiterleitung je nach Login Status */
if(!localStorage.isLoggedIn()){
startActivity(new Intent(this, LoginActivity.class));
this.finish();
}
/** region is the hole university --> all beacons have the same proximity_UUID **/
region = new Region("ranged region", PROXIMITY_UUID, null, null);
beaconManager = new BeaconManager(this);
/** /**
* Start ranging for beacons. * Start ranging for beacons.
**/ **/
beaconManager = new BeaconManager(this); if(RANGING){
/** region is the hole university --> all beacons have the same proximity_UUID **/ beaconManager.setRangingListener(new BeaconManager.RangingListener() {
region = new Region("ranged region", PROXIMITY_UUID, null, null); @Override
beaconManager.setRangingListener(new BeaconManager.RangingListener() { public void onBeaconsDiscovered(Region region, List<Beacon> list) {
@Override if (!list.isEmpty() && !list.get(0).equals(nearestBeacon)){
public void onBeaconsDiscovered(Region region, List<Beacon> list) { // TODO: 30.07.2016 React, when the user is nearer to another Beacon.
if (!list.isEmpty() && !list.get(0).equals(nearestBeacon)){ nearestBeacon = list.get(0);
// TODO: 30.07.2016 React, when the user is nearer to another Beacon. getEventFromServer(nearestBeacon);
nearestBeacon = list.get(0); } if (list.isEmpty()){
getEventFromServer(nearestBeacon); showMessage(getResources().getString(R.string.noBeaconFound));
}
}
} if (list.isEmpty()){ });
showMessage(); }
}
}
}); }
private void setEvent(Event event) {
this.event = event;
} }
private void getEventFromServer(Beacon nearestBeacon) { private void getEventFromServer(Beacon nearestBeacon) {
...@@ -80,13 +99,19 @@ public class MainActivity extends AppCompatActivity { ...@@ -80,13 +99,19 @@ public class MainActivity extends AppCompatActivity {
NetworkService.getEvent(uud, major, minor, new NetworkService.RequestGetEventHandler() { NetworkService.getEvent(uud, major, minor, new NetworkService.RequestGetEventHandler() {
@Override @Override
public void done(final Event event) { public void done(Event event) {
MainActivity.this.runOnUiThread(new Runnable() { if (event != null){
@Override setEvent(event);
public void run() {