Commit 0216b832 authored by Christof Wolke's avatar Christof Wolke

SearchActivity and Materials

parent 31e384e4
......@@ -70,10 +70,13 @@
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".member_view.MaterialsActivity" />
<activity android:name=".member_view.SearchActivity"></activity>
</application>
</manifest>
\ No newline at end of file
......@@ -4,7 +4,6 @@ import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import co.uk.rushorm.core.RushObject;
......@@ -34,10 +33,12 @@ public class Event extends RushObject implements Serializable {
@JsonField(name = "currentEnd")
private int currentEnd;
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) {
this.eventId = eventId;
this.name = name;
this.apps = apps;
......@@ -94,6 +95,7 @@ public class Event extends RushObject implements Serializable {
this.currentEnd = currentEnd;
}
@Override
public String toString() {
return "Event{" +
......
......@@ -4,6 +4,8 @@ import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import co.uk.rushorm.core.RushObject;
......@@ -13,22 +15,19 @@ import co.uk.rushorm.core.RushObject;
@JsonObject
public class Materials extends RushObject implements Serializable {
@JsonField(name = "id")
private int materialsId;
@JsonField(name = "title")
private String title;
@JsonField(name = "urls")
private HashMap<String, String> urls;
@JsonField(name = "url")
private String url;
@JsonField(name = "id")
private int materialsId;
public Materials() {
}
public Materials(int materialsId, String title, String url) {
public Materials(int materialsId, HashMap<String, String> urls) {
this.materialsId = materialsId;
this.title = title;
this.url = url;
this.urls = urls;
}
public int getMaterialsId() {
......@@ -39,28 +38,19 @@ public class Materials extends RushObject implements Serializable {
this.materialsId = materialsId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getUrl() {
return url;
public HashMap<String, String> getUrls() {
return urls;
}
public void setUrl(String url) {
this.url = url;
public void setUrls(HashMap<String, String> urls) {
this.urls = urls;
}
@Override
public String toString() {
return "Materials{" +
"materialsId=" + materialsId +
", title='" + title + '\'' +
", url='" + url + '\'' +
", url=" + urls +
'}';
}
}
......@@ -13,6 +13,7 @@ import classes.Event;
import classes.LocalStorage;
import de.uni_oldenburg.bidl.guest_view.LoginActivity;
import de.uni_oldenburg.bidl.home_view.MainActivity;
import de.uni_oldenburg.bidl.member_view.SearchActivity;
import services.db.DBHelper;
/**
......@@ -58,7 +59,7 @@ public class BaseActivity extends AppCompatActivity implements NavigationView.On
int id = item.getItemId();
if (id == R.id.nav_search) {
//ToDo: toSearcheActivity
toSearchActivity();
} else if (id == R.id.nav_home) {
toHomeActivity();
} else if (id == R.id.nav_profil) {
......@@ -76,6 +77,10 @@ public class BaseActivity extends AppCompatActivity implements NavigationView.On
return true;
}
private void toSearchActivity() {
startActivity(new Intent(this, SearchActivity.class));
}
protected void shareEvent() {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
......
......@@ -32,6 +32,7 @@ import classes.LocalStorage;
import de.uni_oldenburg.bidl.BaseActivity;
import de.uni_oldenburg.bidl.R;
import de.uni_oldenburg.bidl.guest_view.LoginActivity;
import services.db.DBHelper;
import services.servercommunication.NetworkService;
public class MainActivity extends BaseActivity {
......@@ -40,7 +41,7 @@ public class MainActivity extends BaseActivity {
private static final String TAG = MainActivity.class.getSimpleName();
/** Soll nach Beacons gesucht werden? **/
private static final Boolean RANGING = true;
private static Boolean RANGING = true;
/** Package, wo die apps angelegt werden **/
private static final String appPackage = "de.uni_oldenburg.bidl.member_view.";
......@@ -94,16 +95,26 @@ public class MainActivity extends BaseActivity {
beaconManager.setForegroundScanPeriod(4000, 1000);
setProgressDialog();
if (getIntent().getExtras() != null){
setRanging(false);
Event event = (Event) getIntent().getSerializableExtra("event");
initGui(event);
}
/**
* Start ranging for beacons.
**/
startRanging();
Log.d(TAG, RANGING.toString());
if(RANGING && isBluetoothAvailable()){
startRanging();
}
/**
* open activity based on the griditem, displayed at the MainActivity
*/
makeGridItemClickable();
}
private void makeGridItemClickable() {
......@@ -151,7 +162,6 @@ public class MainActivity extends BaseActivity {
* Searching for the nearest Beacon and get the Event from the Server
*/
private void startRanging() {
if(RANGING && isBluetoothAvailable()){
beaconManager.setRangingListener(new BeaconManager.RangingListener() {
@Override
public void onBeaconsDiscovered(Region region, List<Beacon> list) {
......@@ -176,13 +186,14 @@ public class MainActivity extends BaseActivity {
" statt.");
setTitle(R.string.app_name);
} else if (nextEventStart == -1){
} else if (nextEventStart == -1 || event == null){
setInformationText(getString(R.string.noEventToday));
setTitle(R.string.app_name);
}
else{
else if (!list.isEmpty()){
nearestBeacon = list.get(0);
getEventFromServer(nearestBeacon);
}
} if (list.isEmpty()){
......@@ -191,7 +202,7 @@ public class MainActivity extends BaseActivity {
}
});
}
}
private void setInformationText(final String text) {
......@@ -230,12 +241,8 @@ public class MainActivity extends BaseActivity {
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
setTitle(event.getName());
currentEventEnd = event.getCurrentEnd();
map = event.getApps();
Collection<String> appnames = map.values();
updateData(appnames);
setEvent(event);
initGui(event);
}
});
......@@ -248,6 +255,16 @@ public class MainActivity extends BaseActivity {
}
private void initGui(Event event) {
progress.dismiss();
event.save();
setTitle(event.getName());
currentEventEnd = event.getCurrentEnd();
map = event.getApps();
Collection<String> appnames = map.values();
updateData(appnames);
}
private void updateData(Collection<String> apps) {
progress.dismiss();
adapter.clear();
......@@ -265,7 +282,7 @@ public class MainActivity extends BaseActivity {
super.onResume();
// is Bluetooth on, is Location on, etc.
SystemRequirementsChecker.checkWithDefaultDialogs(this);
setRanging(true);
// Start ranging for beacons, when the activity appears on the screen
beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
@Override
......@@ -298,4 +315,8 @@ public class MainActivity extends BaseActivity {
public void setEvent(Event event) {
this.event = event;
}
public void setRanging(boolean RANGING) {
this.RANGING = RANGING;
}
}
package de.uni_oldenburg.bidl.member_view;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import classes.Event;
import classes.apps.materials.Materials;
import de.uni_oldenburg.bidl.R;
import de.uni_oldenburg.bidl.home_view.MainActivity;
import services.db.DBHelper;
import services.servercommunication.NetworkService;
public class MaterialsActivity extends AppCompatActivity {
/** GUI **/
private GridView grid;
private WebView webview;
/** values **/
private ArrayAdapter<String> adapter;
private ArrayList<String> materials = new ArrayList<>();
HashMap<String, String> map;
private Event event;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_materials);
/**init**/
adapter = new ArrayAdapter<>(MaterialsActivity.this, R.layout.grid_item, R.id.grid_text, materials);
grid = (GridView) findViewById(R.id.MaterialActivityGrid);
grid.setAdapter(adapter);
event = DBHelper.getEvent();
getMaterialsFromServer();
/**
* open activity based on the griditem, displayed at the MainActivity
*/
makeGridItemClickable();
}
private void makeGridItemClickable() {
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
String filename = (String) adapterView.getItemAtPosition(position);
String filePath = map.get(filename);
Uri uri = Uri.parse("http://192.168.1.2/"+filePath);
/* try
{
Intent intentUrl = new Intent(Intent.ACTION_VIEW);
intentUrl.setDataAndType(uri, "application/pdf");
intentUrl.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
MaterialsActivity.
}
catch (ActivityNotFoundException e)
{
Toast.makeText(MaterialsActivity.this, "No PDF Viewer Installed", Toast.LENGTH_LONG).show();
}*/
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");
setContentView(webview);
}
});
}
private void getMaterialsFromServer() {
NetworkService.getUrls(event.getEventId(), new NetworkService.RequestGetUrlsHandler() {
@Override
public void done(final Materials materials) {
if (materials != null){
MaterialsActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
updateData(materials);
}
});
}
}
});
}
private void updateData(Materials materials) {
adapter.clear();
if (materials.getUrls() != null){
map = materials.getUrls();
for (Map.Entry<String, String> entry : map.entrySet()){
adapter.insert(entry.getKey(), adapter.getCount());
}
}
adapter.notifyDataSetChanged();
}
}
package de.uni_oldenburg.bidl.member_view;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.SearchView;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
import classes.Event;
import de.uni_oldenburg.bidl.R;
import de.uni_oldenburg.bidl.home_view.MainActivity;
import de.uni_oldenburg.bidl.listfragment.ListCommunicator;
import de.uni_oldenburg.bidl.listfragment.SuperListFragment;
import services.servercommunication.NetworkService;
public class SearchActivity extends AppCompatActivity implements ListCommunicator {
/** GUI **/
private SearchView searchQueryView;
private ArrayList<Event> events;
private ListView eventContainer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
this.searchQueryView = (SearchView) findViewById(R.id.search_query_editText);
this.eventContainer = (ListView) findViewById(R.id.search_eventContainer);
searchQueryView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
if (query.length() > 4){
onStartSearchAction(query);
}else {
Toast.makeText(getApplicationContext(),
getResources().getString(R.string.notEnoughCaracters),
Toast.LENGTH_SHORT).show();
}
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
eventContainer.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String eventName = (String) parent.getItemAtPosition(position);
for (Event event : events){
if (event.getName().equals(eventName)){
startActivity(new Intent(getApplicationContext(), MainActivity.class).putExtra("event",event));
}
}
}
});
}
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);
}
showRefreshAnimation(true);
searchForEvents(query);
}
@Override
public void updateFragList() {
}
@Override
public void onSwipeDismiss(ListView listView, int[] reverseSortedPositions) {
}
/**
*
* Zeigt Refresh Animation an oder beendet sie
* @param show true: wird angezeigt; false: wird nicht angezeigt
*/
private void showRefreshAnimation(boolean show) {
if(getSupportFragmentManager().findFragmentById(R.id.search_eventContainer) instanceof SuperListFragment) {
SuperListFragment listFragment = (SuperListFragment) getSupportFragmentManager().findFragmentById(R.id.search_eventContainer);
if(listFragment != null)
listFragment.showRefreshAnimation(show);
}
}
private void searchForEvents(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();
}
});
}
});
}
public void addEventFragment() {
showRefreshAnimation(false);
try {
if (events != null){
ArrayList<String> eventNames = new ArrayList<>();
for (Event event : events){
eventNames.add(event.getName());
}
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,R.layout.event_item, R.id.eventName, eventNames);
eventContainer.setAdapter(adapter);
}
}catch (NullPointerException e){
e.printStackTrace();
}
}
public void setEvents(ArrayList<Event> events) {
this.events = events;
}
}
......@@ -10,6 +10,7 @@ import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
......@@ -18,6 +19,7 @@ import classes.StatusResponse;
import classes.User;
import classes.apps.feedback.Question;
import classes.apps.forum.Forum;
import classes.apps.materials.Materials;
import services.db.DBHelper;
/**
......@@ -178,7 +180,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){
......@@ -384,4 +386,85 @@ public abstract class NetworkService {
public interface RequestSaveAnswerHandler{
void done (String status);
}
public static void getUrls(int eventId, final RequestGetUrlsHandler handler){
okHttpClient.setReadTimeout(15, TimeUnit.SECONDS);
RequestBody requestBody = new FormEncodingBuilder()
.add("eventId", String.valueOf(eventId))
.build();
Request req = new Request.Builder()
.url(REST.SPRING_GETURLS)
.post(requestBody)
.build();
Call call = okHttpClient.newCall(req);
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 {
if (response.isSuccessful()){
Materials materials = LoganSquare.parse(response.body().byteStream(), Materials.class);
handler.done(materials);
}
} catch (IOException e){
handler.done(null);
e.printStackTrace();
}
}
});
}
public interface RequestGetUrlsHandler{
void done (Materials materials);
}
public static void searchEvents(String eventName, final RequestSearchEventsHandler handler){
okHttpClient.setReadTimeout(15, TimeUnit.SECONDS);
RequestBody requestBody = new FormEncodingBuilder()
.add("eventName", eventName)
.build();
Request req = new Request.Builder()
.url(REST.SPRING_SEARCHEVENTS)
.post(requestBody)
.build();
Call call = okHttpClient.newCall(req);
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 {
if (response.isSuccessful()){
ArrayList<Event> events = (ArrayList<Event>) LoganSquare.parseList(response.body().byteStream(), Event.class);
handler.done(events);
}
} catch (IOException e){
handler.done(null);
e.printStackTrace();
}
}
});
}
public interface RequestSearchEventsHandler{
void done (ArrayList<Event> events);
}
}
......@@ -15,7 +15,7 @@ public abstract class REST {
public static final String LOCAL_PORT = "8080";
public static final String LOCAL_CONTAINER = "/Rest";
public static final String LOCAL_URL = "http://192.168.1.2:" + LOCAL_PORT + LOCAL_CONTAINER;
public static final String LOCAL_URL = "http://192.168.178.24:" + LOCAL_PORT + LOCAL_CONTAINER;
// TODO: 04.08.2016 production URL and paths
......@@ -31,13 +31,18 @@ public abstract class REST {
private static final String REGISTER = "/register";
public static String SPRING_REGISTER = FULL_URL + REGISTER;
//getEvent path
//Event path
private static final String GETEVENT = "/getEvent";
public static String SPRING_GETEVENT = FULL_URL + GETEVENT;
private static final String SEARCHEVENTS = "/searchEvents";
public static final String SPRING_SEARCHEVENTS = FULL_URL + SEARCHEVENTS;
//Apps path
private static final String FORUM = "/forum";
private static final String FEEDBACK = "/feedback";
private static final String MATERIAL = "/material";
//Forum path
private static final String GETFORUM = "/getForum";
public static String SPRING_GETFORUM = FULL_URL + FORUM + GETFORUM;
......@@ -52,5 +57,9 @@ public abstract class REST {
private static final String SAVEANSWER = "/saveAnswer";
public static String SPRING_SAVEANSWER = FULL_URL + FEEDBACK + SAVEANSWER;
//Materials path
private static final String GETURLS = "/getUrls";
public static String SPRING_GETURLS = FULL_URL + MATERIAL + GETURLS;
}
......@@ -18,8 +18,15 @@
android:orientation="vertical"
android:layout_margin="10dp"></RadioGroup>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"