mirror of
				https://github.com/KokaKiwi/BarInsta
				synced 2025-10-31 03:25:34 +00:00 
			
		
		
		
	Extract method to get longest cookie
This reduces duplication and makes it easier to know what `getCookie` is doing, since all domains are now clustered together and it's easy to see the difference between them..
This commit is contained in:
		
							parent
							
								
									10f2e51a2e
								
							
						
					
					
						commit
						890c4d32d1
					
				| @ -10,6 +10,8 @@ import java.net.CookieStore; | ||||
| import java.net.HttpCookie; | ||||
| import java.net.URI; | ||||
| import java.net.URISyntaxException; | ||||
| import java.util.Arrays; | ||||
| import java.util.List; | ||||
| 
 | ||||
| import awais.instagrabber.BuildConfig; | ||||
| import awaisomereport.LogCollector; | ||||
| @ -74,79 +76,40 @@ public final class CookieUtils { | ||||
| 
 | ||||
|     @Nullable | ||||
|     public static String getCookie(@Nullable final String webViewUrl) { | ||||
|         int lastLongestCookieLength = 0; | ||||
|         String mainCookie = null; | ||||
|         final List<String> domains = Arrays.asList( | ||||
|                 "https://instagram.com", | ||||
|                 "https://instagram.com/", | ||||
|                 "http://instagram.com", | ||||
|                 "http://instagram.com", | ||||
|                 "https://www.instagram.com", | ||||
|                 "https://www.instagram.com/", | ||||
|                 "http://www.instagram.com", | ||||
|                 "http://www.instagram.com/" | ||||
|         ); | ||||
| 
 | ||||
|         String cookie; | ||||
|         if (!TextUtils.isEmpty(webViewUrl)) { | ||||
|             cookie = COOKIE_MANAGER.getCookie(webViewUrl); | ||||
|             if (cookie != null) { | ||||
|                 final int cookieLen = cookie.length(); | ||||
|                 if (cookieLen > lastLongestCookieLength) { | ||||
|                     mainCookie = cookie; | ||||
|                     lastLongestCookieLength = cookieLen; | ||||
|             domains.add(0, webViewUrl); | ||||
|         } | ||||
|             } | ||||
|         } | ||||
|         cookie = COOKIE_MANAGER.getCookie("https://instagram.com"); | ||||
|         if (cookie != null) { | ||||
|             final int cookieLen = cookie.length(); | ||||
|             if (cookieLen > lastLongestCookieLength) { | ||||
|                 mainCookie = cookie; | ||||
|                 lastLongestCookieLength = cookieLen; | ||||
|             } | ||||
|         } | ||||
|         cookie = COOKIE_MANAGER.getCookie("https://instagram.com/"); | ||||
|         if (cookie != null) { | ||||
|             final int cookieLen = cookie.length(); | ||||
|             if (cookieLen > lastLongestCookieLength) { | ||||
|                 mainCookie = cookie; | ||||
|                 lastLongestCookieLength = cookieLen; | ||||
|             } | ||||
|         } | ||||
|         cookie = COOKIE_MANAGER.getCookie("http://instagram.com"); | ||||
|         if (cookie != null) { | ||||
|             final int cookieLen = cookie.length(); | ||||
|             if (cookieLen > lastLongestCookieLength) { | ||||
|                 mainCookie = cookie; | ||||
|                 lastLongestCookieLength = cookieLen; | ||||
|             } | ||||
|         } | ||||
|         cookie = COOKIE_MANAGER.getCookie("http://instagram.com/"); | ||||
|         if (cookie != null) { | ||||
|             final int cookieLen = cookie.length(); | ||||
|             if (cookieLen > lastLongestCookieLength) { | ||||
|                 mainCookie = cookie; | ||||
|                 lastLongestCookieLength = cookieLen; | ||||
|             } | ||||
|         } | ||||
|         cookie = COOKIE_MANAGER.getCookie("https://www.instagram.com"); | ||||
|         if (cookie != null) { | ||||
|             final int cookieLen = cookie.length(); | ||||
|             if (cookieLen > lastLongestCookieLength) { | ||||
|                 mainCookie = cookie; | ||||
|                 lastLongestCookieLength = cookieLen; | ||||
|             } | ||||
|         } | ||||
|         cookie = COOKIE_MANAGER.getCookie("https://www.instagram.com/"); | ||||
|         if (cookie != null) { | ||||
|             final int cookieLen = cookie.length(); | ||||
|             if (cookieLen > lastLongestCookieLength) { | ||||
|                 mainCookie = cookie; | ||||
|                 lastLongestCookieLength = cookieLen; | ||||
|             } | ||||
|         } | ||||
|         cookie = COOKIE_MANAGER.getCookie("http://www.instagram.com"); | ||||
|         if (cookie != null) { | ||||
|             final int cookieLen = cookie.length(); | ||||
|             if (cookieLen > lastLongestCookieLength) { | ||||
|                 mainCookie = cookie; | ||||
|                 lastLongestCookieLength = cookieLen; | ||||
|             } | ||||
|         } | ||||
|         cookie = COOKIE_MANAGER.getCookie("http://www.instagram.com/"); | ||||
|         if (cookie != null && cookie.length() > lastLongestCookieLength) mainCookie = cookie; | ||||
| 
 | ||||
|         return mainCookie; | ||||
|         return getLongestCookie(domains); | ||||
|     } | ||||
| 
 | ||||
|     @Nullable | ||||
|     private static String getLongestCookie(final List<String> domains) { | ||||
|         int longestLength = 0; | ||||
|         String longestCookie = null; | ||||
| 
 | ||||
|         for (final String domain : domains) { | ||||
|             final String cookie = COOKIE_MANAGER.getCookie(domain); | ||||
|             if (cookie != null) { | ||||
|                 final int cookieLength = cookie.length(); | ||||
|                 if (cookieLength > longestLength) { | ||||
|                     longestCookie = cookie; | ||||
|                     longestLength = cookieLength; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         return longestCookie; | ||||
|     } | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user