Commit f1c3df5e authored by Christof Wolke's avatar Christof Wolke
Browse files

getting the comments from the Server

parent 991f4e0d
...@@ -7,6 +7,7 @@ import java.io.Serializable; ...@@ -7,6 +7,7 @@ import java.io.Serializable;
import java.util.Date; import java.util.Date;
import co.uk.rushorm.core.RushObject; import co.uk.rushorm.core.RushObject;
import co.uk.rushorm.core.annotations.RushList;
/** /**
* Created by Christof on 23.08.2016. * Created by Christof on 23.08.2016.
...@@ -14,30 +15,30 @@ import co.uk.rushorm.core.RushObject; ...@@ -14,30 +15,30 @@ import co.uk.rushorm.core.RushObject;
@JsonObject @JsonObject
public class Comment extends RushObject implements Serializable { public class Comment extends RushObject implements Serializable {
@JsonField(name = "id") @JsonField(name = "username")
private int commentID; private String username;
@JsonField(name = "text") @JsonField(name = "text")
private String text; private String text;
@JsonField(name = "timestamp") @JsonField(name = "timestamp")
private Date timestamp; private String timestamp;
public Comment() { public Comment() {
} }
public Comment(int commentID, String text, Date timestamp) { public Comment(String username, String text, String timestamp) {
this.commentID = commentID; this.username = username;
this.text = text; this.text = text;
this.timestamp = timestamp; this.timestamp = timestamp;
} }
public int getCommentID() { public String getUsername() {
return commentID; return username;
} }
public void setCommentID(int commentID) { public void setUsername(String username) {
this.commentID = commentID; this.username = username;
} }
public String getText() { public String getText() {
...@@ -48,18 +49,18 @@ public class Comment extends RushObject implements Serializable { ...@@ -48,18 +49,18 @@ public class Comment extends RushObject implements Serializable {
this.text = text; this.text = text;
} }
public Date getTimestamp() { public String getTimestamp() {
return timestamp; return timestamp;
} }
public void setTimestamp(Date timestamp) { public void setTimestamp(String timestamp) {
this.timestamp = timestamp; this.timestamp = timestamp;
} }
@Override @Override
public String toString() { public String toString() {
return "Comment{" + return "Comment{" +
"commentID=" + commentID + "username=" + username +
", text='" + text + '\'' + ", text='" + text + '\'' +
", timestamp=" + timestamp + ", timestamp=" + timestamp +
'}'; '}';
......
...@@ -18,7 +18,6 @@ public class Forum extends RushObject implements Serializable { ...@@ -18,7 +18,6 @@ public class Forum extends RushObject implements Serializable {
@JsonField(name = "id") @JsonField(name = "id")
private int forumId; private int forumId;
@RushList(classType = Comment.class)
@JsonField(name = "comments") @JsonField(name = "comments")
private ArrayList<Comment>comments; private ArrayList<Comment>comments;
...@@ -26,8 +25,8 @@ public class Forum extends RushObject implements Serializable { ...@@ -26,8 +25,8 @@ public class Forum extends RushObject implements Serializable {
} }
public Forum(int forumId, ArrayList<Comment> comments) { public Forum(int id, ArrayList<Comment> comments) {
this.forumId = forumId; this.forumId = id;
this.comments = comments; this.comments = comments;
} }
......
...@@ -2,12 +2,22 @@ package de.uni_oldenburg.bidl.member_view; ...@@ -2,12 +2,22 @@ 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 classes.Event;
import classes.apps.Comment;
import classes.apps.Forum;
import de.uni_oldenburg.bidl.R; 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 { public class ForumActivity extends AppCompatActivity {
/** Tag for Logging **/
private static final String TAG = ForumActivity.class.getSimpleName();
private Forum forum;
@Override @Override
...@@ -15,5 +25,24 @@ public class ForumActivity extends AppCompatActivity { ...@@ -15,5 +25,24 @@ public class ForumActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_forum); setContentView(R.layout.activity_forum);
setTitle(getIntent().getStringExtra("appName")); 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 { ...@@ -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 * Löscht Recommendations, Locations, Favoriten und Check-Ins von der Datenbank
*/ */
......
package services.servercommunication; package services.servercommunication;
import android.util.Log;
import com.bluelinelabs.logansquare.LoganSquare; import com.bluelinelabs.logansquare.LoganSquare;
import com.squareup.okhttp.Call; import com.squareup.okhttp.Call;
import com.squareup.okhttp.Callback; import com.squareup.okhttp.Callback;
...@@ -10,11 +12,15 @@ import com.squareup.okhttp.RequestBody; ...@@ -10,11 +12,15 @@ import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response; import com.squareup.okhttp.Response;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import classes.Event; import classes.Event;
import classes.StatusResponse; import classes.StatusResponse;
import classes.User; 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 * Helfer Klasse, die häufig verwendete I/O Operationen im Netzwerk und der Datenbank erleichtert
...@@ -162,6 +168,7 @@ public abstract class NetworkService { ...@@ -162,6 +168,7 @@ public abstract class NetworkService {
if (response.isSuccessful()){ if (response.isSuccessful()){
String responseString = response.body().string(); String responseString = response.body().string();
Event event = LoganSquare.parse(responseString, Event.class); Event event = LoganSquare.parse(responseString, Event.class);
if (event != null)
event.save(); event.save();
handler.done(event); handler.done(event);
} }
...@@ -177,4 +184,44 @@ public abstract class NetworkService { ...@@ -177,4 +184,44 @@ public abstract class NetworkService {
public interface RequestGetEventHandler { public interface RequestGetEventHandler {
void done(Event event); 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 { ...@@ -35,4 +35,10 @@ public abstract class REST {
private static final String GETEVENT = "/getEvent"; private static final String GETEVENT = "/getEvent";
public static String SPRING_GETEVENT = FULL_URL + 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;
} }
Supports Markdown
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