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();
            };
        }
Exemplo n.º 3
0
 public bool OnLongClick(View v)
 {
     if (v is TextView)
     {
         AtlasUtil.CopyToClipboard(v.Context, Resource.String.settings_clipboard_description, (v as TextView).Text.ToString());
         Toast.MakeText(this, Resource.String.toast_copied_to_clipboard, ToastLength.Short).Show();
         return(true);
     }
     return(false);
 }
 public void SetTitle(bool useConversation)
 {
     if (!useConversation)
     {
         SetTitle(Resource.String.title_select_conversation);
     }
     else
     {
         Title = AtlasUtil.GetConversationTitle(GetLayerClient(), GetParticipantProvider(), mConversation);
     }
 }
        /**
         * Parses the `com.layer.sdk.PUSH` Intent.
         */
        public override void OnReceive(Context context, Intent intent)
        {
            Bundle extras = intent.Extras;

            if (extras == null)
            {
                return;
            }
            string text           = extras.GetString(LAYER_TEXT_KEY, null);
            Uri    conversationId = extras.GetParcelable(LAYER_CONVERSATION_KEY) as Uri;
            Uri    messageId      = extras.GetParcelable(LAYER_MESSAGE_KEY) as Uri;

            if (intent.Action.Equals(ACTION_PUSH))
            {
                // New push from Layer
                if (Util.Log.IsLoggable(Util.Log.VERBOSE))
                {
                    Util.Log.v("Received notification for: " + messageId);
                }
                if (messageId == null)
                {
                    if (Util.Log.IsLoggable(Util.Log.ERROR))
                    {
                        Util.Log.e("No message to notify: " + extras);
                    }
                    return;
                }
                if (conversationId == null)
                {
                    if (Util.Log.IsLoggable(Util.Log.ERROR))
                    {
                        Util.Log.e("No conversation to notify: " + extras);
                    }
                    return;
                }

                if (!GetNotifications(context).IsEnabled())
                {
                    if (Util.Log.IsLoggable(Util.Log.VERBOSE))
                    {
                        Util.Log.v("Blocking notification due to global app setting");
                    }
                    return;
                }

                if (!GetNotifications(context).IsEnabled(conversationId))
                {
                    if (Util.Log.IsLoggable(Util.Log.VERBOSE))
                    {
                        Util.Log.v("Blocking notification due to conversation detail setting");
                    }
                    return;
                }

                // Try to have content ready for viewing before posting a Notification
                AtlasUtil.WaitForContent(App.GetLayerClient().Connect(), messageId, new ContentAvailableCallback(this, context, text));
            }
            else if (intent.Action.Equals(ACTION_CANCEL))
            {
                // User swiped notification out
                if (Util.Log.IsLoggable(Util.Log.VERBOSE))
                {
                    Util.Log.v("Cancelling notifications for: " + conversationId);
                }
                GetNotifications(context).Clear(conversationId);
            }
            else
            {
                if (Util.Log.IsLoggable(Util.Log.ERROR))
                {
                    Util.Log.e("Got unknown intent action: " + intent.Action);
                }
            }
        }
            private void Update(Context context, Conversation conversation, IMessage message)
            {
                string messagesString = mMessages.GetString(conversation.Id.ToString(), null);

                if (messagesString == null)
                {
                    return;
                }

                // Get current notification texts
                IDictionary <long, string> positionText = new Dictionary <long, string>();

                try {
                    JSONObject messagesJson = new JSONObject(messagesString);
                    IIterator  iterator     = messagesJson.Keys();
                    while (iterator.HasNext)
                    {
                        string     messageId   = (string)iterator.Next();
                        JSONObject messageJson = messagesJson.GetJSONObject(messageId);
                        long       position    = messageJson.GetLong(KEY_POSITION);
                        string     text        = messageJson.GetString(KEY_TEXT);
                        positionText[position] = text;
                    }
                } catch (JSONException e) {
                    if (Util.Log.IsLoggable(Util.Log.ERROR))
                    {
                        Util.Log.e(e.Message, e);
                    }
                    return;
                }

                // Sort by message position
                List <long> positions = new List <long>(positionText.Keys);

                positions.Sort();

                // Construct notification
                string conversationTitle = AtlasUtil.GetConversationTitle(App.GetLayerClient(), App.GetParticipantProvider(), conversation);

                NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle().SetBigContentTitle(conversationTitle);
                int i;

                if (positions.Count <= MAX_MESSAGES)
                {
                    i = 0;
                    inboxStyle.SetSummaryText((string)null);
                }
                else
                {
                    i = positions.Count - MAX_MESSAGES;
                    inboxStyle.SetSummaryText(context.GetString(Resource.String.notifications_num_more, i));
                }
                while (i < positions.Count)
                {
                    inboxStyle.AddLine(positionText[positions[i++]]);
                }

                string collapsedSummary = positions.Count == 1 ? positionText[positions[0]] :
                                          context.GetString(Resource.String.notifications_new_messages, positions.Count);

                // Construct notification
                // TODO: use large icon based on avatars
                var mBuilder = new NotificationCompat.Builder(context)
                               .SetSmallIcon(Resource.Drawable.notification)
                               .SetContentTitle(conversationTitle)
                               .SetContentText(collapsedSummary)
                               .SetAutoCancel(true)
                               .SetLights(ContextCompat.GetColor(context, Resource.Color.atlas_action_bar_background), 100, 1900)
                               .SetPriority(NotificationCompat.PriorityHigh)
                               .SetDefaults(NotificationCompat.DefaultSound | NotificationCompat.DefaultVibrate)
                               .SetStyle(inboxStyle);

                // Intent to launch when clicked
                Intent clickIntent = new Intent(context, typeof(MessagesListActivity))
                                     .SetPackage(context.ApplicationContext.PackageName)
                                     .PutExtra(LAYER_CONVERSATION_KEY, conversation.Id)
                                     .PutExtra(LAYER_MESSAGE_KEY, message.Id)
                                     .SetFlags(ActivityFlags.ClearTop);
                PendingIntent clickPendingIntent = PendingIntent.GetActivity(
                    context, Interlocked.Increment(ref sPendingIntentCounterFlag),
                    clickIntent, PendingIntentFlags.OneShot);

                mBuilder.SetContentIntent(clickPendingIntent);

                // Intent to launch when swiped out
                Intent cancelIntent = new Intent(ACTION_CANCEL)
                                      .SetPackage(context.ApplicationContext.PackageName)
                                      .PutExtra(LAYER_CONVERSATION_KEY, conversation.Id)
                                      .PutExtra(LAYER_MESSAGE_KEY, message.Id);
                PendingIntent cancelPendingIntent = PendingIntent.GetBroadcast(
                    context, Interlocked.Increment(ref sPendingIntentCounterFlag),
                    cancelIntent, PendingIntentFlags.OneShot);

                mBuilder.SetDeleteIntent(cancelPendingIntent);

                // Show the notification
                mManager.Notify(conversation.Id.ToString(), MESSAGE_ID, mBuilder.Build());
            }
