Exemplo n.º 1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.DialogueActivity);

            _Instance = this;

            if (MessageDBManager.Get().IsLoaded == false)
            {
                ContactDBManager.Get();                                 //연락처를 모두 메모리에 올림
                LableDBManager.Get().Load();                            //레이블 DB를 모두 메모리에 올림
                MessageDBManager.Get().RefreshLastMessageAll();
            }


            _CurAddress   = Intent.GetStringExtra("address");                                                            //액티비티 인자로 전화번호를 받는다.
            _CurThread_id = MessageDBManager.Get().GetThreadId(_CurAddress);                                             //해당 전화번호로 등록된 thread_id를 찾는다.

            _CurDialogue = MessageDBManager.Get().LoadDialogue(_CurThread_id, false, (int)TextMessage.MESSAGE_TYPE.ALL); //thread_id로 기존에 대화가 존재하는지 찾는다.
            if (_CurDialogue == null)                                                                                    //대화가 없으면 새로 만든다.
            {
                CreateNewDialogue(_CurAddress);
            }

            SetupLayout();

            SetupToolbar();

            //문자 전송 브로드캐스트 리시버 초기화
            _SmsSentReceiver = new SmsSentReceiver();
            _SmsSentReceiver.SentCompleteEvent += _SmsSentReceiver_SentCompleteEvent;
        }
Exemplo n.º 2
0
        public override void OnReceive(Context context, Intent intent)
        {
            var msgs = Telephony.Sms.Intents.GetMessagesFromIntent(intent);

            string      displayName = string.Empty;
            int         unreadCnt   = 0;
            TextMessage objMsg      = null;

            foreach (var msg in msgs)
            {
                objMsg = ConvertToCustomMessageType(msg);                                                      //시스템 메시지 형식을 레뜨레 메시지 형식으로 변환

                UpdateMessage(context, objMsg);                                                                //메시지를 안드로이드 메시지 DB에 삽입

                ContactData objContact = ContactDBManager.Get().GetContactDataByAddress(objMsg.Address, true); //연락처에 있는지 조회

                //연락처에 없으면 서버에 전송.
                if (objContact == null)
                {
                    if (DataStorageManager.LoadBoolData(context, "useOfflineMode", false) == true)
                    {
                        //오프라인 모드 사용 시
                    }
                    else
                    {
                        //온라인 모드 사용 시
                        LableDBManager.Get().AccumulateLableDB(objMsg);                                 //서버에서 레이블 데이터 받은 후 레이블 DB에 저장
                    }

                    displayName = objMsg.Address;                                                   //연락처에 없으면 전화번호로 이름 표시
                }
                else
                {
                    displayName = objContact.Name;                                                  //연락처에 있으면 표시될 이름 변경
                }

                unreadCnt++;                                                                                                                          //읽지않은 개수 카운트

                NotificationHandler.ShowNotification(context, "Lettre Channel 1", displayName, objMsg.Msg, objMsg.Address, "Ticker", 101, unreadCnt); //알림 표시

                //IsLoaded가 true이면 어플이 포그라운드, 메시지 목록이 메모리에 올라와있는 상태임.
                //false이면 최근 메시지목록을 불러오지 않는다. (메모리에 올라간 메시지가 없기 때문에 Refresh하려면 크래시남)
                if (MessageDBManager.Get().IsLoaded == true)
                {
                    long thread_id = MessageDBManager.Get().GetThreadId(objMsg.Address);
                    MessageDBManager.Get().RefreshLastMessage(thread_id);                       //해당 메시지가 속하는 대화를 찾아 최신문자를 새로고침함.
                }
            }

            MainFragActivity.RefreshUI();               //UI 새로고침
        }