public OnlineClient(Utilizator_Trip context, string[] Messages)
        {
            this.context = context;

            Nume         = Messages[2];
            Prenume      = Messages[3];
            TipCont      = Messages[4];
            NumarTelefon = Messages[5];
            Position     = Messages[7];

            TcpClient     Client = new TcpClient(_Details.ServerIP, _Details.LargeFilesPort);
            NetworkStream ns     = Client.GetStream();

            using (MemoryStream ms = new MemoryStream())
            {
                _TcpDataExchange.WriteStreamString(ns, CryptDecryptData.CryptData(new string[] { _Details.GetProfilePic, NumarTelefon }));

                int    ReadedBytes;
                byte[] Buffer = new byte[1000];

                while ((ReadedBytes = ns.Read(Buffer, 0, Buffer.Length)) > 0)
                {
                    ms.Write(Buffer, 0, ReadedBytes);
                }

                Client.Close();
                ns.Dispose();

                Drawable PhotoDrawable = DrawableConverter.ByteArrayToDrawable(ms.ToArray(), context);
                Bitmap   PhotoBitmap   = ((BitmapDrawable)PhotoDrawable).Bitmap;

                Photo = new BitmapDrawable(context.Resources, RoundedBitmap.MakeRound(PhotoBitmap, PhotoBitmap.Width));
            }
        }
Beispiel #2
0
        public TripClient(Client INPUT, Client OUTPUT, string NumarTelefon, Utilizator_Trip e)
        {
            this.INPUT        = INPUT;
            this.OUTPUT       = OUTPUT;
            this.NumarTelefon = NumarTelefon;
            this.e            = e;

            INPUT_GET();
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            RequestWindowFeature(WindowFeatures.NoTitle);
            Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);

            Bundle Extras = Intent.Extras;

            byte[] BackgroundByteArray = Extras.GetByteArray("BackgroundByteArray");
            TripInfo = Extras.GetStringArrayList("TripData").ToArray();
            Me       = new TripClient(Utilizator_Main.INPUT, Utilizator_Main.OUTPUT, new SaveUsingSharedPreferences(this).LoadString(SaveUsingSharedPreferences.Tags.Login.Username), this);
            TripId   = new SaveUsingSharedPreferences(this).LoadString(SaveUsingSharedPreferences.Tags.Trip.TipId);

            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.Utilizator_Trip);

            InitiateView();
            CheckIfNewInTrip();

            test = this;

            LocalActivityManager LAM = new LocalActivityManager(this, false);

            LAM.DispatchCreate(savedInstanceState);
            LAM.DispatchResume();
            LAM.DispatchPause(IsFinishing);
            tabHost.Setup(LAM);

            int[] Layouturi = new int[] {
                Resource.Layout.Utilizator_Trip_ChatView,
                Resource.Layout.Utilizator_Trip_MaskB,
                Resource.Layout.Utilizator_Trip_MaskC,
            };

            Background.Background = DrawableConverter.ByteArrayToDrawable(BackgroundByteArray, this);

            SetTypeface.Normal.SetTypeFace(this, UserNume);
            LeftDrawerListView.Adapter = new Utilizator_Trip_LeftDrawerAdapter(this, Background.Background, new string[] { "Galerie", "Modificare Cont", "As vrea sa cumpar", "Informatii excursie", "Setari", "Iesire Excursie", "Logut" });

            //	OrganizatorProfilePic.SetImageDrawable(RoundedUserProfile);
            //	OrganizatorNume.Text = "Nume Prenume";
            //	SetTypeface.Normal.SetTypeFace (this,OrganizatorNume);

            Pager.Adapter = new Utilizator_Trip_ViewPagerAdapter(SupportFragmentManager, this);

            for (int i = 0; i < 3; i++)
            {
                CreateTab(typeof(Utilizator_Trip_MaskA), Tags[i], string.Empty, TabsIcon[i], tabHost);
            }

            tabHost.TabChanged += TabHost_TabChanged;
            Pager.PageSelected += Pager_PageSelected;
            ClientGetMessage   += Utilizator_Trip_ClientGetMessage;
        }
        public override Android.Views.View OnCreateView(Android.Views.LayoutInflater inflater, Android.Views.ViewGroup container, Android.OS.Bundle savedInstanceState)
        {
            View v = inflater.Inflate(Layouturi[position], null, true);

            switch (position)
            {
            case 0:
            {
                Utilizator_Trip e = (Utilizator_Trip)context;

                ListView ChatView      = v.FindViewById <ListView> (Resource.Id.listView1);
                Button   Send          = v.FindViewById <Button> (Resource.Id.button1);
                EditText MessageToSend = v.FindViewById <EditText>(Resource.Id.editText1);

                Send.Click += (object sender, EventArgs ev) => {
                    if (MessageToSend.Text != string.Empty)
                    {
                        Utilizator_Trip.Me.OUTPUT_SEND(new String [] { "CHAT", Utilizator_Trip.Me.NumarTelefon, MessageToSend.Text.ToString() });
                        MessageToSend.Text = string.Empty;
                    }
                };

                e.ClientGetMessage += (object sender, ClientGetMessageEventArgs ev) => {
                    if (ev.Messages [0] == "CHAT")
                    {
                        List <Utilizator_Trip_Chat_Message> MesajeActuale = new List <Utilizator_Trip_Chat_Message> ();

                        if (ChatView.Adapter != null)
                        {
                            MesajeActuale.AddRange(((Utilizator_Trip_ChatViewAdapter)ChatView.Adapter).Mesaje);
                        }

                        if (ev.Messages[1].Equals(Utilizator_Trip.Me.NumarTelefon))
                        {
                            Drawable Photo = context.Resources.GetDrawable(Resource.Drawable.Icon);
                            if (e.RightDrawerListView.Adapter != null)
                            {
                                foreach (OnlineClient oc in ((Utilizator_Trip_RightDrawerAdapter)e.RightDrawerListView.Adapter).Clients)
                                {
                                    if (oc.NumarTelefon == ev.Messages[1])
                                    {
                                        Photo = oc.Photo;
                                        break;
                                    }
                                }
                            }

                            MesajeActuale.Add(new Utilizator_Trip_Chat_Message("Me", Photo, ev.Messages[2]));
                        }
                        else
                        {
                            Drawable Photo = context.Resources.GetDrawable(Resource.Drawable.Icon);
                            if (e.RightDrawerListView.Adapter != null)
                            {
                                foreach (OnlineClient oc in ((Utilizator_Trip_RightDrawerAdapter)e.RightDrawerListView.Adapter).Clients)
                                {
                                    if (oc.NumarTelefon == ev.Messages[1])
                                    {
                                        Photo = oc.Photo;
                                        break;
                                    }
                                }
                            }

                            MesajeActuale.Add(new Utilizator_Trip_Chat_Message("User", Photo, ev.Messages[2]));
                        }

                        context.RunOnUiThread(() => {
                                ChatView.Adapter = new Utilizator_Trip_ChatViewAdapter(context, MesajeActuale.ToArray());
                                ChatView.SetSelection(ChatView.Count - 1);
                            });
                    }
                };
            }
            break;

            case 1:
            {
            }
            break;
            }

            return(v);
        }