private void CheckFirstTimeRun()
		{
			Profile existing = Database.Instance ().GetProfileById (1);
			#if DEBUG
			if (existing == null) {	

				DBTest.FillMyProfiles (this);

				//DBTest.FillDBProfiles (this);
				//DBTest.FillDBMessages (this);

				var i = new Intent (this, typeof(MainActivity));
				StartActivity (i);

			} else {
				var i = new Intent (this, typeof(MainActivity));
				StartActivity (i);
			}

			return;
			#endif
			if (existing == null) {			

				// create a profile for the user of this app
				existing= new Profile ();							
				existing.Version = 0;
				existing.PicVersion = 0;
				existing.Guid = System.Guid.NewGuid ().ToString ();
				existing.Gender = Profile.GENDER_FEMALE;
				existing.ToMeet = Profile.GENDER_MALE;
				existing.State = Profile.STATE_HIDE;
				Database.Instance ().SaveProfile (existing);
			}

			bool invalid = false;
			if (existing.Name == null || existing.Name.Length == 0) {
				invalid = true;
			} else if (existing.Status == null || existing.Status.Length == 0) {
				invalid = true;
			} else {
				ProfilePicture pic = Database.Instance ().GetPicture (existing.Guid);
				if (pic == null || pic.Big == null) {
					invalid = true;
				}
			}

			if (invalid) {			
				// start the intro
				var i = new Intent (this, typeof(IntroActivity));
				StartActivity (i);
			} else {
				var i = new Intent (this, typeof(MainActivity));
				StartActivity (i);
			}

		}
