Search in sources :

Example 6 with RoomSummary

use of org.matrix.androidsdk.data.RoomSummary in project matrix-android-sdk by matrix-org.

the class MXFileStore method saveSummaries.

/**
 * Flush the pending summaries.
 */
private void saveSummaries() {
    if ((mRoomsToCommitForSummaries.size() > 0) && (null != mFileStoreHandler)) {
        // get the list
        final HashSet<String> fRoomsToCommitForSummaries = mRoomsToCommitForSummaries;
        mRoomsToCommitForSummaries = new HashSet<>();
        Runnable r = new Runnable() {

            @Override
            public void run() {
                mFileStoreHandler.post(new Runnable() {

                    public void run() {
                        if (!isKilled()) {
                            long start = System.currentTimeMillis();
                            for (String roomId : fRoomsToCommitForSummaries) {
                                try {
                                    File roomSummaryFile = new File(mStoreRoomsSummaryFolderFile, roomId);
                                    RoomSummary roomSummary = mRoomSummaries.get(roomId);
                                    if (null != roomSummary) {
                                        writeObject("saveSummaries " + roomId, roomSummaryFile, roomSummary);
                                    } else {
                                        deleteRoomSummaryFile(roomId);
                                    }
                                } catch (OutOfMemoryError oom) {
                                    dispatchOOM(oom);
                                } catch (Exception e) {
                                    Log.e(LOG_TAG, "saveSummaries failed : " + e.getMessage());
                                // Toast.makeText(mContext, "saveSummaries failed " + e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
                                }
                            }
                            Log.d(LOG_TAG, "saveSummaries : " + fRoomsToCommitForSummaries.size() + " summaries in " + (System.currentTimeMillis() - start) + " ms");
                        }
                    }
                });
            }
        };
        Thread t = new Thread(r);
        t.start();
    }
}
Also used : File(java.io.File) RoomSummary(org.matrix.androidsdk.data.RoomSummary) HandlerThread(android.os.HandlerThread)

Aggregations

RoomSummary (org.matrix.androidsdk.data.RoomSummary)6 Room (org.matrix.androidsdk.data.Room)4 File (java.io.File)2 Event (org.matrix.androidsdk.rest.model.Event)2 HandlerThread (android.os.HandlerThread)1 ArrayList (java.util.ArrayList)1 MessageRow (org.matrix.androidsdk.adapters.MessageRow)1 RoomState (org.matrix.androidsdk.data.RoomState)1 ReceiptData (org.matrix.androidsdk.rest.model.ReceiptData)1