Commit 31e384e4 authored by Christof Wolke's avatar Christof Wolke

Andere Logik, wann das eventobject vom Server geholt wird

parent 9e9fd2b0
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
android:value="de.uni_oldenburg.bidl.classes" /> android:value="de.uni_oldenburg.bidl.classes" />
<meta-data <meta-data
android:name="Rush_db_version" android:name="Rush_db_version"
android:value="3" /> android:value="4" />
<meta-data <meta-data
android:name="Rush_db_name" android:name="Rush_db_name"
android:value="bidl.db" /> android:value="bidl.db" />
......
...@@ -25,16 +25,27 @@ public class Event extends RushObject implements Serializable { ...@@ -25,16 +25,27 @@ public class Event extends RushObject implements Serializable {
@JsonField(name = "apps") @JsonField(name = "apps")
private HashMap<String, String> apps; private HashMap<String, String> apps;
@JsonField(name = "nextStart")
private int nextStart;
@JsonField(name = "nextName")
private String nextEventName;
@JsonField(name = "currentEnd")
private int currentEnd;
public Event() { public Event() {
} }
public Event(int eventId, String name, HashMap<String, String> apps) { public Event(int eventId, String name, HashMap<String, String> apps, int nextStart, String nextEventName, int currentEnd) {
this.eventId = eventId; this.eventId = eventId;
this.name = name; this.name = name;
this.apps = apps; this.apps = apps;
this.nextStart = nextStart;
this.nextEventName = nextEventName;
this.currentEnd = currentEnd;
} }
public int getEventId() { public int getEventId() {
return eventId; return eventId;
} }
...@@ -59,12 +70,39 @@ public class Event extends RushObject implements Serializable { ...@@ -59,12 +70,39 @@ public class Event extends RushObject implements Serializable {
this.apps = apps; this.apps = apps;
} }
public int getNextStart() {
return nextStart;
}
public void setNextStart(int nextStart) {
this.nextStart = nextStart;
}
public String getNextEventName() {
return nextEventName;
}
public void setNextEventName(String nextEventName) {
this.nextEventName = nextEventName;
}
public int getCurrentEnd() {
return currentEnd;
}
public void setCurrentEnd(int currentEnd) {
this.currentEnd = currentEnd;
}
@Override @Override
public String toString() { public String toString() {
return "Event{" + return "Event{" +
"eventId=" + eventId + "eventId=" + eventId +
", name='" + name + '\'' + ", name='" + name + '\'' +
", apps=" + apps + ", apps=" + apps +
", nextStart=" + nextStart +
", nextEventName='" + nextEventName + '\'' +
", currentEnd=" + currentEnd +
'}'; '}';
} }
} }
...@@ -4,6 +4,7 @@ import com.bluelinelabs.logansquare.annotation.JsonField; ...@@ -4,6 +4,7 @@ import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject; import com.bluelinelabs.logansquare.annotation.JsonObject;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import co.uk.rushorm.core.RushObject; import co.uk.rushorm.core.RushObject;
......
...@@ -19,7 +19,9 @@ import com.estimote.sdk.Region; ...@@ -19,7 +19,9 @@ import com.estimote.sdk.Region;
import com.estimote.sdk.SystemRequirementsChecker; import com.estimote.sdk.SystemRequirementsChecker;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection; import java.util.Collection;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -59,6 +61,8 @@ public class MainActivity extends BaseActivity { ...@@ -59,6 +61,8 @@ public class MainActivity extends BaseActivity {
private ArrayAdapter<String> adapter; private ArrayAdapter<String> adapter;
private Event event; private Event event;
private HashMap<String, String> map; private HashMap<String, String> map;
private int currentEventEnd;
private int nextEventStart;
...@@ -143,6 +147,9 @@ public class MainActivity extends BaseActivity { ...@@ -143,6 +147,9 @@ public class MainActivity extends BaseActivity {
progress.show(); progress.show();
} }
/**
* Searching for the nearest Beacon and get the Event from the Server
*/
private void startRanging() { private void startRanging() {
if(RANGING && isBluetoothAvailable()){ if(RANGING && isBluetoothAvailable()){
beaconManager.setRangingListener(new BeaconManager.RangingListener() { beaconManager.setRangingListener(new BeaconManager.RangingListener() {
...@@ -150,15 +157,36 @@ public class MainActivity extends BaseActivity { ...@@ -150,15 +157,36 @@ public class MainActivity extends BaseActivity {
public void onBeaconsDiscovered(Region region, List<Beacon> list) { public void onBeaconsDiscovered(Region region, List<Beacon> list) {
noBeaconTV.setVisibility(View.INVISIBLE); noBeaconTV.setVisibility(View.INVISIBLE);
grid.setVisibility(View.VISIBLE); grid.setVisibility(View.VISIBLE);
if (!list.isEmpty() && !list.get(0).equals(nearestBeacon)){ int currentTime = getCurrentTime();
nearestBeacon = list.get(0); if (event != null){
getEventFromServer(nearestBeacon); currentEventEnd = event.getCurrentEnd();
nextEventStart = event.getNextStart();
} else{
currentEventEnd = 0;
nextEventStart = 0;
}
/**
* only do a Network call, if there is a new Beacon or if the current Event ends and
* a new Event starts
*/
if (!list.isEmpty() && !list.get(0).equals(nearestBeacon) || currentEventEnd < currentTime){
if (currentEventEnd <= currentTime && currentTime < nextEventStart){
setInformationText("In "+(nextEventStart-currentTime)+
" Minuten findet die Veranstaltung "+event.getNextEventName()+
" statt.");
setTitle(R.string.app_name);
} else if (nextEventStart == -1){
setInformationText(getString(R.string.noEventToday));
setTitle(R.string.app_name);
}
else{
nearestBeacon = list.get(0);
getEventFromServer(nearestBeacon);
}
} if (list.isEmpty()){ } if (list.isEmpty()){
progress.dismiss(); setInformationText(getString(R.string.noBeaconFound));
grid.setVisibility(View.INVISIBLE);
noBeaconTV.setText(R.string.noBeaconFound);
noBeaconTV.setVisibility(View.VISIBLE);
} }
} }
...@@ -166,6 +194,30 @@ public class MainActivity extends BaseActivity { ...@@ -166,6 +194,30 @@ public class MainActivity extends BaseActivity {
} }
} }
private void setInformationText(final String text) {
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
progress.dismiss();
grid.setVisibility(View.INVISIBLE);
noBeaconTV.setText(text);
noBeaconTV.setVisibility(View.VISIBLE);
}
});
}
/**
* Get the current Time
* @return the current Time with the format from the Server
*/
private int getCurrentTime() {
Calendar calendar = Calendar.getInstance();
Date date = calendar.getTime();
int hour = date.getHours()*60;
int minute = date.getMinutes();
return hour+minute;
}
private void getEventFromServer(Beacon nearestBeacon) { private void getEventFromServer(Beacon nearestBeacon) {
String uud = nearestBeacon.getProximityUUID().toString().toUpperCase(); String uud = nearestBeacon.getProximityUUID().toString().toUpperCase();
int major = nearestBeacon.getMajor(); int major = nearestBeacon.getMajor();
...@@ -179,7 +231,7 @@ public class MainActivity extends BaseActivity { ...@@ -179,7 +231,7 @@ public class MainActivity extends BaseActivity {
@Override @Override
public void run() { public void run() {
setTitle(event.getName()); setTitle(event.getName());
Log.d(TAG, event.getName()); currentEventEnd = event.getCurrentEnd();
map = event.getApps(); map = event.getApps();
Collection<String> appnames = map.values(); Collection<String> appnames = map.values();
updateData(appnames); updateData(appnames);
...@@ -188,8 +240,7 @@ public class MainActivity extends BaseActivity { ...@@ -188,8 +240,7 @@ public class MainActivity extends BaseActivity {
}); });
}else{ }else{
progress.dismiss(); setInformationText(getString(R.string.noCurrentEvent));
showMessage(getResources().getString(R.string.noCurrentEvent));
} }
} }
...@@ -237,22 +288,13 @@ public class MainActivity extends BaseActivity { ...@@ -237,22 +288,13 @@ public class MainActivity extends BaseActivity {
} }
public static boolean isBluetoothAvailable(){ public static boolean isBluetoothAvailable(){
final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
return (bluetoothAdapter != null && bluetoothAdapter.isEnabled()); return (bluetoothAdapter != null && bluetoothAdapter.isEnabled());
} }
private void showMessage(final String message) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
}
});
}
public void setEvent(Event event) { public void setEvent(Event event) {
this.event = event; this.event = event;
} }
......
...@@ -2,6 +2,7 @@ package de.uni_oldenburg.bidl.member_view; ...@@ -2,6 +2,7 @@ package de.uni_oldenburg.bidl.member_view;
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.view.Gravity; import android.view.Gravity;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
...@@ -62,31 +63,32 @@ public class FeedbackActivity extends AppCompatActivity { ...@@ -62,31 +63,32 @@ public class FeedbackActivity extends AppCompatActivity {
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
event = DBHelper.getEvent(); event = DBHelper.getEvent();
NetworkService.getQuestions(event.getEventId(), new NetworkService.RequestGetQuestionsHandler() { NetworkService.getQuestions(event.getEventId(), new NetworkService.RequestGetQuestionsHandler() {
@Override @Override
public void done(final List<Question> questions) { public void done(final List<Question> questions) {
if (questions != null){ if (questions != null){
setQuestions(questions); //setQuestions(questions);
FeedbackActivity.this.runOnUiThread(new Runnable() { FeedbackActivity.this.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
for (Question question : questions) { for (Question question : questions) {
initGui(question); initGui(question);
}
} }
} });
}); } else{
} else{ TextView tv = new TextView(getApplicationContext());
TextView tv = new TextView(getApplicationContext()); tv.setText(R.string.noQuestions);
tv.setText(R.string.noQuestions); tv.setGravity(Gravity.CENTER);
tv.setGravity(Gravity.CENTER); tv.setSingleLine(false);
tv.setSingleLine(false);
} }
} }
}); });
} }
......
...@@ -3,8 +3,12 @@ package services.db; ...@@ -3,8 +3,12 @@ package services.db;
import android.app.Application; import android.app.Application;
import android.content.Context; import android.content.Context;
import java.util.ArrayList;
import java.util.List;
import classes.Event; import classes.Event;
import classes.LocalStorage; import classes.LocalStorage;
import classes.apps.feedback.Question;
import co.uk.rushorm.core.RushCore; import co.uk.rushorm.core.RushCore;
import co.uk.rushorm.core.RushSearch; import co.uk.rushorm.core.RushSearch;
...@@ -46,17 +50,30 @@ public class DBHelper { ...@@ -46,17 +50,30 @@ public class DBHelper {
return event; return event;
} }
public static List<Question> getQuestions(){
List<Question> questions = new RushSearch().find(Question.class);
return questions;
}
public static Question getQuestionById(int questionId){
Question question = new RushSearch().whereEqual("questionId", questionId).findSingle(Question.class);
return question;
}
/** /**
* Löscht Recommendations, Locations, Favoriten und Check-Ins von der Datenbank * Löscht Events und Questions von der Datenbank
*/ */
public static void clearAll() { public static void clearAll() {
clearEvents(); clearEvents();
clearQuestions();
} }
private static void clearEvents() { private static void clearEvents() {
RushCore.getInstance().deleteAll(Event.class); RushCore.getInstance().deleteAll(Event.class);
} }
private static void clearQuestions(){RushCore.getInstance().deleteAll(Question.class);}
} }
...@@ -18,6 +18,7 @@ import classes.StatusResponse; ...@@ -18,6 +18,7 @@ import classes.StatusResponse;
import classes.User; import classes.User;
import classes.apps.feedback.Question; import classes.apps.feedback.Question;
import classes.apps.forum.Forum; import classes.apps.forum.Forum;
import services.db.DBHelper;
/** /**
* Helfer Klasse, die häufig verwendete I/O Operationen im Netzwerk und der Datenbank erleichtert * Helfer Klasse, die häufig verwendete I/O Operationen im Netzwerk und der Datenbank erleichtert
...@@ -132,8 +133,19 @@ public abstract class NetworkService { ...@@ -132,8 +133,19 @@ public abstract class NetworkService {
void done(String statusResponse); void done(String statusResponse);
} }
/**
* Holt sich das aktuelle event mit den zugeordneten apps, dem eventende und wann das nächste
* event in diesem Raum startet.
* @param uud
* @param major
* @param minor
* @param handler
*/
public static void getEvent(String uud, int major, int minor, final RequestGetEventHandler handler){ public static void getEvent(String uud, int major, int minor, final RequestGetEventHandler handler){
okHttpClient.setReadTimeout(15, TimeUnit.SECONDS); okHttpClient.setReadTimeout(15, TimeUnit.SECONDS);
if (DBHelper.getEvent() != null){
DBHelper.clearAll();
}
/* OkHttpClient /* OkHttpClient
Request body mit POST params Request body mit POST params
...@@ -182,6 +194,11 @@ public abstract class NetworkService { ...@@ -182,6 +194,11 @@ public abstract class NetworkService {
void done(Event event); void done(Event event);
} }
/**
* Liefert alle Kommentare der User zu dem Event.
* @param eventId
* @param handler
*/
public static void forum(int eventId, final RequestForumHandler handler){ public static void forum(int eventId, final RequestForumHandler handler){
okHttpClient.setReadTimeout(15, TimeUnit.SECONDS); okHttpClient.setReadTimeout(15, TimeUnit.SECONDS);
...@@ -222,6 +239,13 @@ public abstract class NetworkService { ...@@ -222,6 +239,13 @@ public abstract class NetworkService {
void done(Forum forum); void done(Forum forum);
} }
/**
* Speichert einen neuen Kommentar
* @param comment
* @param forumId
* @param userId
* @param handler
*/
public static void setNewComment(String comment, int forumId, int userId, final RequestNewCommentHandler handler){ public static void setNewComment(String comment, int forumId, int userId, final RequestNewCommentHandler handler){
okHttpClient.setReadTimeout(15, TimeUnit.SECONDS); okHttpClient.setReadTimeout(15, TimeUnit.SECONDS);
...@@ -265,6 +289,11 @@ public abstract class NetworkService { ...@@ -265,6 +289,11 @@ public abstract class NetworkService {
void done(String status); void done(String status);
} }
/**
* Holt sich alle Fragen mit den Antwortmöglichkeiten, die für das Event erstellt wurden.
* @param eventId
* @param handler
*/
public static void getQuestions(int eventId, final RequestGetQuestionsHandler handler){ public static void getQuestions(int eventId, final RequestGetQuestionsHandler handler){
okHttpClient.setReadTimeout(15, TimeUnit.SECONDS); okHttpClient.setReadTimeout(15, TimeUnit.SECONDS);
...@@ -291,6 +320,9 @@ public abstract class NetworkService { ...@@ -291,6 +320,9 @@ public abstract class NetworkService {
try { try {
if (response.isSuccessful()){ if (response.isSuccessful()){
List<Question> questions = LoganSquare.parseList(response.body().byteStream(), Question.class); List<Question> questions = LoganSquare.parseList(response.body().byteStream(), Question.class);
for (Question question: questions) {
question.save();
}
handler.done(questions); handler.done(questions);
} }
}catch (IOException e){ }catch (IOException e){
...@@ -306,6 +338,12 @@ public abstract class NetworkService { ...@@ -306,6 +338,12 @@ public abstract class NetworkService {
void done(List<Question> questions); void done(List<Question> questions);
} }
/**
* speichert die Antworten des Users zu jeder Frage.
* @param questionId
* @param finalAnswer
* @param handler
*/
public static void saveAnswer(int questionId, String finalAnswer, final RequestSaveAnswerHandler handler){ public static void saveAnswer(int questionId, String finalAnswer, final RequestSaveAnswerHandler handler){
okHttpClient.setReadTimeout(15, TimeUnit.SECONDS); okHttpClient.setReadTimeout(15, TimeUnit.SECONDS);
......
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
<!-- Main Activity !--> <!-- Main Activity !-->
<string name="clickAgainToExit">Erneut klicken zum Beenden!</string> <string name="clickAgainToExit">Erneut klicken zum Beenden!</string>
<string name="noCurrentEvent">In diesem Raum findet aktuell keine Veranstaltung statt</string> <string name="noCurrentEvent">In diesem Raum findet aktuell keine Veranstaltung statt!</string>
<string name="noEventToday">Heute findet in diesem Raum keine Veranstaltung mehr statt!</string>
<string name="ESTIMOTE_PROXIMITY_UUID">B9407F30-F5F8-466E-AFF9-25556B57FE6D</string> <string name="ESTIMOTE_PROXIMITY_UUID">B9407F30-F5F8-466E-AFF9-25556B57FE6D</string>
<!-- Menu --> <!-- Menu -->
......
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 to comment