Commit 324d35c1 authored by Christof Wolke's avatar Christof Wolke

neues layout für forum und das senden von nachrichten realisiert

parent b4d8d0a0
package de.uni_oldenburg.bidl.listfragment;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import classes.MyList;
import classes.apps.forum.Comment;
import classes.apps.forum.CommentList;
......@@ -65,7 +71,20 @@ public class CommentListAdapter extends ListAdapter {
this.commentText = (TextView) item.findViewById(R.id.commentText);
this.commentText.setText(comment.getText());
this.time = (TextView) item.findViewById(R.id.commentTime);
this.time.setText(comment.getTimestamp());
String time = getTime(comment.getTimestamp());
this.time.setText(time);
return item;
}
private String getTime(String timestamp) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat strDateFormat = new SimpleDateFormat("d MMM hh:mm");
try {
Date date = format.parse(timestamp);
return strDateFormat.format(date);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
}
package de.uni_oldenburg.bidl.member_view;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.view.menu.MenuAdapter;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.Toast;
......@@ -14,6 +18,8 @@ import java.util.ArrayList;
import java.util.List;
import classes.Event;
import classes.LocalStorage;
import classes.User;
import classes.apps.forum.Comment;
import classes.apps.forum.CommentList;
import classes.apps.forum.Forum;
......@@ -26,7 +32,7 @@ import services.db.DBHelper;
import services.servercommunication.NetworkService;
public class ForumActivity extends BaseActivity implements ListCommunicator, View.OnTouchListener {
public class ForumActivity extends AppCompatActivity implements ListCommunicator, View.OnTouchListener {
/** Tag for Logging **/
private static final String TAG = ForumActivity.class.getSimpleName();
......@@ -34,23 +40,64 @@ public class ForumActivity extends BaseActivity implements ListCommunicator, Vie
private Event event;
private CommentList comments;
/** GUI **/
private EditText yourMessage;
private ImageButton sendButton;
protected LocalStorage localStorage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setContentView(R.layout.activity_forum);
yourMessage = (EditText) findViewById(R.id.yourMessageET);
sendButton = (ImageButton) findViewById(R.id.sendButton);
this.localStorage = new LocalStorage(this);
setMenu();
// setMenu();
setTitle(getIntent().getStringExtra("appName"));
event = DBHelper.getEvent();
getForumObjectFromServer(event.getEventId());
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sendMessage();
view.clearFocus();
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(),0);
yourMessage.setText("");
}
});
}
private void sendMessage() {
User user = localStorage.getLoggedInUser();
if(yourMessage.getText() != null && yourMessage.getText().length() > 0) {
NetworkService.setNewComment(yourMessage.getText().toString(), (int) user.getUserId(), forum.getForumId(), new NetworkService.RequestNewCommentHandler() {
@Override
public void done(String status) {
if (status.equals("ok")) {
updateFragList();
} else {
ForumActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), R.string.forum_response_error, Toast.LENGTH_SHORT).show();
}
});
}
}
});
}else {
Toast.makeText(this, R.string.noText,Toast.LENGTH_SHORT).show();
}
}
private void getForumObjectFromServer(int eventId) {
......@@ -119,15 +166,6 @@ public class ForumActivity extends BaseActivity implements ListCommunicator, Vie
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
float x = motionEvent.getX();
float y = motionEvent.getY();
int eventaction = motionEvent.getAction();
switch (eventaction){
case MotionEvent.ACTION_DOWN:
// updateFragList();
}
return true;
}
}
......@@ -219,4 +219,41 @@ public abstract class NetworkService {
public interface RequestForumHandler{
void done(Forum forum);
}
public static void setNewComment(String comment, int forumId, int userId, final RequestNewCommentHandler handler){
okHttpClient.setReadTimeout(15, TimeUnit.SECONDS);
RequestBody requestBody = new FormEncodingBuilder()
.add("comment", comment)
.add("forumId", String.valueOf(forumId))
.add("userId", String.valueOf(userId))
.build();
Request req = new Request.Builder()
.url(REST.SPRING_SETNEWCOMMENT)
.post(requestBody)
.build();
Call call = okHttpClient.newCall(req);
call.enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
handler.done("failure");
e.printStackTrace();
}
@Override
public void onResponse(Response response) throws IOException {
if(response.isSuccessful()){
StatusResponse statusResponseObj = LoganSquare.parse(response.body().byteStream(), StatusResponse.class);
handler.done(statusResponseObj.getStatus());
}
}
});
}
public interface RequestNewCommentHandler{
void done(String status);
}
}
......@@ -41,4 +41,7 @@ public abstract class REST {
private static final String GETFORUM = "/getForum";
public static String SPRING_GETFORUM = FULL_URL + FORUM + GETFORUM;
private static final String SETNEWCOMMENT = "/setNewComment";
public static String SPRING_SETNEWCOMMENT = FULL_URL + FORUM + SETNEWCOMMENT;
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
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="16dp"
tools:context="de.uni_oldenburg.bidl.member_view.ForumActivity"
tools:showIn="@layout/app_bar_main"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
tools:context="de.uni_oldenburg.bidl.member_view.ForumActivity">
<ImageButton
android:id="@+id/sendButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_send_black_24dp"
android:layout_gravity="right"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:background="@color/white"
android:layout_margin="10dp"/>
<EditText
android:id="@+id/yourMessageET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/sendMessageHint"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_toStartOf="@+id/sendButton"
android:layout_margin="10dp"/>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/commentContainer"></FrameLayout>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/commentContainer"
android:layout_above="@id/yourMessageET"
></FrameLayout>
</RelativeLayout>
......@@ -23,7 +23,6 @@
<include layout="@layout/content_main" />
<include layout="@layout/activity_forum"/>
<include layout="@layout/activity_feedback"/>
......
......@@ -7,28 +7,42 @@
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
android:orientation="horizontal"
android:layout_margin="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/commentUsername"
android:layout_margin="10dp"/>
android:layout_margin="10dp"
android:inputType="textMultiLine"
android:singleLine="false"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/commentTime"
android:layout_margin="10dp"
android:gravity="right"
android:layout_alignParentRight="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/commentText"
android:layout_margin="10dp"/>
android:layout_margin="10dp"
android:inputType="textMultiLine"
android:singleLine="false"
android:gravity="left"
android:layout_toStartOf="@id/commentTime"
android:layout_toEndOf="@id/commentUsername"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/commentTime"
android:layout_margin="10dp"/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
</LinearLayout>
\ No newline at end of file
......@@ -3,6 +3,7 @@
<string name="noBeaconFound">Kein Beacon in der Nähe!</string>
<string name="noConnection">Es konnte keine Verbindung zum Server aufgebaut werden!</string>
<!-- Main Activity !-->
......@@ -18,6 +19,11 @@
<string name="menuLogoutTitle">Ausloggen</string>
<string name="menuShareTitle">Teilen</string>
<!-- ForumActivity !-->
<string name="sendMessageHint">Ihre Nachricht</string>
<string name="noText">Geben Sie eine Nachricht ein!</string>
<string name="forum_response_error">Ihre Nachricht konnte nicht gespeichert werden!</string>
<!-- Login Activity !-->
<string name="title_activity_login">Sign in</string>
......@@ -48,4 +54,5 @@
<string name="action_settings">Settings</string>
</resources>
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