Commit 8ccf1040 authored by Christof Wolke's avatar Christof Wolke

Feedback view

parent cc9f90b9
......@@ -24,7 +24,7 @@
android:value="de.uni_oldenburg.bidl.classes" />
<meta-data
android:name="Rush_db_version"
android:value="2" />
android:value="3" />
<meta-data
android:name="Rush_db_name"
android:value="bidl.db" />
......
......@@ -15,37 +15,28 @@ import co.uk.rushorm.core.RushObject;
public class Answer extends RushObject implements Serializable {
@JsonField(name="id")
private int Answerid;
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;
public Answer(int answerid, List<String> possibleAnswers) {
this.answerid = answerid;
this.possibleAnswers = possibleAnswers;
}
public int getAnswerid() {
return Answerid;
return answerid;
}
public void setAnswerid(int answerid) {
Answerid = answerid;
}
public String getFinalAnswer() {
return finalAnswer;
}
public void setFinalAnswer(String finalAnswer) {
this.finalAnswer = finalAnswer;
this.answerid = answerid;
}
public List<String> getPossibleAnswers() {
......@@ -59,8 +50,7 @@ public class Answer extends RushObject implements Serializable {
@Override
public String toString() {
return "Answer{" +
"Answerid=" + Answerid +
", finalAnswer='" + finalAnswer + '\'' +
"answerid=" + answerid +
", possibleAnswers=" + possibleAnswers +
'}';
}
......
......@@ -15,15 +15,16 @@ import co.uk.rushorm.core.annotations.RushList;
@JsonObject
public class Question extends RushObject implements Serializable {
@RushList(classType = Answer.class)
@JsonField(name = "answers")
private ArrayList<Answer> answers;
@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() {
}
......
......@@ -2,29 +2,125 @@ package de.uni_oldenburg.bidl.member_view;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutCompat;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import classes.Event;
import classes.apps.feedback.Answer;
import classes.apps.feedback.Question;
import de.uni_oldenburg.bidl.BaseActivity;
import de.uni_oldenburg.bidl.R;
import services.db.DBHelper;
import services.servercommunication.NetworkService;
public class FeedbackActivity extends AppCompatActivity {
private Event event;
private List<Question> questions;
private LinearLayout mLinearLayout;
private Button btSendFeedback;
private RadioGroup radioGroup;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_feedback);
mLinearLayout = (LinearLayout) findViewById(R.id.feedback_ll);
btSendFeedback = (Button) findViewById(R.id.sendFeedbackBt);
setTitle(getIntent().getStringExtra("appName"));
btSendFeedback.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
radioGroup.getCheckedRadioButtonId();
}
});
}
NetworkService.getQuestions(1, new NetworkService.RequestGetQuestionsHandler() {
@Override
protected void onStart() {
super.onStart();
event = DBHelper.getEvent();
NetworkService.getQuestions(event.getEventId(), new NetworkService.RequestGetQuestionsHandler() {
@Override
public void done(List<Question> questions) {
Question question = questions.get(0);
Log.d("TEST", "DIE ERSTE FRAGE LAUTET: "+question.getText());
setQuestions(questions);
getAnswers();
}
});
}
@Override
protected void onPause() {
super.onPause();
mLinearLayout.removeAllViews();
}
private void getAnswers() {
for (final Question question : questions){
NetworkService.getPossibleAnswers(question.getQuestionId(), new NetworkService.RequestGetPossibleAnswersHandler() {
@Override
public void done(final Answer answer) {
if (answer != null){
FeedbackActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
initGui(question, answer);
}
});
}
}
});
}
}
private void initGui(Question question, Answer answer) {
for (int row = 0; row < 1; row++){
TextView tv = new TextView(this);
tv.setText(question.getText());
tv.setGravity(Gravity.CENTER);
tv.setPadding(0,40,0,0);
radioGroup = new RadioGroup(this);
radioGroup.setOrientation(LinearLayout.HORIZONTAL);
radioGroup.setGravity(Gravity.CENTER);
for (int i = 0; i < answer.getPossibleAnswers().size(); i++){
RadioButton radioButton = new RadioButton(this);
radioButton.setId((row * 2 )+i);
radioButton.setText(answer.getPossibleAnswers().get(i));
radioGroup.addView(radioButton);
}
mLinearLayout.addView(tv);
mLinearLayout.addView(radioGroup);
}
}
public void setQuestions(List<Question> questions) {
this.questions = questions;
}
}
......@@ -8,6 +8,7 @@ import java.util.List;
import classes.Event;
import classes.LocalStorage;
import classes.apps.AppContainer;
import classes.apps.feedback.Answer;
import co.uk.rushorm.core.RushCore;
import co.uk.rushorm.core.RushSearch;
......@@ -54,6 +55,7 @@ public class DBHelper {
*/
public static void clearAll() {
clearEvents();
clearAnswers();
}
......@@ -61,5 +63,16 @@ public class DBHelper {
RushCore.getInstance().deleteAll(Event.class);
}
//Answer
public static List<Answer> getAllAnswer(){
List<Answer> answers = new RushSearch().find(Answer.class);
return answers;
}
public static void clearAnswers(){RushCore.getInstance().deleteAll(Answer.class);}
}
package services.servercommunication;
import android.util.Log;
import com.bluelinelabs.logansquare.LoganSquare;
import com.squareup.okhttp.Call;
import com.squareup.okhttp.Callback;
......@@ -16,6 +18,7 @@ import java.util.concurrent.TimeUnit;
import classes.Event;
import classes.StatusResponse;
import classes.User;
import classes.apps.feedback.Answer;
import classes.apps.feedback.Question;
import classes.apps.forum.Forum;
......@@ -265,11 +268,11 @@ public abstract class NetworkService {
void done(String status);
}
public static void getQuestions(int feedbackId, final RequestGetQuestionsHandler handler){
public static void getQuestions(int eventId, final RequestGetQuestionsHandler handler){
okHttpClient.setReadTimeout(15, TimeUnit.SECONDS);
RequestBody requestBody = new FormEncodingBuilder()
.add("feedbackId", String.valueOf(feedbackId))
.add("eventId", String.valueOf(eventId))
.build();
Request req = new Request.Builder()
......@@ -305,4 +308,46 @@ public abstract class NetworkService {
public interface RequestGetQuestionsHandler{
void done(List<Question> questions);
}
public static void getPossibleAnswers(int questionId, final RequestGetPossibleAnswersHandler handler){
okHttpClient.setReadTimeout(15, TimeUnit.SECONDS);
RequestBody requestBody = new FormEncodingBuilder()
.add("questionId", String.valueOf(questionId))
.build();
Request req = new Request.Builder()
.url(REST.SPRING_GETPOSSIBLEANSWERS)
.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()){
Answer answer = LoganSquare.parse(response.body().byteStream(), Answer.class);
handler.done(answer);
}
} catch (IOException e){
handler.done(null);
e.printStackTrace();
}
}
});
}
public interface RequestGetPossibleAnswersHandler{
void done(Answer answer);
}
}
......@@ -49,4 +49,7 @@ public abstract class REST {
private static final String GETQUESTIONS = "/getQuestions";
public static String SPRING_GETQUESTIONS = FULL_URL + FEEDBACK + GETQUESTIONS;
private static final String GETPOSSIBLEANSWERS = "/getPossibleAnswers";
public static String SPRING_GETPOSSIBLEANSWERS = FULL_URL + FEEDBACK + GETPOSSIBLEANSWERS;
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="de.uni_oldenburg.bidl.member_view.FeedbackActivity">
<LinearLayout
android:id="@+id/feedback_ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radiogroup"
android:orientation="vertical"
android:layout_margin="10dp"></RadioGroup>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/sendFeedbackBt"
android:text="@string/sendFeedbackBtn"
android:gravity="center"
android:layout_marginTop="50dp"
android:layout_below="@+id/feedback_ll"
android:layout_centerHorizontal="true" />
</RelativeLayout>
......@@ -19,6 +19,9 @@
<string name="menuLogoutTitle">Ausloggen</string>
<string name="menuShareTitle">Teilen</string>
<!-- FeedbackActivity !-->
<string name="sendFeedbackBtn">Abstimmen!</string>
<!-- ForumActivity !-->
<string name="sendMessageHint">Ihre Nachricht</string>
<string name="noText">Geben Sie eine Nachricht ein!</string>
......
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