Commit cc9f90b9 authored by Christof Wolke's avatar Christof Wolke

Network call to get Questions

parent 99924be7
package classes.apps.feedback;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import java.io.Serializable;
import java.util.List;
import co.uk.rushorm.core.RushObject;
/**
* Created by Christof on 06.09.2016.
*/
@JsonObject
public class Answer extends RushObject implements Serializable {
@JsonField(name="id")
private int Answerid;
@JsonField(name="finalAnswer")
private String finalAnswer;
@JsonField(name="possibleAnswers")
private List<String> possibleAnswers;
public Answer() {
}
public Answer(int answerid, String finalAnswer, List<String> possibleAnswers) {
Answerid = answerid;
this.finalAnswer = finalAnswer;
this.possibleAnswers = possibleAnswers;
}
public int getAnswerid() {
return Answerid;
}
public void setAnswerid(int answerid) {
Answerid = answerid;
}
public String getFinalAnswer() {
return finalAnswer;
}
public void setFinalAnswer(String finalAnswer) {
this.finalAnswer = finalAnswer;
}
public List<String> getPossibleAnswers() {
return possibleAnswers;
}
public void setPossibleAnswers(List<String> possibleAnswers) {
this.possibleAnswers = possibleAnswers;
}
@Override
public String toString() {
return "Answer{" +
"Answerid=" + Answerid +
", finalAnswer='" + finalAnswer + '\'' +
", possibleAnswers=" + possibleAnswers +
'}';
}
}
package classes.apps.feedback;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import java.io.Serializable;
import java.util.ArrayList;
import co.uk.rushorm.core.RushObject;
import co.uk.rushorm.core.annotations.RushList;
/**
* Created by Christof on 06.09.2016.
*/
@JsonObject
public class Question extends RushObject implements Serializable {
@JsonField(name = "id")
private int questionId;
@JsonField(name = "text")
private String text;
@RushList(classType = Answer.class)
@JsonField(name = "answers")
private ArrayList<Answer> answers;
public Question() {
}
public Question(int questionId, String text, ArrayList<Answer> answers) {
this.questionId = questionId;
this.text = text;
this.answers = answers;
}
public int getQuestionId() {
return questionId;
}
public void setQuestionId(int questionId) {
this.questionId = questionId;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public ArrayList<Answer> getAnswers() {
return answers;
}
public void setAnswers(ArrayList<Answer> answers) {
this.answers = answers;
}
@Override
public String toString() {
return "Question{" +
"questionId=" + questionId +
", text='" + text + '\'' +
", answers=" + answers +
'}';
}
}
......@@ -2,17 +2,29 @@ package de.uni_oldenburg.bidl.member_view;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import java.util.List;
import classes.apps.feedback.Question;
import de.uni_oldenburg.bidl.BaseActivity;
import de.uni_oldenburg.bidl.R;
import services.servercommunication.NetworkService;
public class FeedbackActivity extends BaseActivity {
public class FeedbackActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setMenu();
setContentView(R.layout.activity_feedback);
setTitle(getIntent().getStringExtra("appName"));
NetworkService.getQuestions(1, new NetworkService.RequestGetQuestionsHandler() {
@Override
public void done(List<Question> questions) {
Question question = questions.get(0);
Log.d("TEST", "DIE ERSTE FRAGE LAUTET: "+question.getText());
}
});
}
}
......@@ -10,11 +10,13 @@ import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
import classes.Event;
import classes.StatusResponse;
import classes.User;
import classes.apps.feedback.Question;
import classes.apps.forum.Forum;
/**
......@@ -245,10 +247,16 @@ public abstract class NetworkService {
@Override
public void onResponse(Response response) throws IOException {
try {
if(response.isSuccessful()){
StatusResponse statusResponseObj = LoganSquare.parse(response.body().byteStream(), StatusResponse.class);
handler.done(statusResponseObj.getStatus());
}
} catch (IOException e){
handler.done("failure");
e.printStackTrace();
}
}
});
}
......@@ -256,4 +264,45 @@ public abstract class NetworkService {
public interface RequestNewCommentHandler{
void done(String status);
}
public static void getQuestions(int feedbackId, final RequestGetQuestionsHandler handler){
okHttpClient.setReadTimeout(15, TimeUnit.SECONDS);
RequestBody requestBody = new FormEncodingBuilder()
.add("feedbackId", String.valueOf(feedbackId))
.build();
Request req = new Request.Builder()
.url(REST.SPRING_GETQUESTIONS)
.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()){
List<Question> questions = LoganSquare.parseList(response.body().byteStream(), Question.class);
handler.done(questions);
}
}catch (IOException e){
handler.done(null);
e.printStackTrace();
}
}
});
}
public interface RequestGetQuestionsHandler{
void done(List<Question> questions);
}
}
......@@ -37,6 +37,7 @@ public abstract class REST {
//Apps path
private static final String FORUM = "/forum";
private static final String FEEDBACK = "/feedback";
//Forum path
private static final String GETFORUM = "/getForum";
public static String SPRING_GETFORUM = FULL_URL + FORUM + GETFORUM;
......@@ -44,4 +45,8 @@ public abstract class REST {
private static final String SETNEWCOMMENT = "/setNewComment";
public static String SPRING_SETNEWCOMMENT = FULL_URL + FORUM + SETNEWCOMMENT;
//Feedback path
private static final String GETQUESTIONS = "/getQuestions";
public static String SPRING_GETQUESTIONS = FULL_URL + FEEDBACK + GETQUESTIONS;
}
......@@ -3,13 +3,10 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="de.uni_oldenburg.bidl.member_view.FeedbackActivity"
tools:showIn="@layout/app_bar_main"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
tools:context="de.uni_oldenburg.bidl.member_view.FeedbackActivity">
</RelativeLayout>
......@@ -23,7 +23,6 @@
<include layout="@layout/content_main" />
<include layout="@layout/activity_feedback"/>
......
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