Beispiel #2
0
		static public void FillMyProfiles(Context context)
		{
			Profile p = new Profile ();
			p.Version = 1;
			p.Guid = System.Guid.NewGuid ().ToString ();
			p.Name = "TestPerson";
			p.Gender = Profile.GENDER_FEMALE;
			p.ToMeet = Profile.GENDER_BOTH;
			p.Status = "Status for test person";
			p.State = Profile.STATE_HIDE;
			p.LastSeen = 1;
			Database.Instance().SaveProfile (p);

			AddProfilePicture (context, p.Guid);
		}
		public void RefreshProfile(Profile profile)
		{
			// been block, stop broadcasting
			if (profile.Blocked >= NetworkManager2.BLOCK_COUNT_LIMIT) {
				Stop ();
			}

			Stop ();
			// make up the message that will be sent
			ProfileBroadcastMessage m = new ProfileBroadcastMessage();
			m.Guid = profile.Guid;
			m.Gender = profile.Gender;
			m.ToMeet = profile.ToMeet;
			m.Version = profile.Version;
			m.PicVersion = profile.PicVersion;
			ProtoBuf.Serializer.Serialize(broadcastMessage,m);
			broadcastMessage.Position = 0;
			Start ();
		}
		public override void OnViewCreated (View view, Bundle savedInstanceState)
		{
			this.profile = Database.Instance ().GetProfileById (1);
			this.picture = Database.Instance ().GetPicture (profile.Guid);

			if (this.picture == null) {
				this.picture = new ProfilePicture ();
			}

			ImageView iv = view.FindViewById<ImageView> (Resource.Id.picture);

			if (this.picture.Big != null) {			
				iv.SetImageBitmap (Utils.BytesToBitmap (this.picture.Big));
			}
							
			iv.Click += delegate {                
				Intent intent = new Intent(MediaStore.ActionImageCapture);
				mImageCaptureUri = global::Android.Net.Uri.FromFile(new Java.IO.File(CreateDirectoryForPictures(), string.Format("myPhoto_{0}.jpg", System.Guid.NewGuid())));
				intent.PutExtra(MediaStore.ExtraOutput, mImageCaptureUri);
				intent.PutExtra("return-data", false);
				StartActivityForResult(intent, PICK_FROM_CAMERA);
			} ;

			EditText name = (view.FindViewById<EditText> (Resource.Id.name));
			name.Text = profile.Name == null ? "" : profile.Name;
			name.TextChanged += (object sender, global::Android.Text.TextChangedEventArgs e) => {
				profile.Name = e.Text.ToString();
				profile_dirty = true;
			};

			RadioGroup gender = (view.FindViewById<RadioGroup> (Resource.Id.radioGender));
			gender.Check (profile.Gender == Profile.GENDER_MALE ? Resource.Id.genderMale : Resource.Id.genderFemale);
			gender.CheckedChange += (object sender, RadioGroup.CheckedChangeEventArgs e) => {
				profile.Gender = e.CheckedId == Resource.Id.genderMale ? Profile.GENDER_MALE : Profile.GENDER_FEMALE;
				profile_dirty = true;
			};

			CheckBox meetMen = (view.FindViewById<CheckBox> (Resource.Id.meet_men));
			meetMen.Checked = (profile.ToMeet & Profile.GENDER_MALE)==Profile.GENDER_MALE;
			meetMen.CheckedChange += (object sender, CompoundButton.CheckedChangeEventArgs e) => {
				if (e.IsChecked) {
					profile.ToMeet |= Profile.GENDER_MALE;
				}
				else {
					profile.ToMeet &= ~Profile.GENDER_MALE;
				}
				profile_dirty = true;
			};

			CheckBox meetWomen = (view.FindViewById<CheckBox> (Resource.Id.meet_women));
			meetWomen.Checked = (profile.ToMeet & Profile.GENDER_FEMALE)==Profile.GENDER_FEMALE;
			meetWomen.CheckedChange += (object sender, CompoundButton.CheckedChangeEventArgs e) => {
				if (e.IsChecked) {
					profile.ToMeet |= Profile.GENDER_FEMALE;
				}
				else {
					profile.ToMeet &= ~Profile.GENDER_FEMALE;
				}
				profile_dirty = true;
			};
				
			EditText status = (view.FindViewById<EditText> (Resource.Id.status));
			status.Text = profile.Status == null ? "" : profile.Status;
			status.TextChanged += (object sender, global::Android.Text.TextChangedEventArgs e) => {
				profile.Status = e.Text.ToString();
				profile_dirty = true;
			};				

		}
		public void RefreshProfile(Profile profile)
		{
			if (profile == null)
				return;

			if (null != this.ProfileBroadcast) {
				this.ProfileBroadcast.RefreshProfile (profile);
			}
			if (null != this.UPDBroadcastListener) {
				this.UPDBroadcastListener.RefreshProfile (profile);
			}
			lock (this.MyPicture) {
				this.MyPicture = Database.Instance ().GetPicture (profile.Guid);
			}
			lock (this.MyProfile) {
				this.MyProfile = profile;
			}
		}	
		// request handler sends out a picture, this handles accepting the pciture
		private void HandleProfileMessage(MemoryStream data, string fromIp, TcpClient tcpClient)
		{
			if (Logging) {
				Database.Instance ().SaveLog ("Profile - HandleProfileMessage() " + fromIp);
			}

			MessageProfile m = ProtoBuf.Serializer.Deserialize<MessageProfile> (data);

			// look up the profile
			Profile profile = Database.Instance().GetProfileByGuid(m.Guid);
			if (profile == null) {
				profile = new Profile();
			}
			// and picture
			ProfilePicture pic = Database.Instance().GetPicture(m.Guid);
			if (pic == null) {
				pic = new ProfilePicture();
			}								

			profile.Guid = m.Guid;
			profile.Version = m.Version;
			profile.PicVersion = m.PicVersion;
			profile.Name = m.Name;
			profile.Gender = m.Gender;
			profile.ToMeet = m.ToMeet;
			profile.Status = m.Status;
			if (profile.Blocked < BLOCK_COUNT_LIMIT) {
				// change to show
				if (profile.State == Profile.STATE_PENDING || profile.State == Profile.STATE_HIDE) {
					profile.State = Profile.STATE_SHOW;
				}
				// if picture included
				if (null != m.Small) {
					pic.Guid = m.Guid;
					pic.Small = m.Small;
					pic.Big = m.Big;
					Database.Instance().SaveProfilePicture(pic);
				}
			}
			Database.Instance().SaveProfile(profile);

			// check for and clear out any old entry
			// this happens when some unistalls and reinstalls creating a new profile but on the same device					
			Profile old = Database.Instance().GetProfileByIpNotGuid(fromIp, m.Guid);
			if (null != old) {
				Database.Instance().DeleteProfile(old.Guid);
			}				

		}	