Exemplo n.º 7
0
        public void Awake()
        {
            var toolController = FindObjectOfType <ToolManager>().m_properties;

            if (toolController == null)
            {
                return;
            }

            toolController.AddExtraToolToController <SelectionTool>();
            var textureButton = AtlasUtil.LoadTextureFromAssembly("ModTools.SelectionToolButton.png");

            textureButton.name = "SelectionToolButton";
            var textureBar = AtlasUtil.LoadTextureFromAssembly("ModTools.SelectionToolBar.png");

            textureBar.name = "SelectionToolBar";

            var escButton = (UIButton)UIView.Find("Esc");
            var atlas     = AtlasUtil.CreateAtlas(new[]
            {
                textureButton,
                textureBar,
                GetTextureByName(escButton.disabledBgSprite, escButton.atlas),
                GetTextureByName(escButton.hoveredBgSprite, escButton.atlas),
                GetTextureByName(escButton.pressedBgSprite, escButton.atlas),
                GetTextureByName(escButton.normalBgSprite, escButton.atlas),
            });
            var buttonGo = new GameObject("SelectionToolButton");

            button                  = buttonGo.AddComponent <UIButton>();
            button.tooltip          = "Mod Tools - Selection Tool";
            button.normalFgSprite   = "SelectionToolButton";
            button.hoveredFgSprite  = "SelectionToolButton";
            button.pressedFgSprite  = "SelectionToolButton";
            button.disabledFgSprite = "SelectionToolButton";
            button.focusedFgSprite  = "SelectionToolButton";
            button.normalBgSprite   = escButton.normalBgSprite;
            button.focusedBgSprite  = escButton.normalBgSprite;
            button.hoveredBgSprite  = escButton.hoveredBgSprite;
            button.pressedBgSprite  = escButton.pressedBgSprite;
            button.disabledBgSprite = escButton.disabledBgSprite;
            button.playAudioEvents  = true;
            button.width            = 46f;
            button.height           = 46f;
            UIView.GetAView().AttachUIComponent(buttonGo);
            button.absolutePosition = escButton.absolutePosition - new Vector3(95, 0, 0);
            button.atlas            = atlas;
            button.eventClicked    += (c, e) => ToggleTool();
            button.isVisible        = MainWindow.Instance.Config.SelectionTool;

            var dragGo = new GameObject("SelectionToolDragHandler");

            dragGo.transform.parent        = button.transform;
            dragGo.transform.localPosition = Vector3.zero;
            var drag = dragGo.AddComponent <UIDragHandle>();

            drag.tooltip = button.tooltip;
            drag.width   = button.width;
            drag.height  = button.height;

            var barGo = new GameObject("SelectionToolBar");

            bar = barGo.AddComponent <UITiledSprite>();
            UIView.GetAView().AttachUIComponent(barGo);
            bar.atlas = atlas;
            bar.width = UIView.GetAView().fixedWidth;
            var relativePosition = bar.relativePosition;

            relativePosition.x   = 0;
            bar.relativePosition = relativePosition;
            bar.height           = 28;
            bar.zOrder           = 18;
            bar.spriteName       = "SelectionToolBar";
            bar.Hide();

            fullscreenContainer = UIView.Find("FullScreenContainer");
        }
Exemplo n.º 8
0
 /**
  * Deauthenticates with Layer and clears cached AuthenticationProvider credentials.
  *
  * @param callback Callback to receive deauthentication success and failure.
  */
 public static void Deauthenticate(AtlasUtil.IDeauthenticationCallback callback)
 {
     AtlasUtil.Deauthenticate(GetLayerClient(), new DeauthenticationCallback(callback));
 }