Search in sources :

Example 1 with RoomUserAdapter

use of ingage.ingage20.adapters.RoomUserAdapter in project iNGAGE by davis123123.

the class RoomUsersActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_room_users);
    String type = "check";
    String json_string = "";
    chatRoomManager = new ChatRoomManager(getApplicationContext());
    HashMap<String, String> chatroom = chatRoomManager.getUserDetails();
    String thread_id = chatroom.get(ChatRoomManager.THREAD_ID);
    chatRoomHandler = new ChatRoomHandler(getApplicationContext());
    sessionManager = new SessionManager(getApplicationContext());
    HashMap<String, String> user = sessionManager.getUserDetails();
    ownUsername = user.get(SessionManager.KEY_NAME);
    roomUserRecyclerView = (RecyclerView) findViewById(R.id.rv_posts);
    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    roomUserRecyclerView.setLayoutManager(layoutManager);
    roomUserAdapter = new RoomUserAdapter(this);
    roomUserRecyclerView.setAdapter(roomUserAdapter);
    try {
        json_string = chatRoomHandler.execute(type, thread_id).get();
        Log.d("CHECK", "result : " + json_string);
    } catch (InterruptedException | ExecutionException e) {
        e.printStackTrace();
    }
    try {
        jsonObject = new JSONObject(json_string);
        jsonArray = jsonObject.getJSONArray("users");
        int count = 0;
        String username, token;
        username = "-";
        while (count < jsonArray.length()) {
            JSONObject JO = jsonArray.getJSONObject(count);
            username = JO.getString("username");
            token = JO.getString("token");
            ChatRoomUserHelper chatRoomUserHelper = new ChatRoomUserHelper(username, token);
            if (!ownUsername.equals(chatRoomUserHelper.getUsername())) {
                roomUserAdapter.add(chatRoomUserHelper);
            }
            count++;
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
Also used : ChatRoomHandler(ingage.ingage20.handlers.ChatRoomHandler) SessionManager(ingage.ingage20.managers.SessionManager) ChatRoomManager(ingage.ingage20.managers.ChatRoomManager) JSONException(org.json.JSONException) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ChatRoomUserHelper(ingage.ingage20.helpers.ChatRoomUserHelper) RoomUserAdapter(ingage.ingage20.adapters.RoomUserAdapter) JSONObject(org.json.JSONObject) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RoomUserAdapter (ingage.ingage20.adapters.RoomUserAdapter)1 ChatRoomHandler (ingage.ingage20.handlers.ChatRoomHandler)1 ChatRoomUserHelper (ingage.ingage20.helpers.ChatRoomUserHelper)1 ChatRoomManager (ingage.ingage20.managers.ChatRoomManager)1 SessionManager (ingage.ingage20.managers.SessionManager)1 ExecutionException (java.util.concurrent.ExecutionException)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1