Commit f1c3df5e authored by Christof Wolke's avatar Christof Wolke

getting the comments from the Server

parent 991f4e0d
......@@ -7,6 +7,7 @@ import java.io.Serializable;
import java.util.Date;
import co.uk.rushorm.core.RushObject;
import co.uk.rushorm.core.annotations.RushList;
/**
* Created by Christof on 23.08.2016.
......@@ -14,30 +15,30 @@ import co.uk.rushorm.core.RushObject;
@JsonObject
public class Comment extends RushObject implements Serializable {
@JsonField(name = "id")
private int commentID;
@JsonField(name = "username")
private String username;
@JsonField(name = "text")
private String text;
@JsonField(name = "timestamp")
private Date timestamp;
private String timestamp;
public Comment() {
}
public Comment(int commentID, String text, Date timestamp) {
this.commentID = commentID;
public Comment(String username, String text, String timestamp) {
this.username = username;
this.text = text;
this.timestamp = timestamp;
}
public int getCommentID() {
return commentID;
public String getUsername() {
return username;
}
public void setCommentID(int commentID) {
this.commentID = commentID;
public void setUsername(String username) {
this.username = username;
}
public String getText() {
......@@ -48,18 +49,18 @@ public class Comment extends RushObject implements Serializable {
this.text = text;
}
public Date getTimestamp() {
public String getTimestamp() {
return timestamp;
}
public void setTimestamp(Date timestamp) {
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
@Override
public String toString() {
return "Comment{" +
"commentID=" + commentID +
"username=" + username +
", text='" + text + '\'' +
", timestamp=" + timestamp +
'}';
......
......@@ -18,7 +18,6 @@ public class Forum extends RushObject implements Serializable {
@JsonField(name = "id")
private int forumId;
@RushList(classType = Comment.class)
@JsonField(name = "comments")
private ArrayList<Comment>comments;
......@@ -26,8 +25,8 @@ public class Forum extends RushObject implements Serializable {
}
public Forum(int forumId, ArrayList<Comment> comments) {
this.forumId = forumId;
public Forum(int id, ArrayList<Comment> comments) {
this.forumId = id;
this.comments = comments;
}
......
......@@ -2,12 +2,22 @@ package de.uni_oldenburg.bidl.member_view;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import classes.Event;
import classes.apps.Comment;
import classes.apps.Forum;
import de.uni_oldenburg.bidl.R;
import de.uni_oldenburg.bidl.home_view.MainActivity;
import services.db.DBHelper;
import services.servercommunication.NetworkService;
public class ForumActivity extends AppCompatActivity {
/** Tag for Logging **/
private static final String TAG = ForumActivity.class.getSimpleName();
private Forum forum;
@Override
......@@ -15,5 +25,24 @@ public class ForumActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_forum);
setTitle(getIntent().getStringExtra("appName"));
Event event = DBHelper.getEvent();
getForumObjectFromServer(event.getEventId());
Comment comment = forum.getComments().get(0);
Log.d(TAG, "FORUMACTIVITY: "+comment.getText());
}
private void getForumObjectFromServer(int eventId) {
NetworkService.forum(eventId, new NetworkService.RequestForumHandler() {
@Override
public void done(final Forum forum) {
setForum(forum);
}
});
}
public void setForum(Forum forum) {
this.forum = forum;
}
}
......@@ -44,6 +44,11 @@ public class DBHelper {
}
public static Event getEvent(){
Event event = new RushSearch().findSingle(Event.class);
return event;
}
/**
* Löscht Recommendations, Locations, Favoriten und Check-Ins von der Datenbank
*/
......
package services.servercommunication;
import android.util.Log;
import com.bluelinelabs.logansquare.LoganSquare;
import com.squareup.okhttp.Call;
import com.squareup.okhttp.Callback;
......@@ -10,11 +12,15 @@ 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;
import classes.Event;
import classes.StatusResponse;
import classes.User;
import classes.apps.Comment;
import classes.apps.Forum;
/**
* Helfer Klasse, die häufig verwendete I/O Operationen im Netzwerk und der Datenbank erleichtert
......@@ -162,6 +168,7 @@ public abstract class NetworkService {
if (response.isSuccessful()){
String responseString = response.body().string();
Event event = LoganSquare.parse(responseString, Event.class);
if (event != null)
event.save();
handler.done(event);
}
......@@ -177,4 +184,44 @@ public abstract class NetworkService {
public interface RequestGetEventHandler {
void done(Event event);
}
public static void forum(int eventId, final RequestForumHandler handler){
okHttpClient.setReadTimeout(15, TimeUnit.SECONDS);
RequestBody requestBody = new FormEncodingBuilder()
.add("eventId", String.valueOf(eventId))
.build();
Request req = new Request.Builder()
.url(REST.SPRING_FORUM)
.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()){
Forum forum = LoganSquare.parse(response.body().byteStream(), Forum.class);
handler.done(forum);
}
}catch (IOException e){
handler.done(null);
e.printStackTrace();
}
}
});
}
public interface RequestForumHandler{
void done(Forum forum);
}
}
......@@ -35,4 +35,10 @@ public abstract class REST {
private static final String GETEVENT = "/getEvent";
public static String SPRING_GETEVENT = FULL_URL + GETEVENT;
//Apps path
private static final String APP = "/app";
//Forum path
private static final String FORUM = "/forum";
public static String SPRING_FORUM = FULL_URL + APP + FORUM;
}
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