<commit_before>/*
 * Copyright 2016 OpenMarket Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package im.vector;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;

import org.matrix.androidsdk.HomeserverConnectionConfig;
import org.matrix.androidsdk.MXDataHandler;
import org.matrix.androidsdk.MXSession;
import org.matrix.androidsdk.call.IMXCall;
import org.matrix.androidsdk.call.MXCallsManager;
import org.matrix.androidsdk.data.IMXStore;
import org.matrix.androidsdk.data.MXFileStore;
import org.matrix.androidsdk.data.MXMemoryStore;
import org.matrix.androidsdk.data.Room;
import org.matrix.androidsdk.data.RoomState;
import org.matrix.androidsdk.db.MXLatestChatMessageCache;
import org.matrix.androidsdk.db.MXMediasCache;
import org.matrix.androidsdk.listeners.IMXNetworkEventListener;
import org.matrix.androidsdk.listeners.MXEventListener;
import org.matrix.androidsdk.rest.model.Event;
import org.matrix.androidsdk.rest.model.login.Credentials;

import im.vector.activity.VectorCallViewActivity;
import im.vector.activity.CommonActivityUtils;
import im.vector.activity.SplashActivity;
import im.vector.activity.VectorHomeActivity;
import im.vector.gcm.GcmRegistrationManager;
import im.vector.services.EventStreamService;
import im.vector.store.LoginStorage;

import java.util.ArrayList;
import java.util.Collection;

/**
 * Singleton to control access to the Matrix SDK and providing point of control for MXSessions.
 */
public class Matrix {
    // the log tag
    private static final String LOG_TAG = "Matrix";

    // static instance
    private static Matrix instance = null;

    // the application context
    private Context mAppContext;

    // login storage
    private LoginStorage mLoginStorage;

    // list of session
    private ArrayList<MXSession> mMXSessions;

    // GCM registration manager
    private GcmRegistrationManager mGCMRegistrationManager;

    // list of store : some sessions or activities use tmp stores
    // provide an storage to exchange them
    private ArrayList<IMXStore> mTmpStores;

    // tell if the client should be logged out
    public boolean mHasBeenDisconnected = false;

    // i.e the event has been read from another client
    private static final MXEventListener mLiveEventListener = new MXEventListener() {
        @Override
        public void onIgnoredUsersListUpdate() {
            // the application cache will be cleared at next launch if the application is not yet launched
            // else it will be done when onLiveEventsChunkProcessed will be called in VectorHomeActivity.
            VectorHomeActivity.mClearCacheRequired = true;
        }

        private boolean mRefreshUnreadCounter = false;

        @Override
        public void onLiveEvent(Event event, RoomState roomState) {
            mRefreshUnreadCounter |=  Event.EVENT_TYPE_MESSAGE.equals(event.type) || Event.EVENT_TYPE_RECEIPT.equals(event.type);
        }

        @Override
        public void onLiveEventsChunkProcessed() {
            // when the client does not use GCM
            // we need to compute the application badge values

            if ((null != instance) && (null != instance.mMXSessions) && mRefreshUnreadCounter) {
                GcmRegistrationManager gcmMgr = instance.getSharedGCMRegistrationManager();

                // check if the GCM is not available
                if ((null != gcmMgr) && (!gcmMgr.useGCM() || !gcmMgr.hasRegistrationToken())) {
                    int unreadCount = 0;

                    for(MXSession session :  instance.mMXSessions) {
                        if (session.isAlive()) {
                            Collection<Room> rooms = session.getDataHandler().getStore().getRooms();

                            if (null != rooms) {
                                for(Room room : rooms) {
                                    if ((0 != room.getNotificationCount()) || (0 != room.getHighlightCount())) {
                                        unreadCount++;
                                    }
                                }
                            }
                        }
                    }

                    // update the badge counter
                    CommonActivityUtils.updateBadgeCount(instance.mAppContext, unreadCount);
                }
            }

            mRefreshUnreadCounter = false;

            Log.d(LOG_TAG, "onLiveEventsChunkProcessed ");
            EventStreamService.checkDisplayedNotification();
        }
    };
<commit_msg>Update comments<commit_after>/*
 * Copyright 2016 OpenMarket Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package im.vector;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;

import org.matrix.androidsdk.HomeserverConnectionConfig;
import org.matrix.androidsdk.MXDataHandler;
import org.matrix.androidsdk.MXSession;
import org.matrix.androidsdk.call.IMXCall;
import org.matrix.androidsdk.call.MXCallsManager;
import org.matrix.androidsdk.data.IMXStore;
import org.matrix.androidsdk.data.MXFileStore;
import org.matrix.androidsdk.data.MXMemoryStore;
import org.matrix.androidsdk.data.Room;
import org.matrix.androidsdk.data.RoomState;
import org.matrix.androidsdk.db.MXLatestChatMessageCache;
import org.matrix.androidsdk.db.MXMediasCache;
import org.matrix.androidsdk.listeners.IMXNetworkEventListener;
import org.matrix.androidsdk.listeners.MXEventListener;
import org.matrix.androidsdk.rest.model.Event;
import org.matrix.androidsdk.rest.model.login.Credentials;

import im.vector.activity.VectorCallViewActivity;
import im.vector.activity.CommonActivityUtils;
import im.vector.activity.SplashActivity;
import im.vector.activity.VectorHomeActivity;
import im.vector.gcm.GcmRegistrationManager;
import im.vector.services.EventStreamService;
import im.vector.store.LoginStorage;

import java.util.ArrayList;
import java.util.Collection;

/**
 * Singleton to control access to the Matrix SDK and providing point of control for MXSessions.
 */
public class Matrix {
    // the log tag
    private static final String LOG_TAG = "Matrix";

