コード例 #1
0
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            ActivityInstance = this;
            progress         = new ProgressDialogHelper(this);
            signInService    = new SignInService();
            bitmapService    = new BitmapOperationService();
            appSettings      = SharedPreferencesHelper.GetAppSettings(this);
            if (!appSettings.ChatDisabled)
            {
                this.chatHubClientService = ChatHubClientService.GetServiceInstance(bearerToken);
            }
            this.messagesService = new MessagesService(bearerToken);
            SetContentView(Resource.Layout.ConversationActivity);
            SetupViews(savedInstanceState);
            SetupConversationToolbar();
            pageNumber = 0;
            GetExtras();
            player = new MediaPlayer();
            player.SetDataSource(this, Android.Net.Uri.Parse("android.resource://" + this.PackageName + "/raw/" + Resource.Raw.message_sound));
            player.Prepare();
            progress.ShowProgressDialog("Trwa pobieranie wiadomoœci...");
            await SetupIntelocutorInfo();
            await GetAndDisplayMesages(savedInstanceState);

            coversationsLayoutWrapper.Visibility = ViewStates.Visible;
            progress.CloseProgressDialog();
        }
コード例 #2
0
        private void TimerCallBackMethod(object state)
        {
            if (IsScreenOff())
            {
                SetLastTurnOffScreenDate();

                if (this.chatHubClientService.IsConnected())
                {
                    StopConnectionAfterTimeout();
                }
                else if (lastConnectionDate.AddMinutes(12) < DateTime.Now)
                {
                    lastConnectionDate        = DateTime.Now;
                    this.chatHubClientService = ChatHubClientService.GetServiceInstance(bearerToken);
                }
            }
            else
            {
                lastConnectionDate    = DateTime.Now;
                lastScreenTurnOffDate = null;
                if (!this.chatHubClientService.IsConnected())
                {
                    this.chatHubClientService = ChatHubClientService.GetServiceInstance(bearerToken);
                }
            }
        }
コード例 #3
0
        private void SendMessage()
        {
            if (editTextMessage.Text != null & editTextMessage.Text != string.Empty)
            {
                if (chatHubClientService != null && chatHubClientService.IsConnected())
                {
                    var date    = DateTime.Now;
                    var message = new ConversationMessage();
                    message.MessageContent = editTextMessage.Text;
                    message.UserWasSender  = true;
                    message.ConversationId = this.conversationInfoModel.ConversationId;
                    message.MessageHeader  = String.Format("ja, {0} {1}", date.GetDateDottedStringFormat(), date.GetTimeColonStringFormat());

                    this.conversationMessagesListAdapter.AddReceivedMessage(message);
                    chatHubClientService.SendMessage(editTextMessage.Text, this.conversationInfoModel.InterlocutorId.ToString(), this.conversationInfoModel.ConversationId);

                    editTextMessage.Text = string.Empty;
                }
                else
                {
                    if (appSettings.ChatDisabled)
                    {
                        Action actionOnConfirm = () =>
                        {
                            appSettings.ChatDisabled = false;
                            SharedPreferencesHelper.SetAppSettings(this, appSettings);
                            StartService(new Intent(this.ApplicationContext, typeof(MessengerService)));
                            this.chatHubClientService = ChatHubClientService.GetServiceInstance(bearerToken);
                        };

                        AlertsService.ShowConfirmDialog(this, "Masz wy³¹czon¹ us³ugê czatu. Czy chcesz j¹ teraz w³¹czyæ?", actionOnConfirm);
                    }
                    else
                    {
                        AlertsService.ShowLongToast(this, "Nie mogê po³¹czyæ siê z serwerem. Upewnij siê czy masz dostêp do internetu.");
                    }
                }
            }
        }
コード例 #4
0
        private void DoWork()
        {
            this.signalRThread = new Thread(() =>
            {
                timeoutInSeconds             = 15;
                timerInterval                = 1000 * 5;
                displayManager               = (DisplayManager)GetSystemService(Context.DisplayService);
                powerManager                 = (PowerManager)GetSystemService(Context.PowerService);
                this.sharedPreferencesHelper = new SharedPreferencesHelper(Application.ApplicationContext);
                this.bearerToken             = (string)this.sharedPreferencesHelper.GetSharedPreference <string>(SharedPreferencesKeys.BEARER_TOKEN);
                this.chatHubClientService    = ChatHubClientService.GetServiceInstance(bearerToken);
                lastConnectionDate           = DateTime.Now;
                this.chatHubClientService.RegisterReceiveMessages(ShowNotification);
                this.chatHubClientService.RegisterNotReceivedMessagesChecked(SetCheckedNotReceivedMessages);


                timer = new Timer(new TimerCallback(TimerCallBackMethod));
                timer.Change(timerInterval, timerInterval);
            }
                                            );
            signalRThread.Start();
        }
コード例 #5
0
        public override async void OnReceive(Context context, Intent intent)
        {
            bearerToken = SharedPreferencesHelper.GetBearerToken(context);
            if (bearerToken == null)
            {
                return;
            }
            var isUserConnectedToInternet = await DoesUserHasInternetConnection(bearerToken);

            if (!isUserConnectedToInternet)
            {
                return;
            }
            this.context = context.ApplicationContext;
            var powerManager = (PowerManager)context.GetSystemService(Context.PowerService);

            _wakeLock = powerManager.NewWakeLock(WakeLockFlags.Partial, "MSH");
            _wakeLock.Acquire();
            timerTick     = 1;
            timerInterval = 1000 * 5;
            timer         = new System.Threading.Timer(new TimerCallback(TimerCallBackMethod));
            timer.Change(timerInterval, timerInterval);

            this.appsettings = SharedPreferencesHelper.GetAppSettings(this.context);
            if (!appsettings.ChatDisabled)
            {
                MessengerService.AddOutsidePendingWork();
                chatHubServiceInstance = ChatHubClientService.GetServiceInstance(bearerToken);
            }
            if (!appsettings.NotificationsDisabled)
            {
                SetCheckingNewAdvertisementsAction(context);
                checkingNewAdvertsAction();
            }
            else
            {
                checkingNewAdvertsFinished = true;
            }
        }