Beispiel #7
0
		static public void FillDBProfiles(Context context)
		{
			Profile p = new Profile ();
			p.Version = 1;
			p.Guid = System.Guid.NewGuid ().ToString ();
			p.Name = "Patrica";
			p.Gender = Profile.GENDER_FEMALE;
			p.ToMeet = Profile.GENDER_MALE;
			p.Status = "Im just the most amazing person, what more do you need to know?";
			p.State = Profile.STATE_SHOW;
			p.LastSeen = 1;
			Database.Instance().SaveProfile (p);

			AddProfilePicture (context, p.Guid);

			//////////////////////////////////////////////////////////////////////////

			p = new Profile ();							
			p.Version = 1;
			p.Guid = System.Guid.NewGuid ().ToString ();
			p.Name = "Wendy";
			p.Gender = Profile.GENDER_FEMALE;
			p.ToMeet = Profile.GENDER_MALE;
			p.Status = "I like party all night long.";
			p.LastSeen = 1;
			p.State = Profile.STATE_SHOW;
			Database.Instance().SaveProfile (p);

			AddProfilePicture (context, p.Guid);

			////////////////////////////////////////////////////////////////////////

			p = new Profile ();

			p.Version = 1;
			p.Guid = System.Guid.NewGuid ().ToString ();
			p.Name = "Suzan";
			p.Gender = Profile.GENDER_FEMALE;
			p.ToMeet = Profile.GENDER_MALE;
			p.Status = "This app is fun isn't it!";
			p.LastSeen = 1;
			p.State = Profile.STATE_SHOW;

			Database.Instance().SaveProfile (p);

			AddProfilePicture (context, p.Guid);

		}
		public void RefreshProfile(Profile profile)
		{
			this.MyToMeet = profile.ToMeet;		
			this.MyGender = profile.Gender;
		}
		void HandleProfileBroadcast(MemoryStream message, string fromIp)
		{		
			ProfileBroadcastMessage recieved_profile = ProtoBuf.Serializer.Deserialize<ProfileBroadcastMessage> (message);
					
			// is there a possibility of a match
			if ((recieved_profile.Gender == (MyToMeet & recieved_profile.Gender)) &&
			    (MyGender == (recieved_profile.ToMeet & MyGender))) {

				Profile profile = Database.Instance ().GetProfileByGuid (recieved_profile.Guid);

				bool fetch_profile = false;
				bool include_pic = false;
				bool notify = false;

				// we have it already,
				if (profile != null) {
					// if profile pic changed, ask for the profile including the picture
					if (profile.PicVersion != recieved_profile.PicVersion) {
						fetch_profile = true;
						include_pic = true;
					}
					// if only the profile changed get just that
					else if (profile.Version != recieved_profile.Version) {
						fetch_profile = true;
					}					
					profile.LastSeen = DateTime.Now.Ticks;
					profile.IPAddress = fromIp;
					notify = true;
				} 
				// its a new profile
				else {			
					// create a pending entry for in the DB
					profile = new Profile ();
					profile.Guid = recieved_profile.Guid;
					profile.Gender = recieved_profile.Gender;
					profile.ToMeet = recieved_profile.ToMeet;
					profile.Version = recieved_profile.Version;
					profile.PicVersion = recieved_profile.PicVersion;
					profile.LastSeen = DateTime.Now.Ticks;
					profile.IPAddress = fromIp;
					profile.State = Profile.STATE_PENDING; 
					fetch_profile = true;
					include_pic = true;
					notify = true;		
				}

				// fetch the profile
				bool save = true;
				if (fetch_profile && profile.CanRequest ()) {
					profile.LastRequest = DateTime.Now.Ticks;
					NetworkManager2.Instance ().RequestHandler.RequestSendUseProfile (fromIp, include_pic);
				}

				// save the profile
				if (save) {
					Database.Instance ().SaveProfile (profile, notify);
				}

			}
		}