Search in sources :

Example 11 with ResultThreads

use of com.fanap.podchat.model.ResultThreads in project pod-chat-android-sdk by FanapSoft.

the class ChatTest method populateThreadsListFromCacheOnly.

// requests for list of threads from cache
@Test
public void populateThreadsListFromCacheOnly() {
    chatListeners = new ChatListener() {

        @Override
        public void onGetThread(String content, ChatResponse<ResultThreads> thread) {
            if (thread.isCache()) {
                System.out.println("Received List: " + content);
                threads.addAll(thread.getResult().getThreads());
                resumeProcess();
            }
        }
    };
    chat.addListener(chatListeners);
    RequestThread requestThread = new RequestThread.Builder().count(25).build();
    presenter.getThreads(requestThread, null);
    pauseProcess();
    System.out.println("Received List: " + threads.size());
}
Also used : ResultThreads(com.fanap.podchat.model.ResultThreads) ChatListener(com.fanap.podchat.chat.ChatListener) RequestThread(com.fanap.podchat.requestobject.RequestThread) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

Example 12 with ResultThreads

use of com.fanap.podchat.model.ResultThreads in project pod-chat-android-sdk by FanapSoft.

the class ChatTest method populateThreadsListFromServerOrCache.

// requests for list of threads
@Test
public void populateThreadsListFromServerOrCache() {
    chatListeners = new ChatListener() {

        @Override
        public void onGetThread(String content, ChatResponse<ResultThreads> thread) {
            System.out.println("Received List: " + content);
            threads.addAll(thread.getResult().getThreads());
        }
    };
    chat.addListener(chatListeners);
    RequestThread requestThread = new RequestThread.Builder().count(25).build();
    presenter.getThreads(requestThread, null);
    long t1 = System.currentTimeMillis();
    Mockito.verify(view, Mockito.after(10000).atLeastOnce()).onGetThreadList(Mockito.any(), Mockito.any());
    long t2 = System.currentTimeMillis();
    System.out.println("Received List: " + threads.size() + " after: " + (t2 - t1) + " ms");
}
Also used : ResultThreads(com.fanap.podchat.model.ResultThreads) ChatListener(com.fanap.podchat.chat.ChatListener) RequestThread(com.fanap.podchat.requestobject.RequestThread) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

Example 13 with ResultThreads

use of com.fanap.podchat.model.ResultThreads in project pod-chat-android-sdk by FanapSoft.

the class ChatTest method populateThreadsListFromServerOnly.

// requests for list of threads from server
@Test
public void populateThreadsListFromServerOnly() {
    chatListeners = new ChatListener() {

        @Override
        public void onGetThread(String content, ChatResponse<ResultThreads> thread) {
            if (!thread.isCache()) {
                System.out.println("Received List: " + content);
                threads.addAll(thread.getResult().getThreads());
                resumeProcess();
            }
        }
    };
    chat.setListener(chatListeners);
    RequestThread requestThread = new RequestThread.Builder().count(25).withNoCache().build();
    presenter.getThreads(requestThread, null);
    pauseProcess();
    System.out.println("Received List: " + threads.size());
}
Also used : ResultThreads(com.fanap.podchat.model.ResultThreads) ChatListener(com.fanap.podchat.chat.ChatListener) RequestThread(com.fanap.podchat.requestobject.RequestThread) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

Example 14 with ResultThreads

use of com.fanap.podchat.model.ResultThreads in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method reformatGetThreadsResponse.

/**
 * Reformat the get thread response
 */
private ChatResponse<ResultThreads> reformatGetThreadsResponse(ChatMessage chatMessage, Callback callback) {
    ChatResponse<ResultThreads> outPutThreads = new ChatResponse<>();
    ArrayList<Thread> threads = gson.fromJson(chatMessage.getContent(), new TypeToken<ArrayList<Thread>>() {
    }.getType());
    if (cache) {
        // get threads summary shouldn't update cache
        if (!handlerSend.containsKey(chatMessage.getUniqueId())) {
            // messageDatabaseHelper.saveThreads(threads);
            dataSource.saveThreadResultFromServer(threads);
        }
    }
    ResultThreads resultThreads = new ResultThreads();
    resultThreads.setThreads(threads);
    resultThreads.setContentCount(chatMessage.getContentCount());
    outPutThreads.setErrorCode(0);
    outPutThreads.setErrorMessage("");
    outPutThreads.setHasError(false);
    outPutThreads.setUniqueId(chatMessage.getUniqueId());
    if (callback != null) {
        resultThreads.setHasNext(threads.size() + callback.getOffset() < chatMessage.getContentCount());
        resultThreads.setNextOffset(callback.getOffset() + threads.size());
    }
    outPutThreads.setResult(resultThreads);
    return outPutThreads;
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) ResultThreads(com.fanap.podchat.model.ResultThreads) ChatResponse(com.fanap.podchat.model.ChatResponse) RequestCreateThread(com.fanap.podchat.requestobject.RequestCreateThread) ResultPinThread(com.fanap.podchat.chat.pin.pin_thread.model.ResultPinThread) Thread(com.fanap.podchat.mainmodel.Thread) RequestLeaveThread(com.fanap.podchat.requestobject.RequestLeaveThread) HandlerThread(android.os.HandlerThread) PinThread(com.fanap.podchat.chat.pin.pin_thread.PinThread) ResultLeaveThread(com.fanap.podchat.model.ResultLeaveThread) RequestMuteThread(com.fanap.podchat.requestobject.RequestMuteThread) ResultJoinPublicThread(com.fanap.podchat.chat.thread.public_thread.ResultJoinPublicThread) RequestJoinPublicThread(com.fanap.podchat.chat.thread.public_thread.RequestJoinPublicThread) PublicThread(com.fanap.podchat.chat.thread.public_thread.PublicThread) RequestThread(com.fanap.podchat.requestobject.RequestThread) ResultThread(com.fanap.podchat.model.ResultThread) RequestPinThread(com.fanap.podchat.chat.pin.pin_thread.model.RequestPinThread)

