protected override void OnResume()
 {
     // Clear any notifications for this conversation
     PushNotificationReceiver.GetNotifications(this).Clear(mConversation);
     base.OnResume();
     SetTitle(mConversation != null);
 }
        private void Refresh()
        {
            if (!GetLayerClient().IsAuthenticated)
            {
                return;
            }

            mConversationName.Text     = AtlasUtil.GetConversationMetadataTitle(mConversation);
            mShowNotifications.Checked = PushNotificationReceiver.GetNotifications(this).IsEnabled(mConversation.Id);

            ISet <string> participantsMinusMe = new HashSet <string>(mConversation.Participants);

            participantsMinusMe.Remove(GetLayerClient().AuthenticatedUserId);

            if (participantsMinusMe.Count == 0)
            {
                // I've been removed
                mConversationName.Enabled = false;
                mLeaveButton.Visibility   = ViewStates.Gone;
            }
            else if (participantsMinusMe.Count == 1)
            {
                // 1-on-1
                mConversationName.Enabled = false;
                mLeaveButton.Visibility   = ViewStates.Gone;
            }
            else
            {
                // Group
                mConversationName.Enabled = true;
                mLeaveButton.Visibility   = ViewStates.Visible;
            }
            mParticipantAdapter.Refresh();
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            mConversationName        = FindViewById <EditText>(Resource.Id.conversation_name);
            mShowNotifications       = FindViewById <Switch>(Resource.Id.show_notifications_switch);
            mParticipantRecyclerView = FindViewById <RecyclerView>(Resource.Id.participants);
            mLeaveButton             = FindViewById <Button>(Resource.Id.leave_button);
            mAddParticipantsButton   = FindViewById <Button>(Resource.Id.add_participant_button);

            // Get Conversation from Intent extras
            Uri conversationId = Intent.GetParcelableExtra(PushNotificationReceiver.LAYER_CONVERSATION_KEY) as Uri;

            mConversation = GetLayerClient().GetConversation(conversationId);
            if (mConversation == null && !IsFinishing)
            {
                Finish();
            }

            mParticipantAdapter = new ParticipantAdapter(this);
            mParticipantRecyclerView.SetAdapter(mParticipantAdapter);

            LinearLayoutManager manager = new LinearLayoutManager(this, LinearLayoutManager.Vertical, false);

            mParticipantRecyclerView.SetLayoutManager(manager);

            mConversationName.EditorAction += (sender, args) =>
            {
                if (args.ActionId == ImeAction.Done || (args.Event != null && args.Event.Action == KeyEventActions.Down && args.Event.KeyCode == Keycode.Enter))
                {
                    string title = ((EditText)sender).Text.ToString().Trim();
                    AtlasUtil.SetConversationMetadataTitle(mConversation, title);
                    Toast.MakeText(this, Resource.String.toast_group_name_updated, ToastLength.Short).Show();
                    args.Handled = true;
                }
                args.Handled = false;
            };

            mShowNotifications.CheckedChange += (sender, args) =>
            {
                PushNotificationReceiver.GetNotifications(this).SetEnabled(mConversation.Id, args.IsChecked);
            };

            mLeaveButton.Click += (sender, args) =>
            {
                SetEnabled(false);
                mConversation.RemoveParticipants(GetLayerClient().AuthenticatedUserId);
                Refresh();
                Intent intent = new Intent(this, typeof(ConversationsListActivity));
                intent.SetFlags(ActivityFlags.ClearTop);
                SetEnabled(true);
                StartActivity(intent);
            };

            mAddParticipantsButton.Click += (sender, args) =>
            {
                // TODO
                Toast.MakeText(this, "Coming soon", ToastLength.Long).Show();
            };
        }
Пример #4
0
        private void Refresh()
        {
            if (!GetLayerClient().IsAuthenticated)
            {
                return;
            }

            /* Account */
            IParticipant participant = GetParticipantProvider().GetParticipant(GetLayerClient().AuthenticatedUserId);

            mAvatar.SetParticipants(GetLayerClient().AuthenticatedUserId);
            mUserName.Text = participant.Name;
            mUserState.SetText(GetLayerClient().IsConnected ? Resource.String.settings_content_connected : Resource.String.settings_content_disconnected);

            /* Notifications */
            mShowNotifications.Checked = PushNotificationReceiver.GetNotifications(this).IsEnabled();

            /* Debug */
            // enable logging through adb: `adb shell setprop log.tag.LayerSDK VERBOSE`
            bool enabledByEnvironment = Android.Util.Log.IsLoggable("LayerSDK", LogPriority.Verbose);

            mVerboseLogging.Enabled = !enabledByEnvironment;
            mVerboseLogging.Checked = enabledByEnvironment || LayerClient.IsLoggingEnabled;
            mAppVersion.Text        = GetString(Resource.String.settings_content_app_version, BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE);
            mAtlasVersion.Text      = AtlasUtil.Version;
            mLayerVersion.Text      = LayerClient.Version;
            mAndroidVersion.Text    = GetString(Resource.String.settings_content_android_version, Build.VERSION.Release, (int)Build.VERSION.SdkInt);
            mUserId.Text            = GetLayerClient().AuthenticatedUserId;

            /* Statistics */
            long totalMessages = 0;
            long totalUnread   = 0;
            IList <Conversation> conversations = GetLayerClient().Conversations;

            foreach (Conversation conversation in conversations)
            {
                totalMessages += conversation.TotalMessageCount.IntValue();
                totalUnread   += conversation.TotalUnreadMessageCount.IntValue();
            }
            mConversationCount.Text  = string.Format("%d", conversations.Count);
            mMessageCount.Text       = string.Format("%d", totalMessages);
            mUnreadMessageCount.Text = string.Format("%d", totalUnread);

            /* Rich Content */
            mDiskUtilization.Text = ReadableByteFormat(GetLayerClient().DiskUtilization);
            long allowance = GetLayerClient().DiskCapacity;

            if (allowance == 0)
            {
                mDiskAllowance.SetText(Resource.String.settings_content_disk_unlimited);
            }
            else
            {
                mDiskAllowance.Text = ReadableByteFormat(allowance);
            }
            mAutoDownloadMimeTypes.Text = string.Join("\n", GetLayerClient().AutoDownloadMimeTypes);
        }
 public ContentAvailableCallback(PushNotificationReceiver pushNotificationReceiver, Context context, string text)
 {
     _receiver = pushNotificationReceiver;
     _context  = context;
     _text     = text;
 }
