Пример #1
0
		public UpdateChecker(Context ctx, DataBaseWrapper db, Setting setting) {
			if (string.IsNullOrEmpty (setting.NewestVersion)) {
				setting.NewestVersion = Setting.CurrentVersion;
			}
			var connectivityManager = (ConnectivityManager)ctx.GetSystemService(Context.ConnectivityService);
			if (setting.Synchronisation != Setting.Frequency.wlan || connectivityManager.GetNetworkInfo(ConnectivityType.Wifi).GetState() == NetworkInfo.State.Connected) {
				new Thread (async () => {
					string contentsTask;
					try {
						using(var httpClient = new HttpClient()) {
							contentsTask = await httpClient.GetStringAsync ("https://raw.githubusercontent.com/Bla-Chat/Android/master/version.txt");
						}
					} catch (Exception e) {
						Log.Error ("BlaChat", e.StackTrace);
						contentsTask = null;
					} finally {
						//semaphore.Release ();
					}
					if (contentsTask != null) {
						setting.NewestVersion = contentsTask;
						db.Update(setting);
					}
				}).Start ();
			}
		}
Пример #2
0
		protected override void OnCreate (Bundle bundle)
		{
			db = new DataBaseWrapper (this.Resources);
			if ((setting = db.Table<Setting> ().FirstOrDefault ()) == null) {
				db.Insert(setting = new Setting ());
			}
			StartupTheme = setting.Theme;
			SetTheme (setting.Theme);
			base.OnCreate (bundle);

			SetContentView (Resource.Layout.ChatActivity);

			conversation = Intent.GetStringExtra ("conversation");

			chat = db.Get<Chat> (conversation);
			visibleMessages = chat.VisibleMessages;
			if (visibleMessages <= 0) {
				visibleMessages = setting.VisibleMessages;
			}
			if (visibleMessages <= 0) {
				visibleMessages = 30;
			}
			Title = chat.name;
			ActionBar.SetDisplayHomeAsUpEnabled(true);
			ActionBar.SetIcon (Resource.Drawable.Icon);

			user = db.Table<User>().FirstOrDefault ();

			Button send = FindViewById<Button> (Resource.Id.send);
			send.Click += delegate {
				TextView message = FindViewById<TextView> (Resource.Id.message);
				var msg = message.Text;
				message.Text = "";

				if (msg.Equals("")) return;

				LinearLayout messageList = FindViewById<LinearLayout> (Resource.Id.messageLayout);
				AddMessage(messageList, new Message() {time = "sending", author = "Du", nick = user.user, text = msg, conversation = this.conversation});

				ScrollView scrollView = FindViewById<ScrollView> (Resource.Id.messageScrollView);
				scrollView.FullScroll (FocusSearchDirection.Down);
				scrollView.Post (() => scrollView.FullScroll (FocusSearchDirection.Down));

				OnBind();
				new Thread(async () => {
					while(!await network.SendMessage (db, user, chat, msg)) {
						await network.Authenticate(db, user);
					}
				}).Start();
			};
		}
Пример #3
0
		protected override void OnCreate (Bundle bundle)
		{
			db = new DataBaseWrapper (this.Resources);
			if ((setting = db.Table<Setting> ().FirstOrDefault ()) == null) {
				db.Insert(setting = new Setting ());
			}
			StartupTheme = setting.Theme;
			SetTheme (setting.Theme);
			base.OnCreate (bundle);

			new UpdateChecker (this, db, setting);

			// Check if the application knows a user.
			User user = db.Table<User>().FirstOrDefault ();
			if (user != null && user.user != null) {
				initializeAuthenticated (user);
			} else {
				initializeNotAuthenticated ();
			}
		}
Пример #4
0
		protected override void OnCreate (Bundle bundle)
		{
			db = new DataBaseWrapper (this.Resources);
			if ((setting = db.Table<Setting> ().FirstOrDefault ()) == null) {
				db.Insert(setting = new Setting ());
			}
			SetTheme (setting.Theme);
			base.OnCreate (bundle);

			network = new AsyncNetwork ();
			db = new DataBaseWrapper (this.Resources);
			user = db.Table<User>().FirstOrDefault ();

			if (setting.FontSize == Setting.Size.large) {
				SetContentView (Resource.Layout.SettingsLarge);
			} else {
				SetContentView (Resource.Layout.Settings);
			}

			InitializeView();
		}
Пример #5
0
		protected override void OnCreate (Bundle bundle)
		{
			db = new DataBaseWrapper (this.Resources);
			if ((setting = db.Table<Setting> ().FirstOrDefault ()) == null) {
				db.Insert(setting = new Setting ());
			}
			SetTheme (setting.Theme);
			base.OnCreate (bundle);

			if (Intent.ActionSend == Intent.Action)
			{
				if (Intent.GetStringExtra(Intent.ExtraText) != null) {
					textShare = Intent.GetStringExtra(Intent.ExtraText);
				} else {
					var uriString = Intent.GetParcelableExtra (Intent.ExtraStream).ToString();
					var uri = Android.Net.Uri.Parse(uriString);
					if (uri != null) {
						fileset.Add(uri);
					}
				}
			}
			else if (Intent.ActionSendMultiple == Intent.Action)
			{
				var uris= Intent.GetParcelableArrayListExtra(Intent.ExtraStream);
				if (uris != null) {
					foreach(var uri in uris)                         
					{
						fileset.Add(Android.Net.Uri.Parse(uri.ToString()));
					}
				}
			}

			// Check if the application knows a user.
			User user = db.Table<User>().FirstOrDefault ();
			if (user != null && user.user != null) {
				initializeAuthenticated (user);
			}
		}
