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 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
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_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
android:name="de.uni_oldenburg.bidl.AppClass"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
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
android:name=".base_view.MainActivity"
android:label="Home"
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:name="de.uni_oldenburg.bidl.base_view.MainActivity"
android:label="Bidl"
android:screenOrientation="sensorPortrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".guest_view.LoginActivity" />
<activity android:name=".guest_view.RegisterActivity"></activity>
<activity android:name="de.uni_oldenburg.bidl.guest_view.LoginActivity"
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>
</manifest>
\ No newline at end of file
......@@ -3,11 +3,17 @@ package classes;
import com.bluelinelabs.logansquare.annotation.JsonField;
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.
*/
@JsonObject
public class Event {
public class Event extends RushObject implements Serializable {
@JsonField(name = "id")
private int eventId;
......@@ -15,6 +21,7 @@ public class Event {
@JsonField(name = "name")
private String name;
@JsonField(name = "appContainer")
private AppContainer appContainer;
......@@ -27,6 +34,7 @@ public class Event {
this.appContainer = appContainer;
}
public int getEventId() {
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.JsonObject;
import java.io.Serializable;
import co.uk.rushorm.core.RushObject;
/**
* Created by Christof on 23.08.2016.
*/
@JsonObject
public class AppContainer {
public class AppContainer extends RushObject implements Serializable{
@JsonField(name = "id")
private int appContainerId;
......
package classes;
package classes.apps;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import java.io.Serializable;
import java.util.Date;
import co.uk.rushorm.core.RushObject;
/**
* Created by Christof on 23.08.2016.
*/
@JsonObject
public class Comment {
public class Comment extends RushObject implements Serializable {
@JsonField(name = "id")
private int commentID;
......
package classes;
package classes.apps;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import java.io.Serializable;
import co.uk.rushorm.core.RushObject;
/**
* Created by Christof on 23.08.2016.
*/
@JsonObject
public class Feedback {
public class Feedback extends RushObject implements Serializable {
@JsonField(name = "id")
private int feedbackId;
......
package classes;
package classes.apps;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import java.io.Serializable;
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.
*/
@JsonObject
public class Forum {
public class Forum extends RushObject implements Serializable {
@JsonField(name = "id")
private int forumId;
@RushList(classType = Comment.class)
@JsonField(name = "comments")
private ArrayList<Comment>comments;
......
package classes;
package classes.apps;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import java.io.Serializable;
import co.uk.rushorm.core.RushObject;
/**
* Created by Christof on 23.08.2016.
*/
@JsonObject
public class Materials {
public class Materials extends RushObject implements Serializable {
@JsonField(name = "id")
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;
import android.os.Handler;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
......@@ -16,17 +17,21 @@ import java.util.List;
import java.util.UUID;
import classes.Event;
import classes.LocalStorage;
import classes.User;
import de.uni_oldenburg.bidl.R;
import de.uni_oldenburg.bidl.guest_view.LoginActivity;
import services.servercommunication.NetworkService;
import static de.uni_oldenburg.bidl.R.string.noBeaconFound;
public class MainActivity extends AppCompatActivity {
/** Tag for Logging **/
private static final String TAG = MainActivity.class.getSimpleName();
/** Soll nach Beacons gesucht werden? **/
private static final Boolean RANGING = true;
/** Estimote Beacon UUID **/
private static final UUID PROXIMITY_UUID = UUID.fromString("B9407F30-F5F8-466E-AFF9-25556B57FE6D");
......@@ -34,10 +39,12 @@ public class MainActivity extends AppCompatActivity {
private TextView beaconID;
/** values **/
boolean doubleBackToExitPressedOnce = false;
private Region region;
private BeaconManager beaconManager;
private Beacon nearestBeacon;
private Event event;
protected LocalStorage localStorage;
......@@ -45,32 +52,44 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/** init **/
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.
**/
beaconManager = new BeaconManager(this);
/** region is the hole university --> all beacons have the same proximity_UUID **/
region = new Region("ranged region", PROXIMITY_UUID, null, null);
beaconManager.setRangingListener(new BeaconManager.RangingListener() {
@Override
public void onBeaconsDiscovered(Region region, List<Beacon> list) {
if (!list.isEmpty() && !list.get(0).equals(nearestBeacon)){
// TODO: 30.07.2016 React, when the user is nearer to another Beacon.
nearestBeacon = list.get(0);
getEventFromServer(nearestBeacon);
if(RANGING){
beaconManager.setRangingListener(new BeaconManager.RangingListener() {
@Override
public void onBeaconsDiscovered(Region region, List<Beacon> list) {
if (!list.isEmpty() && !list.get(0).equals(nearestBeacon)){
// TODO: 30.07.2016 React, when the user is nearer to another Beacon.
nearestBeacon = list.get(0);
getEventFromServer(nearestBeacon);
} if (list.isEmpty()){
showMessage(getResources().getString(R.string.noBeaconFound));
}
}
} if (list.isEmpty()){
showMessage();
});
}
}
}
});
}
private void setEvent(Event event) {
this.event = event;
}
private void getEventFromServer(Beacon nearestBeacon) {
......@@ -80,13 +99,19 @@ public class MainActivity extends AppCompatActivity {
NetworkService.getEvent(uud, major, minor, new NetworkService.RequestGetEventHandler() {
@Override
public void done(final Event event) {
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
beaconID.setText(event.getName());
}
});
public void done(Event event) {
if (event != null){
setEvent(event);
}else{
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), "aktuell findet keine Veranstaltung statt", Toast.LENGTH_SHORT).show();
}
});
}
}
});
......@@ -96,6 +121,7 @@ public class MainActivity extends AppCompatActivity {
protected void onResume(){
super.onResume();
// is Bluetooth on, is Location on, etc.
//TODO: only check if Bluethooth is on.
SystemRequirementsChecker.checkWithDefaultDialogs(this);
// Start ranging for beacons, when the activity appears on the screen
beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
......@@ -118,28 +144,11 @@ public class MainActivity extends AppCompatActivity {
super.onPause();
}
@Override
public void onBackPressed() {
if (doubleBackToExitPressedOnce) {
super.onBackPressed();
this.finishAffinity();
return;
}
this.doubleBackToExitPressedOnce = true;
Toast.makeText(this, getString(R.string.clickAgainToExit), Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
doubleBackToExitPressedOnce = false;
}
}, 2000);
}
private void showMessage() {
Toast.makeText(this, noBeaconFound, Toast.LENGTH_SHORT).show();
private void showMessage(String message) {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}
}
package de.uni_oldenburg.bidl.base_view;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.estimote.sdk.Beacon;
import com.estimote.sdk.BeaconManager;
import com.estimote.sdk.Region;
import com.estimote.sdk.SystemRequirementsChecker;
import java.util.List;
import java.util.UUID;
import de.uni_oldenburg.bidl.R;
import de.uni_oldenburg.bidl.guest_view.LoginActivity;
import pl.droidsonroids.gif.GifImageView;
import static de.uni_oldenburg.bidl.R.string.noBeaconFound;
public class SplashActivity extends AppCompatActivity {
/** Estimote Beacon UUID **/
private static final UUID PROXIMITY_UUID = UUID.fromString("B9407F30-F5F8-466E-AFF9-25556B57FE6D");
/** Tag for Logging **/
private static final String TAG = SplashActivity.class.getSimpleName();
/** GUI **/
private ImageView uniLogo;
private GifImageView loadingSpinner;
private TextView splashMessage;
/** Values **/
private Region region;
private BeaconManager beaconManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
/** init **/
uniLogo = (ImageView) findViewById(R.id.uniLogo);
loadingSpinner = (GifImageView) findViewById(R.id.loadingSpinner);
splashMessage = (TextView) findViewById(R.id.splashText);
/** Fullscreen modus **/
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN);
/**
* Start ranging for beacons.
**/
beaconManager = new BeaconManager(this);
beaconManager.setForegroundScanPeriod(7000,5000);
beaconManager.setRangingListener(new BeaconManager.RangingListener() {
@Override
public void onBeaconsDiscovered(Region region, List<Beacon> list) {
if (!list.isEmpty()){
Beacon nearestBeacon = list.get(0);
toLoginActivity();
// TODO: 30.07.2016 save the Beacon in the database and overwrite the DB, when the nearestBeacon != the saved beacon.
} if (list.isEmpty()){
showMessage();
toLoginActivity();
}
}
});
region = new Region("ranged region", PROXIMITY_UUID, null, null);
//// TODO: 29.07.2016 Servercall to get the Event, which takes place, get the Beacon from the Database.
// TODO: 30.07.2016 React, when the user is nearer to another Beacon.
}
@Override
protected void onResume(){
super.onResume();
// is Bluetooth on, is Location on, etc.
SystemRequirementsChecker.checkWithDefaultDialogs(this);
// Start ranging for beacons, when the activity appears on the screen
beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
@Override
public void onServiceReady() {
beaconManager.startRanging(region);
}
});
}
/**
* Ranging ist stopped, if the Activity disappears.
*/
@Override
public void onPause(){
beaconManager.stopRanging(region);
super.onPause();
}
private void toLoginActivity() {
startActivity(new Intent(this, LoginActivity.class));
}
private void showMessage() {
Toast.makeText(this, noBeaconFound, Toast.LENGTH_SHORT).show();
}
}
......@@ -13,6 +13,7 @@ import android.widget.Toast;
import com.estimote.sdk.SystemRequirementsChecker;
import classes.LocalStorage;
import classes.User;
import de.uni_oldenburg.bidl.R;
import de.uni_oldenburg.bidl.base_view.MainActivity;
......@@ -29,6 +30,8 @@ public class LoginActivity extends AppCompatActivity {
private Button btLogin;
private TextView tvRegister;
private LocalStorage localStorage;
/** values **/
private String email;
private String password;
......@@ -52,6 +55,8 @@ public class LoginActivity extends AppCompatActivity {
tvRegister = (TextView) findViewById(R.id.register);
/** Login **/