Exemplo n.º 1
0
		public static string GetDBImagePath(long id, long userid, SizeDB sizeDB)
		{		
			string path = ImageStore.FileDB;
			
			if (sizeDB == SizeDB.Size100)
			{
				path = ImageStore.FileDB100;
			}
			if (sizeDB == SizeDB.Size75)
			{
				path = ImageStore.FileDB75;
			}
			if (sizeDB == SizeDB.Size50)
			{
				path = ImageStore.FileDB50;
			}
			if (sizeDB == SizeDB.SizeFacebook)
			{
				return ImageStore.ProfilesFacebook + userid + ".png";
			}
			if (sizeDB == SizeDB.SizeProfil)
			{
				return ImageStore.Profiles + userid + ".png";
			}			
			if (sizeDB == SizeDB.SizeMiniMap)
			{
				return ImageStore.MapLocations + id + ".png";
			}
			
			path += userid + "/";
			return path + id + ".png";
		}				
Exemplo n.º 2
0
		public void UpdatedImage (long id, long userid, SizeDB sizeDB)
		{
			if (userid == user.Id)
			{
				UIImage profileImage = ImageStore.GetLocalFullPicture(id, userid, sizeDB);
				if (profileImage != null)
				{
					profileImage = UIImageUtils.resizeImage(profileImage, new SizeF (35, 35));			
					ImageView.Image = GraphicsII.RemoveSharpEdges(profileImage);
					SetNeedsDisplay();
				}
			}
		}		
Exemplo n.º 3
0
		public static UIImage SaveDBPic (string picfile, long id, long userid, SizeDB sizeDB)
		{
			LRUCache<long,UIImage> dbCache = ImageStore.GetCache(sizeDB);
			
			lock (dbCache.SyncValue){				
				using (var pic = UIImage.FromFileUncached (picfile)){
					if (pic == null)
						return null;
					
					SizeF size = pic.Size;
					string path = ImageStore.FileDB;
					
					if (sizeDB == SizeDB.Size100)
					{
						path = ImageStore.FileDB100;
						size = new SizeF(100, 100);
					}
					if (sizeDB == SizeDB.Size75)
					{
						path = ImageStore.FileDB75;
						size = new SizeF(75, 75);
					}
					if (sizeDB == SizeDB.Size50)
					{
						path = ImageStore.FileDB50;
						size = new SizeF(50, 50);
					}
					
					path = path + userid + "/";
					if (!Directory.Exists(path))
						Directory.CreateDirectory(path);
					
					UIImage cute = UIImageUtils.resizeImage(pic, size);

					var bytes = cute.AsPNG ();
					NSError err;
					bytes.Save (path + id + ".png", false, out err);
					
					// we might as well add it to the cache
					dbCache [id] = cute;
					
					return cute;
				}
			}
		}		
Exemplo n.º 4
0
		public static Uri GetPicUrlFromId (long id, long userid, SizeDB sizeDB)
		{			
			Uri res = null;
			try
			{
				if (sizeDB == SizeDB.Size100)
				{
					return (res = new Uri(string.Format("{0}/Zoom_100/{1}/{2}.jpg", streamingUrl, userid, id)));
				}
				if (sizeDB == SizeDB.Size75)
				{
					return (res = new Uri(string.Format("{0}/Zoom_75/{1}/{2}.jpg", streamingUrl, userid, id)));
				}
				if (sizeDB == SizeDB.Size50)
				{
					return (res = new Uri(string.Format("{0}/Zoom_50/{1}/{2}.jpg", streamingUrl, userid, id)));
				}
				if (sizeDB == SizeDB.SizeMiniMap)
				{
					return (res = new Uri(string.Format("{0}/MapLocations/{1}.jpg", streamingUrl, id)));
				}
				if (sizeDB == SizeDB.SizeProfil)
				{
					return (res = new Uri(string.Format("{0}/Profiles/{1}.jpg", streamingUrl, userid)));
				}
				if (sizeDB == SizeDB.SizeFacebook)
				{
					string accessToken = NSUserDefaults.StandardUserDefaults.StringForKey("FacebookAccessToken");
					return (res = new Uri(string.Format("https://graph.facebook.com/{0}/picture?access_token={1}", userid, accessToken)));
				}				
				return (res = new Uri(string.Format("{0}/Zoom_308_307/{1}/{2}.jpg", streamingUrl, userid, id)));
			}
			finally
			{
				//idToUrl[new Tuple<long, SizeDB>(id, sizeDB)] = res.OriginalString;
			}
		}
Exemplo n.º 5
0
		public static bool DeleteDBPic (long id, long userid, SizeDB sizeDB)
		{
			try
			{
				LRUCache<long,UIImage> dbCache = ImageStore.GetCache(sizeDB);
				string picfile = UrlStore.GetDBImagePath(id, userid, sizeDB);
				
				lock (dbCache.SyncValue)
				{
					dbCache.Remove(id);
					
					if (File.Exists (picfile))
					{	
						File.Delete(picfile);
					}
				}
				return true;
			}
			catch (Exception ex)
			{
				Util.LogException("DeleteDBPic", ex);
				return false;
			}			
		}
