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 @@
android:value="de.uni_oldenburg.bidl.classes" />
<meta-data
android:name="Rush_db_version"
android:value="3" />
android:value="4" />
<meta-data
android:name="Rush_db_name"
android:value="bidl.db" />
......
......@@ -25,16 +25,27 @@ public class Event extends RushObject implements Serializable {
@JsonField(name = "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(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.name = name;
this.apps = apps;
this.nextStart = nextStart;
this.nextEventName = nextEventName;
this.currentEnd = currentEnd;
}
public int getEventId() {
return eventId;
}
......@@ -59,12 +70,39 @@ public class Event extends RushObject implements Serializable {
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
public String toString() {
return "Event{" +
"eventId=" + eventId +
", name='" + name + '\'' +
", apps=" + apps +
", nextStart=" + nextStart +
", nextEventName='" + nextEventName + '\'' +
", currentEnd=" + currentEnd +
'}';
}
}
......@@ -4,6 +4,7 @@ import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import co.uk.rushorm.core.RushObject;
......
......@@ -19,7 +19,9 @@ import com.estimote.sdk.Region;
import com.estimote.sdk.SystemRequirementsChecker;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -59,6 +61,8 @@ public class MainActivity extends BaseActivity {
private ArrayAdapter<String> adapter;
private Event event;
private HashMap<String, String> map;
private int currentEventEnd;
private int nextEventStart;
......@@ -143,6 +147,9 @@ public class MainActivity extends BaseActivity {
progress.show();
}
/**
* Searching for the nearest Beacon and get the Event from the Server
*/
private void startRanging() {
if(RANGING && isBluetoothAvailable()){
beaconManager.setRangingListener(new BeaconManager.RangingListener() {
......@@ -150,20 +157,65 @@ public class MainActivity extends BaseActivity {
public void onBeaconsDiscovered(Region region, List<Beacon> list) {
noBeaconTV.setVisibility(View.INVISIBLE);
grid.setVisibility(View.VISIBLE);
if (!list.isEmpty() && !list.get(0).equals(nearestBeacon)){
int currentTime = getCurrentTime();
if (event != null){
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()){
setInformationText(getString(R.string.noBeaconFound));
}
}
});
}
}
private void setInformationText(final String text) {
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
progress.dismiss();
grid.setVisibility(View.INVISIBLE);
noBeaconTV.setText(R.string.noBeaconFound);
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) {
......@@ -179,7 +231,7 @@ public class MainActivity extends BaseActivity {
@Override
public void run() {
setTitle(event.getName());
Log.d(TAG, event.getName());
currentEventEnd = event.getCurrentEnd();
map = event.getApps();
Collection<String> appnames = map.values();
updateData(appnames);
......@@ -188,8 +240,7 @@ public class MainActivity extends BaseActivity {
});
}else{
progress.dismiss();
showMessage(getResources().getString(R.string.noCurrentEvent));
setInformationText(getString(R.string.noCurrentEvent));
}
}
......@@ -237,22 +288,13 @@ public class MainActivity extends BaseActivity {
}
public static boolean isBluetoothAvailable(){
final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
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) {
this.event = event;
}
......
......@@ -2,6 +2,7 @@ package de.uni_oldenburg.bidl.member_view;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
......@@ -66,7 +67,7 @@ public class FeedbackActivity extends AppCompatActivity {
@Override
public void done(final List<Question> questions) {
if (questions != null){
setQuestions(questions);
//setQuestions(questions);
FeedbackActivity.this.runOnUiThread(new Runnable() {
@Override
......@@ -88,6 +89,7 @@ public class FeedbackActivity extends AppCompatActivity {
}
});
}
......
......@@ -3,8 +3,12 @@ package services.db;
import android.app.Application;
import android.content.Context;
import java.util.ArrayList;
import java.util.List;
import classes.Event;
import classes.LocalStorage;
import classes.apps.feedback.Question;
import co.uk.rushorm.core.RushCore;
import co.uk.rushorm.core.RushSearch;
......@@ -46,17 +50,30 @@ public class DBHelper {
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() {
clearEvents();
clearQuestions();
}
private static void clearEvents() {
RushCore.getInstance().deleteAll(Event.class);
}
private static void clearQuestions(){RushCore.getInstance().deleteAll(Question.class);}
}
......@@ -18,6 +18,7 @@ import classes.StatusResponse;
import classes.User;
import classes.apps.feedback.Question;
import classes.apps.forum.Forum;
import services.db.DBHelper;
/**
* Helfer Klasse, die häufig verwendete I/O Operationen im Netzwerk und der Datenbank erleichtert
......@@ -132,8 +133,19 @@ public abstract class NetworkService {
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){
okHttpClient.setReadTimeout(15, TimeUnit.SECONDS);
if (DBHelper.getEvent() != null){
DBHelper.clearAll();
}
/* OkHttpClient
Request body mit POST params
......@@ -182,6 +194,11 @@ public abstract class NetworkService {
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){
okHttpClient.setReadTimeout(15, TimeUnit.SECONDS);
......@@ -222,6 +239,13 @@ public abstract class NetworkService {
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){
okHttpClient.setReadTimeout(15, TimeUnit.SECONDS);
......@@ -265,6 +289,11 @@ public abstract class NetworkService {
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){
okHttpClient.setReadTimeout(15, TimeUnit.SECONDS);
......@@ -291,6 +320,9 @@ public abstract class NetworkService {
try {
if (response.isSuccessful()){
List<Question> questions = LoganSquare.parseList(response.body().byteStream(), Question.class);
for (Question question: questions) {
question.save();
}
handler.done(questions);
}
}catch (IOException e){
......@@ -306,6 +338,12 @@ public abstract class NetworkService {
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){
okHttpClient.setReadTimeout(15, TimeUnit.SECONDS);
......
......@@ -8,7 +8,8 @@
<!-- Main Activity !-->
<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>
<!-- 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