    // static instance
    private static Matrix instance = null;

    // the application context
    private Context mAppContext;

    // login storage
    private LoginStorage mLoginStorage;

    // list of session
    private ArrayList<MXSession> mMXSessions;

    // GCM registration manager
    private GcmRegistrationManager mGCMRegistrationManager;

    // list of store : some sessions or activities use tmp stores
    // provide an storage to exchange them
    private ArrayList<IMXStore> mTmpStores;

    // tell if the client should be logged out
    public boolean mHasBeenDisconnected = false;

    // i.e the event has been read from another client
    private static final MXEventListener mLiveEventListener = new MXEventListener() {
        @Override
        public void onIgnoredUsersListUpdate() {
            // the application cache will be cleared at next launch if the application is not yet launched
            // else it will be done when onLiveEventsChunkProcessed will be called in VectorHomeActivity.
            VectorHomeActivity.mClearCacheRequired = true;
        }

        private boolean mRefreshUnreadCounter = false;

        @Override
        public void onLiveEvent(Event event, RoomState roomState) {
            mRefreshUnreadCounter |=  Event.EVENT_TYPE_MESSAGE.equals(event.type) || Event.EVENT_TYPE_RECEIPT.equals(event.type);
        }

        @Override
        public void onLiveEventsChunkProcessed() {
            // when the client does not use GCM (ie. FDroid),
            // we need to compute the application badge values

            if ((null != instance) && (null != instance.mMXSessions) && mRefreshUnreadCounter) {
                GcmRegistrationManager gcmMgr = instance.getSharedGCMRegistrationManager();

                // perform update: if the GCM is not available or if GCM registration failed
                if ((null != gcmMgr) && (!gcmMgr.useGCM() || !gcmMgr.hasRegistrationToken())) {
                    int unreadCount = 0;

                    for(MXSession session :  instance.mMXSessions) {
                        if (session.isAlive()) {
                            Collection<Room> rooms = session.getDataHandler().getStore().getRooms();

                            if (null != rooms) {
                                for(Room room : rooms) {
                                    if ((0 != room.getNotificationCount()) || (0 != room.getHighlightCount())) {
                                        unreadCount++;
                                    }
                                }
                            }
                        }
                    }

                    // update the badge counter
                    CommonActivityUtils.updateBadgeCount(instance.mAppContext, unreadCount);
                }
            }

            mRefreshUnreadCounter = false;

            Log.d(LOG_TAG, "onLiveEventsChunkProcessed ");
            EventStreamService.checkDisplayedNotification();
        }
    };

{'fraction_non_alphanumeric': 0.07924128634700559, 'fraction_numerical': 0.0021182360870402464, 'mean_word_length': 2.578022735101619, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5617933', 'n_tokens_mistral': 2686, 'n_tokens_neox': 2589, 'n_words': 759}