Exemplo n.º 6
0
		public static UIImage RequestFullPicture (long id, long userid, SizeDB sizeDB, ISizeImageUpdated notify)
		{
			var pic = GetLocalFullPicture (id, userid, sizeDB);
			if (pic == null){
				QueueRequestForPicture (id, userid, sizeDB, notify); 
				
				// return default picture or null while waiting for the high-res version to come				
				return null;
			}
			
			return pic;
		}
Exemplo n.º 7
0
		public static UIImage GetLocalFullPicture (long id, long userid, SizeDB sizeDB)
		{
			try
			{
				LRUCache<long,UIImage> dbCache = ImageStore.GetCache(sizeDB);
				
				lock (dbCache.SyncValue)
				{
					var ret = dbCache[id];
					if (ret == null)
					{
						var path = UrlStore.GetDBImagePath(new Tuple<long, long, SizeDB>(id, userid, sizeDB));
						if (File.Exists(path))
						{
							UIImage image = UIImage.FromFile(path);
							dbCache[id] = image;
							return image;
						}
						else
							return null;
					}
					else
						return ret;
				}
			}
			catch (Exception ex)
			{
				Util.LogException("GetLocalFullPicture", ex);
				return null;
			}		
		}
Exemplo n.º 8
0
		public static LRUCache<long,UIImage> GetCache(SizeDB sizeDB)
		{
			LRUCache<long,UIImage> dbCache = DBcachefull;
			if (sizeDB == SizeDB.Size100)
			{
				dbCache = DBcache100;
			}
			if (sizeDB == SizeDB.Size75)
			{
				dbCache = DBcache75;
			}
			if (sizeDB == SizeDB.Size50)
			{
				dbCache = DBcache50;
			}
			if (sizeDB == SizeDB.SizeMiniMap)
			{
				dbCache = DBcacheMiniMap;
			}
			if (sizeDB == SizeDB.SizeProfil)
			{
				dbCache = DBcacheProfiles;
			}			
			if (sizeDB == SizeDB.SizeFacebook)
			{
				dbCache = DBcacheFacebook;
			}
			
			return dbCache;
		}		
Exemplo n.º 9
0
			public void UpdatedImage (long id, long userid, SizeDB sizeDB)
			{				
				if (imagesCellInfo == null)
					return;
				
				if (sizeDB == SizeDB.Size50)
				{
					int i = 0;
					foreach (ImageInfo imgInfo in imagesCellInfo.Images)
					{
						if (imgInfo.Img != null && imgInfo.Img.Id == id)
						{
							images[i] = ImageStore.GetLocalFullPicture (id, userid, SizeDB.Size50);
							if (images[i] != null)
								buttons[i].SetBackgroundImage(images[i], UIControlState.Normal);
							
							break;
						}
						i++;
					}
				}
				
				SetNeedsDisplay ();				
			}
Exemplo n.º 10
0
		public void UpdatedImage (long id, long userid, SizeDB sizeDB)
		{
			var profileImage = ImageStore.GetLocalFullPicture (id, userid, SizeDB.SizeProfil);
			if (profileImage != null)
			{
				Graphics.ConfigLayerHighRes(imageLayer);
				imageLayer.Contents = UIImageUtils.resizeImage(profileImage, sizeProfile).CGImage;
				SetNeedsDisplay();
			}
		}
Exemplo n.º 11
0
		public void UpdatedImage (long id, long userid, SizeDB sizeDB)
		{
			if (_User != null)
			{
				if (_User.id == userid)
				{
					userImage = ImageStore.GetLocalFullPicture((long)_User.id, (long)_User.id, SizeDB.SizeFacebook);
					if (userImage != null)
					{
						userImage = UIImageUtils.resizeImage(userImage, new SizeF (35, 35));
						userImage = GraphicsII.RemoveSharpEdges(userImage);
					
						this.GetContainerTableView ().SetNeedsLayout();
					}
				}
			}
		}
Exemplo n.º 12
0
			public void UpdatedImage (long id, long userid, SizeDB sizeDB)
			{				
				if (activity == null)
					return;
				
				if (sizeDB == SizeDB.Size50)
				{
					if (activity.DbActivity.IdPhoto != id)
						return;
					
					tweetImage = ImageStore.GetLocalFullPicture (id, userid, SizeDB.Size50);
					if (tweetImage != null)
						imageBtn.SetBackgroundImage(tweetImage, UIControlState.Normal);				
				}
				
				if (sizeDB == SizeDB.SizeProfil)
				{
					if (activity.DbActivity.IdOwner != userid)
						return;
					
					userImage = ImageStore.GetLocalFullPicture (id, userid, SizeDB.SizeProfil);
					if (userImage != null)
						userBtn.SetBackgroundImage(userImage, UIControlState.Normal);					
				}
				SetNeedsDisplay ();				
			}