Пример #6
0
        protected override void OnCreate(Bundle bundle)
        {
            db = new DataBaseWrapper(this.Resources);
            if ((setting = db.Table <Setting> ().FirstOrDefault()) == null)
            {
                db.Insert(setting = new Setting());
            }
            StartupTheme = setting.Theme;
            SetTheme(setting.Theme);
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.ChatActivity);

            conversation = Intent.GetStringExtra("conversation");

            chat            = db.Get <Chat> (conversation);
            visibleMessages = chat.VisibleMessages;
            if (visibleMessages <= 0)
            {
                visibleMessages = setting.VisibleMessages;
            }
            if (visibleMessages <= 0)
            {
                visibleMessages = 30;
            }
            Title = chat.name;
            ActionBar.SetDisplayHomeAsUpEnabled(true);
            ActionBar.SetIcon(Resource.Drawable.Icon);

            user = db.Table <User>().FirstOrDefault();

            Button send = FindViewById <Button> (Resource.Id.send);

            send.Click += delegate {
                TextView message = FindViewById <TextView> (Resource.Id.message);
                var      msg     = message.Text;
                message.Text = "";

                if (msg.Equals(""))
                {
                    return;
                }

                LinearLayout messageList = FindViewById <LinearLayout> (Resource.Id.messageLayout);
                AddMessage(messageList, new Message()
                {
                    time = "sending", author = "Du", nick = user.user, text = msg, conversation = this.conversation
                });

                ScrollView scrollView = FindViewById <ScrollView> (Resource.Id.messageScrollView);
                scrollView.FullScroll(FocusSearchDirection.Down);
                scrollView.Post(() => scrollView.FullScroll(FocusSearchDirection.Down));

                OnBind();
                new Thread(async() => {
                    while (!await network.SendMessage(db, user, chat, msg))
                    {
                        await network.Authenticate(db, user);
                    }
                }).Start();
            };
        }
        private async Task <int> Notify(AsyncNetwork network, string title, string message)
        {
            Setting setting = db.Table <Setting> ().FirstOrDefault();

            if (!setting.Notifications)
            {
                return(0);
            }

            // Set up an intent so that tapping the notifications returns to this app:
            Intent intent = new Intent(this, typeof(MainActivity));

            // Create a PendingIntent; we're only using one PendingIntent (ID = 0):
            const int     pendingIntentId = 0;
            PendingIntent pendingIntent   =
                PendingIntent.GetActivity(this, pendingIntentId, intent, PendingIntentFlags.OneShot);
            var msg = message;

            if (msg.StartsWith("#image"))
            {
                msg = "You received an image.";
            }
            NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                                                 .SetContentIntent(pendingIntent)
                                                 .SetContentTitle(title)
                                                 .SetContentText(msg)
                                                 .SetAutoCancel(true)
                                                 .SetSmallIcon(Resource.Drawable.Icon);

            if (setting.Sound)
            {
                builder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification));
            }


            if ((int)Android.OS.Build.VERSION.SdkInt >= 14)
            {
                if (setting.Led)
                {
                    builder.SetLights(Android.Graphics.Color.Magenta, 500, 500);
                }
                if (message.StartsWith("#image"))
                {
                    // Instantiate the Image (Big Picture) style:
                    NotificationCompat.BigPictureStyle picStyle = new NotificationCompat.BigPictureStyle();

                    // Convert the image to a bitmap before passing it into the style:
                    picStyle.BigPicture(await network.GetImageBitmapFromUrlNoCache(message.Substring("#image ".Length)));

                    // Set the summary text that will appear with the image:
                    picStyle.SetSummaryText(msg);

                    // Plug this style into the builder:
                    builder.SetStyle(picStyle);
                }
                else
                {
                    NotificationCompat.BigTextStyle textStyle = new NotificationCompat.BigTextStyle();

                    // Fill it with text:
                    textStyle.BigText(message);

                    // Set the summary text:
                    textStyle.SetSummaryText("New message");
                    builder.SetStyle(textStyle);
                }
            }

            // Build the notification:
            Notification notification = builder.Build();

            // Get the notification manager:
            NotificationManager notificationManager =
                GetSystemService(Context.NotificationService) as NotificationManager;

            // Publish the notification:
            const int notificationId = 0;

            notificationManager.Notify(notificationId, notification);

            if (setting.Vibrate)
            {
                Vibrator v = (Vibrator)GetSystemService(Context.VibratorService);                  // Make phone vibrate
                v.Vibrate(300);
            }

            return(notificationId);
        }