Пример #6
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // View cache
            mAvatar                = FindViewById <AtlasAvatar>(Resource.Id.avatar);
            mUserName              = FindViewById <TextView>(Resource.Id.user_name);
            mUserState             = FindViewById <TextView>(Resource.Id.user_state);
            mLogoutButton          = FindViewById <Button>(Resource.Id.logout_button);
            mShowNotifications     = FindViewById <Switch>(Resource.Id.show_notifications_switch);
            mVerboseLogging        = FindViewById <Switch>(Resource.Id.logging_switch);
            mAppVersion            = FindViewById <TextView>(Resource.Id.app_version);
            mAtlasVersion          = FindViewById <TextView>(Resource.Id.atlas_version);
            mLayerVersion          = FindViewById <TextView>(Resource.Id.layer_version);
            mAndroidVersion        = FindViewById <TextView>(Resource.Id.android_version);
            mUserId                = FindViewById <TextView>(Resource.Id.user_id);
            mConversationCount     = FindViewById <TextView>(Resource.Id.conversation_count);
            mMessageCount          = FindViewById <TextView>(Resource.Id.message_count);
            mUnreadMessageCount    = FindViewById <TextView>(Resource.Id.unread_message_count);
            mDiskUtilization       = FindViewById <TextView>(Resource.Id.disk_utilization);
            mDiskAllowance         = FindViewById <TextView>(Resource.Id.disk_allowance);
            mAutoDownloadMimeTypes = FindViewById <TextView>(Resource.Id.auto_download_mime_types);
            mAvatar.Init(GetParticipantProvider(), GetPicasso());

            // Long-click copy-to-clipboard
            mUserName.SetOnLongClickListener(this);
            mUserState.SetOnLongClickListener(this);
            mAppVersion.SetOnLongClickListener(this);
            mAndroidVersion.SetOnLongClickListener(this);
            mAtlasVersion.SetOnLongClickListener(this);
            mLayerVersion.SetOnLongClickListener(this);
            mUserId.SetOnLongClickListener(this);
            mConversationCount.SetOnLongClickListener(this);
            mMessageCount.SetOnLongClickListener(this);
            mUnreadMessageCount.SetOnLongClickListener(this);
            mDiskUtilization.SetOnLongClickListener(this);
            mDiskAllowance.SetOnLongClickListener(this);
            mAutoDownloadMimeTypes.SetOnLongClickListener(this);

            // Buttons and switches
            mLogoutButton.Click += (sender, args) =>
            {
                SetEnabled(false);
                new AlertDialog.Builder(this)
                .SetCancelable(false)
                .SetMessage(Resource.String.alert_message_logout)
                .SetPositiveButton(Resource.String.alert_button_logout, (sender_, args_) =>
                {
                    if (Util.Log.IsLoggable(Util.Log.VERBOSE))
                    {
                        Util.Log.v("Deauthenticating");
                    }
                    ((IDialogInterface)sender_).Dismiss();
                    ProgressDialog progressDialog = new ProgressDialog(this);
                    progressDialog.SetMessage(Resources.GetString(Resource.String.alert_dialog_logout));
                    progressDialog.SetCancelable(false);
                    progressDialog.Show();
                    App.Deauthenticate(new AtlasUtilDeauthenticationCallback(this, progressDialog));
                })
                .SetNegativeButton(Resource.String.alert_button_cancel, (sender_, args_) =>
                {
                    ((IDialogInterface)sender_).Dismiss();
                    SetEnabled(true);
                })
                .Show();
            };

            mShowNotifications.CheckedChange += (sender, args) =>
            {
                PushNotificationReceiver.GetNotifications(this).SetEnabled(args.IsChecked);
            };

            mVerboseLogging.CheckedChange += (sender, args) =>
            {
                LayerClient.SetLoggingEnabled(this, args.IsChecked);
                Atlas.Util.Log.SetAlwaysLoggable(args.IsChecked);
                Util.Log.SetAlwaysLoggable(args.IsChecked);
            };
        }
 protected override void OnPause()
 {
     // Update the notification position to the latest seen
     PushNotificationReceiver.GetNotifications(this).Clear(mConversation);
     base.OnPause();
 }