Exemplo n.º 13
0
		public void UpdatedImage (long id, long userid, SizeDB sizeDB)
		{
			if (_Image != null && _Image.Id != id)
				return;
			
			UIImage filePic = ImageStore.GetLocalFullPicture(id, userid, SizeDB.Size75);
			if (filePic != null)
			{			
				var resImg = UIImageUtils.resizeImage (filePic, photoSize);
				resImg = GraphicsII.RemoveSharpEdges(resImg, photoSize.Width, 4);
									
				BeginInvokeOnMainThread (() =>
				{
					_Photo = resImg;
					this.SetImage(_Photo, UIControlState.Normal);
					SetNeedsDisplay ();
				});
			}
			else
			{
				var resImg = GetTakePhotoImage();
				
				BeginInvokeOnMainThread (() =>
				{
					_Photo = resImg;
					this.SetImage (_Photo, UIControlState.Normal);						
					SetNeedsDisplay();
				});
			}				
		}
Exemplo n.º 14
0
			public void UpdatedImage (long id, long userid, SizeDB sizeDB)
			{
				if (currentUserId != userid)
					return;
				
				UIImage profileImage = ImageStore.GetLocalFullPicture(id, userid, sizeDB);
				if (profileImage != null)
				{
					profileImage = UIImageUtils.resizeImage(profileImage, new SizeF(PicSize, PicSize));
					var sharpImage = GraphicsII.RemoveSharpEdges(profileImage);
					
					activityBtn.SetBackgroundImage(sharpImage, UIControlState.Normal);
					SetNeedsDisplay ();						
				}
			}
Exemplo n.º 15
0
			public void UpdatedImage (long id, long userid, SizeDB sizeDB)
			{
				if (_Tweet == null)
					return;
				
				if (sizeDB == SizeDB.SizeMiniMap)
				{
					if (_Tweet.Image.Id != id)
						return;
					
					mapPlanImage = ImageStore.GetLocalFullPicture(id, userid, SizeDB.SizeMiniMap);
					
					if (mapPlanImage != null)
						SetMiniMap(mapPlanImage);
				}
				else
				{			
					if (_Tweet.Image.Id != id)
						return;
					
					if (_Tweet.User.Id != userid)
						return;					
					
					photoImage = ImageStore.GetLocalFullPicture(id, userid, SizeDB.SizeFull);
					if (photoImage != null)
					{
						photoBtn.SetBackgroundImage(photoImage, UIControlState.Normal);
						spinner.StopAnimating();						
					}
				}
				
				SetNeedsDisplay();
			}
Exemplo n.º 16
0
		//
		// Requests that the picture for "id" be downloaded, the optional url prevents
		// one lookup, it can be null if not known
		//
		public static void QueueRequestForPicture (long id, long userid, SizeDB sizeDB, ISizeImageUpdated notify)
		{									
			if (notify == null)
			{
				var argNullEx = new ArgumentNullException ("notify");
				Util.LogException("notifier is null!", argNullEx);				
				throw argNullEx;
			}
			
			Uri url;
			lock (requestQueue)
				url = UrlStore.GetPicUrlFromId (id, userid, sizeDB);
			
			if (url == null)
				return;		
			
			var pendReq = new Tuple<long, long, SizeDB>(id, userid, sizeDB);
			lock (requestQueue){
				if (pendingRequests.ContainsKey (pendReq)){
					Util.Log ("pendingRequest: added new listener for {0}", id);
					pendingRequests [pendReq].Add (notify);
					return;
				}
				var slot = new List<ISizeImageUpdated> ();
				slot.Add (notify);
				pendingRequests [pendReq] = slot;
#if DEBUGIMAGE
				pendingTimes [id] = DateTime.UtcNow.Ticks;
#endif	
				if (picDownloaders > MaxRequests){
					Util.Log ("Queuing Image request because {0} >= {1} {2}", requestQueue.Count, MaxRequests, picDownloaders);
					var imgRequest = new ImgRequest() { ID = id, UserId = userid, SizeDb = sizeDB };
					requestQueue.Push (imgRequest);
				} else {					
					ThreadPool.QueueUserWorkItem (delegate { 
						
							try {
								StartPicDownload (pendReq, url); 
							} catch (Exception e){
								Util.LogException("QueueRequestForPicture", e);
							}
						});
				}
			}
		}
Exemplo n.º 17
0
		public void UpdatedImage (long id, long userid, SizeDB sizeDB)
		{
			var profileImage = ImageStore.GetLocalFullPicture (id, userid, SizeDB.SizeProfil);
			if (profileImage != null)
			{
				profileImage = UIImageUtils.resizeImage(profileImage, new SizeF (26, 26));
				profilePic.Image = GraphicsII.RemoveSharpEdges(profileImage);
				SetNeedsDisplay();
			}
		}
Exemplo n.º 18
0
		public void UpdatedImage (long id, long userId, SizeDB sizeDB)
		{		
			if (_Image == null || _Image.Id != id)
				return;

			try 
			{
				UIImage resImg = ImageStore.GetLocalFullPicture(id, userId, SizeDB.Size100);
				
				if (resImg != null)
				{
					photoImage = resImg;
					RefreshImage(resImg);
				}
				
				SetNeedsDisplay ();
			}
			catch (Exception ex)
			{
				Util.LogException("UpdatedImage", ex);
			}
		}