Commit 4d0d3c8f authored by Christof Wolke's avatar Christof Wolke

favorite feature beendet

parent 058d5b3d
......@@ -24,7 +24,7 @@
android:value="de.uni_oldenburg.bidl.classes" />
<meta-data
android:name="Rush_db_version"
android:value="6" />
android:value="1" />
<meta-data
android:name="Rush_db_name"
android:value="bidl.db" />
......
......@@ -5,8 +5,10 @@ import com.bluelinelabs.logansquare.annotation.JsonObject;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import co.uk.rushorm.core.RushObject;
import co.uk.rushorm.core.annotations.RushList;
/**
* Created by Christof on 23.08.2016.
......@@ -33,18 +35,23 @@ public class Event extends RushObject implements Serializable {
@JsonField(name = "currentEnd")
private int currentEnd;
@JsonField(name = "eventTimes")
@RushList(classType = EventTime.class)
private List<EventTime> eventTimeList;
public Event() {
}
public Event(int eventId, String name, HashMap<String, String> apps, int nextStart,
String nextEventName, int currentEnd) {
public Event(int eventId, String name, HashMap<String, String> apps,
int nextStart, String nextEventName, int currentEnd, List<EventTime> eventTimeList) {
this.eventId = eventId;
this.name = name;
this.apps = apps;
this.nextStart = nextStart;
this.nextEventName = nextEventName;
this.currentEnd = currentEnd;
this.eventTimeList = eventTimeList;
}
public int getEventId() {
......@@ -95,6 +102,13 @@ public class Event extends RushObject implements Serializable {
this.currentEnd = currentEnd;
}
public List<EventTime> getEventTimeList() {
return eventTimeList;
}
public void setEventTimeList(List<EventTime> eventTimeList) {
this.eventTimeList = eventTimeList;
}
@Override
public String toString() {
......@@ -105,6 +119,7 @@ public class Event extends RushObject implements Serializable {
", nextStart=" + nextStart +
", nextEventName='" + nextEventName + '\'' +
", currentEnd=" + currentEnd +
", eventTimeList=" + eventTimeList +
'}';
}
}
......@@ -9,6 +9,9 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import java.util.Calendar;
import java.util.Date;
import classes.apps.event.Event;
import classes.LocalStorage;
import de.uni_oldenburg.bidl.guest_view.LoginActivity;
......@@ -99,8 +102,12 @@ public class BaseActivity extends AppCompatActivity implements NavigationView.On
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
Event event = DBHelper.getEvent();
if(event !=null){
sendIntent.putExtra(Intent.EXTRA_TEXT, "Ich sitze gerade in der Veranstaltung "+event.getName()+".");
if(event != null ){
if (event.getCurrentEnd() >= getCurrentTime()){
sendIntent.putExtra(Intent.EXTRA_TEXT, "Ich sitze gerade in der Veranstaltung "+event.getName()+".");
} else {
sendIntent.putExtra(Intent.EXTRA_TEXT, "Ich benutze gerade die Bidl App der Universität Oldenburg!");
}
} else {
sendIntent.putExtra(Intent.EXTRA_TEXT, "Ich benutze gerade die Bidl App der Universität Oldenburg!");
}
......@@ -126,4 +133,16 @@ public class BaseActivity extends AppCompatActivity implements NavigationView.On
public void setDrawerLayout(int drawerLayout) {
this.drawerLayout = drawerLayout;
}
/**
* Get the current Time
* @return the current Time with the format from the Server
*/
public int getCurrentTime() {
Calendar calendar = Calendar.getInstance();
Date date = calendar.getTime();
int hour = date.getHours()*60;
int minute = date.getMinutes();
return hour+minute;
}
}
......@@ -3,13 +3,18 @@ package de.uni_oldenburg.bidl.home_view;
import android.app.ProgressDialog;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.nfc.Tag;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;
import com.estimote.sdk.Beacon;
import com.estimote.sdk.BeaconManager;
......@@ -25,8 +30,10 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import classes.User;
import classes.apps.event.Event;
import classes.LocalStorage;
import classes.apps.event.Favorite;
import de.uni_oldenburg.bidl.BaseActivity;
import de.uni_oldenburg.bidl.R;
import de.uni_oldenburg.bidl.guest_view.LoginActivity;
......@@ -58,6 +65,7 @@ public class MainActivity extends BaseActivity {
private ArrayList<String> apps = new ArrayList<>();
private ArrayAdapter<String> adapter;
private Event event;
private User user;
private HashMap<String, String> map;
private int currentEventEnd;
private int nextEventStart;
......@@ -86,6 +94,7 @@ public class MainActivity extends BaseActivity {
this.finish();
} else {
setProgressDialog();
user = localStorage.getLoggedInUser();
}
/** region is the hole university --> all beacons have the same proximity_UUID **/
......@@ -96,8 +105,14 @@ public class MainActivity extends BaseActivity {
if (getIntent().getExtras() != null){
setRanging(false);
Event event = (Event) getIntent().getSerializableExtra("event");
initGui(event);
if (getIntent().getSerializableExtra("event") != null){
Event event = (Event) getIntent().getSerializableExtra("event");
initGui(event);
} else if (getIntent().getSerializableExtra("favorite") != null){
Favorite favorite = (Favorite) getIntent().getSerializableExtra("favorite");
getEventById(favorite);
}
}
/**
......@@ -112,9 +127,63 @@ public class MainActivity extends BaseActivity {
*/
makeGridItemClickable();
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fabMain);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
if(event != null) {
NetworkService.addFavorite(user.getUserId(), event.getEventId(), event.getName(),
event.getEventTimeList(), new NetworkService.AddFavoriteHandler() {
@Override
public void done(final String status) {
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
Log.d(TAG, status);
if(status.equals("connection_error")){
showToastMessage(getString(R.string.noConnection));
} else if (status.equals("error")){
showToastMessage(getString(R.string.couldNotSaveFavorite));
} else{
Snackbar.make(view, event.getName() + " wurde zu Ihren Favoriten hinzugefügt!",
Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
}
});
}
});
} else{
showToastMessage(getString(R.string.findEventToSaveAsFavorite));
}
}
});
}
private void getEventById(Favorite favorite) {
NetworkService.getEventById(favorite.getFavoriteId(), new NetworkService.RequestGetEventByIdHandler() {
@Override
public void done(final Event event) {
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
if (event != null){
setEvent(event);
initGui(event);
} else {
Toast.makeText(getApplicationContext(), getString(R.string.noConnection), Toast.LENGTH_SHORT).show();
}
}
});
}
});
}
private void makeGridItemClickable() {
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
......@@ -195,6 +264,7 @@ public class MainActivity extends BaseActivity {
}
} if (list.isEmpty()){
event = null;
setInformationText(getString(R.string.noBeaconFound));
}
}
......@@ -215,24 +285,12 @@ public class MainActivity extends BaseActivity {
});
}
/**
* 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) {
String uud = nearestBeacon.getProximityUUID().toString().toUpperCase();
int major = nearestBeacon.getMajor();
int minor = nearestBeacon.getMinor();
NetworkService.getEvent(uud, major, minor, new NetworkService.RequestGetEventHandler() {
NetworkService.getEventByBeacon(uud, major, minor, new NetworkService.RequestGetEventHandler() {
@Override
public void done(final Event event) {
if (event != null){
......@@ -256,6 +314,7 @@ public class MainActivity extends BaseActivity {
private void initGui(Event event) {
progress.dismiss();
event.save();
setEvent(event);
setTitle(event.getName());
currentEventEnd = event.getCurrentEnd();
map = event.getApps();
......@@ -317,4 +376,10 @@ public class MainActivity extends BaseActivity {
public void setRanging(boolean RANGING) {
this.RANGING = RANGING;
}
public void showToastMessage(final String message){
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
}
}
package de.uni_oldenburg.bidl.member_view;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
......@@ -11,6 +12,7 @@ import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;
......@@ -25,6 +27,7 @@ import classes.User;
import classes.apps.event.Event;
import classes.apps.event.Favorite;
import de.uni_oldenburg.bidl.R;
import de.uni_oldenburg.bidl.home_view.MainActivity;
import de.uni_oldenburg.bidl.listfragment.EventTimeAdapter;
import services.ViewHelper.SwipeDismissListViewTouchListener;
import services.db.DBHelper;
......@@ -52,15 +55,6 @@ public class FavoriteActivity extends AppCompatActivity {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
enableSwipeDismiss();
}
......@@ -109,7 +103,7 @@ public class FavoriteActivity extends AppCompatActivity {
FavoriteActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
if (favoriteList.size() > 0 ){
if (favoriteList != null ){
setFavoriteList(favoriteList);
addListView();
} else {
......@@ -155,6 +149,18 @@ public class FavoriteActivity extends AppCompatActivity {
}
public void sendFavoriteToHomeActivity(View view){
View parentRow = (View) view.getParent();
final int position = listView.getPositionForView(parentRow);
String eventName = (String) listView.getItemAtPosition(position);
for (Favorite favorite : favoriteList){
if (favorite.getName().equals(eventName)){
startActivity(new Intent(getApplicationContext(), MainActivity.class).putExtra("favorite",favorite));
}
}
}
}
......@@ -18,6 +18,7 @@ import classes.apps.materials.Materials;
import de.uni_oldenburg.bidl.R;
import services.db.DBHelper;
import services.servercommunication.NetworkService;
import services.servercommunication.REST;
public class MaterialsActivity extends AppCompatActivity {
......@@ -56,7 +57,7 @@ public class MaterialsActivity extends AppCompatActivity {
String filename = (String) adapterView.getItemAtPosition(position);
String filePath = map.get(filename);
Uri uri = Uri.parse("http://192.168.1.2/"+filePath);
Uri uri = Uri.parse(REST.FULL_URL+filePath);
/* try
{
......@@ -72,7 +73,7 @@ public class MaterialsActivity extends AppCompatActivity {
webview = new WebView(MaterialsActivity.this);
webview.getSettings().setJavaScriptEnabled(true);
//// TODO: 13.09.2016 load the right url!
webview.loadUrl("https://docs.google.com/gview?embedded=true&url=http://192.168.1.2/MC-VL00-Organisatorisches-WS1415");
webview.loadUrl("https://docs.google.com/gview?embedded=true&url="+uri);
setContentView(webview);
}
......
......@@ -28,6 +28,7 @@ public class SearchActivity extends BaseActivity implements ListCommunicator {
private ArrayList<Event> events;
private ListView eventContainer;
private ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -72,7 +73,6 @@ public class SearchActivity extends BaseActivity implements ListCommunicator {
private void onStartSearchAction(String query) {
View view = SearchActivity.this.getCurrentFocus();
// view.clearFocus();
if (view != null){
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
......@@ -105,15 +105,20 @@ public class SearchActivity extends BaseActivity implements ListCommunicator {
}
}
private void searchForEvents(String eventName){
private void searchForEvents(final String eventName){
NetworkService.searchEvents(eventName, new NetworkService.RequestSearchEventsHandler() {
@Override
public void done(final ArrayList<Event> events) {
SearchActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
setEvents(events);
addEventFragment();
if (events.size() > 0){
setEvents(events);
addEventFragment();
} else {
eventContainer.setAdapter(null);
Toast.makeText(getApplicationContext(), getString(R.string.noEventFound), Toast.LENGTH_SHORT).show();
}
}
});
}
......@@ -129,7 +134,7 @@ public class SearchActivity extends BaseActivity implements ListCommunicator {
for (Event event : events){
eventNames.add(event.getName());
}
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,R.layout.event_item, R.id.eventName, eventNames);
adapter = new ArrayAdapter<>(this,R.layout.event_item, R.id.eventName, eventNames);
eventContainer.setAdapter(adapter);
}
}catch (NullPointerException e){
......
......@@ -2,6 +2,7 @@ package services.db;
import android.app.Application;
import android.content.Context;
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
......@@ -10,7 +11,9 @@ import classes.apps.event.Event;
import classes.LocalStorage;
import classes.apps.event.Favorite;
import classes.apps.feedback.Question;
import co.uk.rushorm.core.Rush;
import co.uk.rushorm.core.RushCore;
import co.uk.rushorm.core.RushObject;
import co.uk.rushorm.core.RushSearch;
/**
......@@ -78,13 +81,33 @@ public class DBHelper {
return favorites;
}
/**
* Gibt einen Favoriten für ein bestimmtes Event (falls vorhanden)
* @param eventId ID des Events für den das Favoriten Object geliefert werden soll
* @return Wenn vorhanden: Favoriten Object, sonst null
*/
public static Favorite getFavoriteByEventId(long eventId) {
Favorite favorite = new RushSearch().whereEqual("favoriteId", eventId).findSingle(Favorite.class);
return favorite;
}
/**
* Löscht einen Favoriten aus der DB
* @param eventId favorite der gelöscht werden soll.
*/
public static void removeFavoriteById(int eventId){
Favorite favorite = new RushSearch().whereEqual("favoriteId", eventId).findSingle(Favorite.class);
favorite.delete();
}
public static void clearFavorites(){RushCore.getInstance().deleteAll(Favorite.class);}
/**
* Löscht Events und Questions von der Datenbank
*/
public static void clearAll() {
clearEvents();
clearQuestions();
clearFavorites();
}
private static void clearEvents() {
......@@ -93,7 +116,6 @@ public class DBHelper {
private static void clearQuestions(){RushCore.getInstance().deleteAll(Question.class);}
private static void clearFavorites(){RushCore.getInstance().deleteAll(Favorite.class);}
}
......@@ -19,6 +19,7 @@ import java.util.concurrent.TimeUnit;
import classes.apps.event.Event;
import classes.StatusResponse;
import classes.User;
import classes.apps.event.EventTime;
import classes.apps.event.Favorite;
import classes.apps.feedback.Question;
import classes.apps.forum.Forum;
......@@ -146,7 +147,7 @@ public abstract class NetworkService {
* @param minor
* @param handler
*/
public static void getEvent(String uud, int major, int minor, final RequestGetEventHandler handler){
public static void getEventByBeacon(String uud, int major, int minor, final RequestGetEventHandler handler){
okHttpClient.setReadTimeout(15, TimeUnit.SECONDS);
if (DBHelper.getEvent() != null){
DBHelper.clearAll();
......@@ -162,7 +163,7 @@ public abstract class NetworkService {
.build();
/* add body to POST-request */
Request req = new Request.Builder()
.url(REST.SPRING_GETEVENT)
.url(REST.SPRING_GETEVENTBYBEACON)
.post(requestBody)
.build();
/* Server call preparation */
......@@ -183,7 +184,7 @@ public abstract class NetworkService {
String responseString = response.body().string();
Event event = LoganSquare.parse(responseString, Event.class);
if (event != null)
//event.save();
event.save();
handler.done(event);
}
}catch (IOException e){
......@@ -199,6 +200,62 @@ public abstract class NetworkService {
void done(Event event);
}
/**
* Holt sich ein event mit den zugeordneten apps.
* @param eventId
* @param handler
*/
public static void getEventById(int eventId, final RequestGetEventByIdHandler handler){
okHttpClient.setReadTimeout(15, TimeUnit.SECONDS);
if (DBHelper.getEvent() != null){
DBHelper.clearAll();
}
/* OkHttpClient
Request body mit POST params
*/
RequestBody requestBody = new FormEncodingBuilder()
.add("eventId",String.valueOf(eventId))
.build();
/* add body to POST-request */
Request req = new Request.Builder()
.url(REST.SPRING_GETEVENTBYID)
.post(requestBody)
.build();
/* Server call preparation */
Call call = okHttpClient.newCall(req);
/* Async call */
call.enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
handler.done(null);
e.printStackTrace();
}
@Override
public void onResponse(Response response) throws IOException {
try {
/* Server response parsing */
if (response.isSuccessful()){
String responseString = response.body().string();
Event event = LoganSquare.parse(responseString, Event.class);
if (event != null)
event.save();
handler.done(event);
}
}catch (IOException e){
handler.done(null);
e.printStackTrace();
}
}
});
}
public interface RequestGetEventByIdHandler {
void done(Event event);
}
/**
* Liefert alle Kommentare der User zu dem Event.
* @param eventId
......@@ -682,7 +739,7 @@ public abstract class NetworkService {
public static void fetchFavoriteList(int userId, final FetchFavoriteListHandler handler) {
okHttpClient.setReadTimeout(15, TimeUnit.SECONDS);
if (!ConnectionHelper.isNetworkAvailable() && DBHelper.getFavoriteList() == null && DBHelper.getFavoriteList().size() > 0) {
if (!ConnectionHelper.isNetworkAvailable() && DBHelper.getFavoriteList() != null && DBHelper.getFavoriteList().size() > 0) {
handler.done(DBHelper.getFavoriteList());
} else{
/* OkHttpClient */
......@@ -714,6 +771,7 @@ public abstract class NetworkService {
List<Favorite> favoriteListFromServer = LoganSquare.parseList(response.body().byteStream(), Favorite.class);
if (favoriteListFromServer != null) {
DBHelper.clearFavorites();
/* save new Favorites to DB */
for (Favorite favorite : favoriteListFromServer) {
favorite.save();
......@@ -745,7 +803,7 @@ public abstract class NetworkService {
* @param eventId Id des Events, die aus der Favoritenliste entfernt werden sol
* @param handler Callback handler
*/
public static void removeFavorite(int userId, int eventId, final RemoveFavoriteHandler handler) {
public static void removeFavorite(int userId, final int eventId, final RemoveFavoriteHandler handler) {
okHttpClient.setReadTimeout(15, TimeUnit.SECONDS);
// Request an Server
......@@ -776,6 +834,7 @@ public abstract class NetworkService {
if (response.isSuccessful()) {
StatusResponse statusResponse = LoganSquare.parse(response.body().byteStream(), StatusResponse.class);
handler.done(statusResponse.getStatus());
DBHelper.removeFavoriteById(eventId);
}
} catch (IOException e) {
handler.done("parsing_failed");
......@@ -791,4 +850,62 @@ public abstract class NetworkService {
public interface RemoveFavoriteHandler {
void done(String status);
}
/**
* Fügt einem Nutzer neuen Favoriten hinzu
*
* @param userId Id des Nutzers
* @param eventId Id des Events das favorisiert wird
* @param handler Callback handler
*/
public static void addFavorite(long userId, long eventId, String name, List<EventTime> eventTimes, final AddFavoriteHandler handler) {
// Speichere Favorite Local
final Favorite favorite = new Favorite((int) eventId, name, eventTimes);
// Request an Server
RequestBody requestBody = new FormEncodingBuilder()
.add("userId", Long.toString(userId))
.add("eventId", Long.toString(eventId))
.build();
/* add body to POST-request */
Request req = new Request.Builder()
.url(REST.SPRING_FAVORITE_ADD)
.post(requestBody)
.build();
/* Server call preparation*/
Call call = okHttpClient.newCall(req);
/* ASync call */
call.enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
handler.done("connection_error");
e.printStackTrace();
}
@Override
public void onResponse(Response response) throws IOException {
try {
/* server response parsing */
if (response.isSuccessful()) {
StatusResponse statusResponse = LoganSquare.parse(response.body().byteStream(), StatusResponse.class);
if(statusResponse.getStatus().equals("ok")) {
favorite.save();
}
handler.done(statusResponse.getStatus());
} else {
handler.done("error");
}
} catch (IOException e) {
handler.done("parsing_failed");
e.printStackTrace();
}
}
});
}
public interface AddFavoriteHandler {
void done(String status);
}
}
......@@ -32,8 +32,11 @@ public abstract class REST {
public static String SPRING_REGISTER = FULL_URL + REGISTER;
//Event path
private static final String GETEVENT = "/getEvent";
public static String SPRING_GETEVENT = FULL_URL + GETEVENT;
private static final String GETEVENTBYBEACON = "/getEventByBeacon";
public static String SPRING_GETEVENTBYBEACON = FULL_URL + GETEVENTBYBEACON;
private static final String GETEVENTBYID = "/getEventById";
public static String SPRING_GETEVENTBYID = FULL_URL + GETEVENTBYID;