Example 15 with ResultThreads

use of com.fanap.podchat.model.ResultThreads in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method publishThreadsList.

private String publishThreadsList(String uniqueId, Long finalOffset, ThreadManager.ThreadResponse cacheThreadResponse) {
    ChatResponse<ResultThreads> chatResponse = new ChatResponse<>();
    List<Thread> threadList = cacheThreadResponse.getThreadList();
    chatResponse.setCache(true);
    long contentCount = cacheThreadResponse.getContentCount();
    ResultThreads resultThreads = new ResultThreads();
    resultThreads.setThreads(threadList);
    resultThreads.setContentCount(contentCount);
    chatResponse.setCache(true);
    resultThreads.setHasNext(threadList.size() + finalOffset < contentCount);
    resultThreads.setNextOffset(finalOffset + threadList.size());
    chatResponse.setResult(resultThreads);
    chatResponse.setUniqueId(uniqueId);
    String result = gson.toJson(chatResponse);
    listenerManager.callOnGetThread(result, chatResponse);
    return result;
}
Also used : ResultThreads(com.fanap.podchat.model.ResultThreads) ChatResponse(com.fanap.podchat.model.ChatResponse) RequestCreateThread(com.fanap.podchat.requestobject.RequestCreateThread) ResultPinThread(com.fanap.podchat.chat.pin.pin_thread.model.ResultPinThread) Thread(com.fanap.podchat.mainmodel.Thread) RequestLeaveThread(com.fanap.podchat.requestobject.RequestLeaveThread) HandlerThread(android.os.HandlerThread) PinThread(com.fanap.podchat.chat.pin.pin_thread.PinThread) ResultLeaveThread(com.fanap.podchat.model.ResultLeaveThread) RequestMuteThread(com.fanap.podchat.requestobject.RequestMuteThread) ResultJoinPublicThread(com.fanap.podchat.chat.thread.public_thread.ResultJoinPublicThread) RequestJoinPublicThread(com.fanap.podchat.chat.thread.public_thread.RequestJoinPublicThread) PublicThread(com.fanap.podchat.chat.thread.public_thread.PublicThread) RequestThread(com.fanap.podchat.requestobject.RequestThread) ResultThread(com.fanap.podchat.model.ResultThread) RequestPinThread(com.fanap.podchat.chat.pin.pin_thread.model.RequestPinThread)

Aggregations

ResultThreads (com.fanap.podchat.model.ResultThreads)28 RequestThread (com.fanap.podchat.requestobject.RequestThread)28 ChatListener (com.fanap.podchat.chat.ChatListener)24 Test (org.junit.Test)14 LargeTest (android.support.test.filters.LargeTest)12 Thread (com.fanap.podchat.mainmodel.Thread)9 ChatResponse (com.fanap.podchat.model.ChatResponse)7 FlakyTest (android.support.test.filters.FlakyTest)5 MediumTest (android.support.test.filters.MediumTest)5 HandlerThread (android.os.HandlerThread)4 PinThread (com.fanap.podchat.chat.pin.pin_thread.PinThread)4 RequestPinThread (com.fanap.podchat.chat.pin.pin_thread.model.RequestPinThread)4 ResultPinThread (com.fanap.podchat.chat.pin.pin_thread.model.ResultPinThread)4 PublicThread (com.fanap.podchat.chat.thread.public_thread.PublicThread)4 RequestJoinPublicThread (com.fanap.podchat.chat.thread.public_thread.RequestJoinPublicThread)4 ResultJoinPublicThread (com.fanap.podchat.chat.thread.public_thread.ResultJoinPublicThread)4 ResultHistory (com.fanap.podchat.model.ResultHistory)4 ResultLeaveThread (com.fanap.podchat.model.ResultLeaveThread)4 ResultThread (com.fanap.podchat.model.ResultThread)4 RequestCreateThread (com.fanap.podchat.requestobject.RequestCreateThread)4