| @@ -0,0 +1,41 @@ | ||
| package at.renehollander.chat.fragments; | ||
|
|
||
| import android.os.Bundle; | ||
| import android.support.annotation.Nullable; | ||
| import android.view.LayoutInflater; | ||
| import android.view.View; | ||
| import android.view.ViewGroup; | ||
| import android.widget.ListView; | ||
|
|
||
| import at.renehollander.chat.Application; | ||
| import at.renehollander.chat.R; | ||
| import at.renehollander.chat.adapter.ChatRoomListListAdapter; | ||
| import at.renehollander.chat.model.ChatRoom; | ||
|
|
||
| public class ChatRoomListFragment extends CustomFragment { | ||
|
|
||
| private ListView chatRooms; | ||
|
|
||
| @Override | ||
| public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
| return inflater.inflate(R.layout.fragment_chatroomlist, container, false); | ||
| } | ||
|
|
||
| @Override | ||
| public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | ||
| super.onViewCreated(view, savedInstanceState); | ||
|
|
||
| getActivity().setTitle(getResources().getString(R.string.chatrooms_fragment_title)); | ||
| chatRooms = (ListView) findViewById(R.id.listView); | ||
|
|
||
| chatRooms.setAdapter(new ChatRoomListListAdapter(getActivity(), ((Application) getActivity().getApplication()).getChatrooms())); | ||
| chatRooms.setOnItemClickListener((adapterView, view2, position, id) -> { | ||
| ChatRoomFragment crf = new ChatRoomFragment(); | ||
| Bundle bundle = new Bundle(); | ||
| bundle.putCharSequence("room", ((ChatRoom) chatRooms.getAdapter().getItem(position)).getName()); | ||
| crf.setArguments(bundle); | ||
| replace(R.id.fragment_container, crf); | ||
| }); | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,20 @@ | ||
| package at.renehollander.chat.fragments; | ||
|
|
||
| import android.support.v4.app.Fragment; | ||
| import android.support.v4.app.FragmentTransaction; | ||
| import android.view.View; | ||
|
|
||
| public abstract class CustomFragment extends Fragment { | ||
|
|
||
| public View findViewById(int id) { | ||
| return getActivity().findViewById(id); | ||
| } | ||
|
|
||
| public void replace(int id, Fragment newFragment) { | ||
| FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction(); | ||
| transaction.replace(id, newFragment); | ||
| transaction.addToBackStack(null); | ||
| transaction.commit(); | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,32 @@ | ||
| package at.renehollander.chat.model; | ||
|
|
||
| import android.databinding.ObservableArrayList; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class ChatRoom { | ||
|
|
||
| private String name; | ||
| private ObservableArrayList<Message> messages; | ||
|
|
||
| public ChatRoom(String name, ObservableArrayList<Message> messages) { | ||
| this.name = name; | ||
| this.messages = messages; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public ObservableArrayList<Message> getMessages() { | ||
| return messages; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "ChatRoom{" + | ||
| "name='" + name + '\'' + | ||
| ", messages=" + messages + | ||
| '}'; | ||
| } | ||
| } |
| @@ -0,0 +1,55 @@ | ||
| package at.renehollander.chat.model; | ||
|
|
||
| import java.util.Date; | ||
|
|
||
| public class Message { | ||
|
|
||
| public static enum Flag { | ||
| SENT, RECIEVED; | ||
| } | ||
|
|
||
| private Flag flag; | ||
| private String room; | ||
| private String user; | ||
| private Date date; | ||
| private String text; | ||
|
|
||
| public Message(Flag flag, String room, String user, Date date, String text) { | ||
| this.flag = flag; | ||
| this.room = room; | ||
| this.user = user; | ||
| this.date = date; | ||
| this.text = text; | ||
| } | ||
|
|
||
| public Flag getFlag() { | ||
| return flag; | ||
| } | ||
|
|
||
| public String getRoom() { | ||
| return room; | ||
| } | ||
|
|
||
| public String getUser() { | ||
| return user; | ||
| } | ||
|
|
||
| public Date getDate() { | ||
| return date; | ||
| } | ||
|
|
||
| public String getText() { | ||
| return text; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Message{" + | ||
| "flag=" + flag + | ||
| ", room='" + room + '\'' + | ||
| ", user='" + user + '\'' + | ||
| ", date=" + date + | ||
| ", text='" + text + '\'' + | ||
| '}'; | ||
| } | ||
| } |
| @@ -0,0 +1,40 @@ | ||
| package at.renehollander.chat.util; | ||
|
|
||
| import android.databinding.ObservableArrayList; | ||
| import android.widget.BaseAdapter; | ||
|
|
||
| import at.renehollander.chat.model.ChatRoom; | ||
|
|
||
| public class ObservableListChangeListener extends ObservableArrayList.OnListChangedCallback<ObservableArrayList<ChatRoom>> { | ||
|
|
||
| private final BaseAdapter adapter; | ||
|
|
||
| public ObservableListChangeListener(BaseAdapter adapter) { | ||
| this.adapter = adapter; | ||
| } | ||
|
|
||
| @Override | ||
| public void onChanged(ObservableArrayList<ChatRoom> chatRooms) { | ||
| adapter.notifyDataSetChanged(); | ||
| } | ||
|
|
||
| @Override | ||
| public void onItemRangeChanged(ObservableArrayList<ChatRoom> chatRooms, int i, int i1) { | ||
| adapter.notifyDataSetChanged(); | ||
| } | ||
|
|
||
| @Override | ||
| public void onItemRangeInserted(ObservableArrayList<ChatRoom> chatRooms, int i, int i1) { | ||
| adapter.notifyDataSetChanged(); | ||
| } | ||
|
|
||
| @Override | ||
| public void onItemRangeMoved(ObservableArrayList<ChatRoom> chatRooms, int i, int i1, int i2) { | ||
| adapter.notifyDataSetChanged(); | ||
| } | ||
|
|
||
| @Override | ||
| public void onItemRangeRemoved(ObservableArrayList<ChatRoom> chatRooms, int i, int i1) { | ||
| adapter.notifyDataSetChanged(); | ||
| } | ||
| } |
| @@ -0,0 +1,11 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <shape xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| <solid android:color="@color/message_recieved_color" /> | ||
|
|
||
| <!--<padding--> | ||
| <!--android:left="1dp"--> | ||
| <!--android:right="1dp"--> | ||
| <!--android:top="1dp" />--> | ||
|
|
||
| <corners android:radius="@dimen/rounded_corner_radius" /> | ||
| </shape> |
| @@ -0,0 +1,11 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <shape xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| <solid android:color="@color/message_sent_color" /> | ||
|
|
||
| <!--<padding--> | ||
| <!--android:left="1dp"--> | ||
| <!--android:right="1dp"--> | ||
| <!--android:top="1dp" />--> | ||
|
|
||
| <corners android:radius="@dimen/rounded_corner_radius" /> | ||
| </shape> |
| @@ -0,0 +1,9 @@ | ||
| <vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:width="24dp" | ||
| android:height="24dp" | ||
| android:viewportHeight="24.0" | ||
| android:viewportWidth="24.0"> | ||
| <path | ||
| android:fillColor="@color/icon_color" | ||
| android:pathData="M2.01,21L23,12 2.01,3 2,10l15,2 -15,2z" /> | ||
| </vector> |
| @@ -0,0 +1,4 @@ | ||
| <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:id="@+id/fragment_container" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" /> |
| @@ -0,0 +1,22 @@ | ||
| <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| android:orientation="vertical" | ||
| android:paddingBottom="8dp" | ||
| android:paddingLeft="8dp" | ||
| android:paddingRight="8dp" | ||
| android:paddingTop="8dp"> | ||
|
|
||
| <TextView | ||
| android:id="@+id/header" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:textSize="22sp"/> | ||
|
|
||
| <TextView | ||
| android:id="@+id/text" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" /> | ||
|
|
||
|
|
||
| </LinearLayout> |
| @@ -0,0 +1,46 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent"> | ||
|
|
||
| <ListView | ||
| android:id="@+id/listView" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| android:layout_marginBottom="48dip" | ||
| android:divider="@null" | ||
| android:background="@color/messages_background" | ||
| android:showDividers="none" | ||
| android:stackFromBottom="true" | ||
| android:transcriptMode="alwaysScroll" /> | ||
|
|
||
| <LinearLayout | ||
| android:layout_width="match_parent" | ||
| android:layout_height="48dip" | ||
| android:layout_alignParentBottom="true" | ||
| android:layout_margin="0dp" | ||
| android:background="#FFFFFF" | ||
| android:orientation="horizontal" | ||
| android:padding="0dp"> | ||
|
|
||
| <EditText | ||
| android:id="@+id/newmsg" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:layout_marginLeft="10dp" | ||
| android:layout_weight="10" | ||
| android:hint="Send a message" /> | ||
|
|
||
| <ImageButton | ||
| android:id="@+id/newmsgsend" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:layout_gravity="center_vertical" | ||
| android:layout_weight="1" | ||
| android:background="#FFFFFF" | ||
| android:src="@drawable/ic_send_black" | ||
|
|
||
| /> | ||
| </LinearLayout> | ||
|
|
||
| </RelativeLayout> |
| @@ -0,0 +1,12 @@ | ||
| <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| android:gravity="center_horizontal" | ||
| android:orientation="vertical"> | ||
|
|
||
| <ListView | ||
| android:id="@+id/listView" | ||
| android:layout_width="fill_parent" | ||
| android:layout_height="fill_parent" /> | ||
|
|
||
| </LinearLayout> |
| @@ -0,0 +1,18 @@ | ||
| <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| android:gravity="left" | ||
| android:orientation="vertical" | ||
| android:padding="4dp"> | ||
|
|
||
| <TextView | ||
| android:id="@+id/text" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:background="@drawable/message_recieved_rounded_corner" | ||
| android:paddingTop="4dp" | ||
| android:paddingBottom="4dp" | ||
| android:paddingLeft="8dp" | ||
| android:paddingRight="8dp" /> | ||
|
|
||
| </LinearLayout> |
| @@ -0,0 +1,18 @@ | ||
| <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| android:gravity="right" | ||
| android:orientation="vertical" | ||
| android:padding="4dp"> | ||
|
|
||
| <TextView | ||
| android:id="@+id/text" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:background="@drawable/message_sent_rounded_corner" | ||
| android:paddingTop="4dp" | ||
| android:paddingBottom="4dp" | ||
| android:paddingLeft="8dp" | ||
| android:paddingRight="8dp" /> | ||
|
|
||
| </LinearLayout> |
| @@ -0,0 +1,28 @@ | ||
| package at.renehollander.mobileapp.endpoint; | ||
|
|
||
| import at.renehollander.mobileapp.handler.ChatHandler; | ||
| import at.renehollander.mobileapp.util.Maps; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
|
|
||
| import javax.inject.Named; | ||
| import javax.ws.rs.GET; | ||
| import javax.ws.rs.Path; | ||
| import javax.ws.rs.core.Response; | ||
| import java.util.Date; | ||
|
|
||
| @Named | ||
| @Path("/test") | ||
| public class TestEndpoint { | ||
|
|
||
| @Autowired | ||
| private ChatHandler chatHandler; | ||
|
|
||
| @GET | ||
| public Response get() { | ||
| System.out.println("here"); | ||
| chatHandler.onChat(null, Maps.of("room", "Room 1", "user", "Rene8888", "date", new Date(), "text", "hellooooooo")); | ||
| chatHandler.onChat(null, Maps.of("room", "Room 2", "user", "Rene8888", "date", new Date(), "text", "hellooooooo")); | ||
| return Response.status(200).build(); | ||
| } | ||
|
|
||
| } |