Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

A lot of changes

  • Loading branch information...
commit 40997e1796848d03f732c64b57463319f00d1764 1 parent 14141e7
Viacheslav Okolitiy authored November 20, 2012
306  AndroidVkSdk/src/com/perm/kate/api/Api.java
@@ -25,15 +25,19 @@
25 25
 import com.perm.kate.api.models.social.CommentList;
26 26
 import com.perm.kate.api.models.social.Counters;
27 27
 import com.perm.kate.api.models.social.LastUserActivity;
  28
+import com.perm.kate.api.models.social.Message;
28 29
 import com.perm.kate.api.models.social.NewsFeed;
29 30
 import com.perm.kate.api.models.social.Notification;
  31
+import com.perm.kate.api.models.social.Notifications;
30 32
 import com.perm.kate.api.models.social.Poll;
  33
+import com.perm.kate.api.models.social.SearchDialogItem;
31 34
 import com.perm.kate.api.models.social.User;
32 35
 import com.perm.kate.api.models.social.UserStatus;
33 36
 import com.perm.kate.api.models.social.friends.FriendsList;
34 37
 import com.perm.kate.api.models.social.group.Group;
35 38
 import com.perm.kate.api.models.social.wall.WallMessage;
36 39
 import com.perm.kate.api.request.RequestHelper;
  40
+import com.perm.kate.api.response.NotificationsResponseHandler;
37 41
 import com.perm.kate.api.response.geo.CityResponseHandler;
38 42
 import com.perm.kate.api.response.geo.CountryResponseHandler;
39 43
 import com.perm.kate.api.response.media.AlbumResponseHandler;
@@ -45,7 +49,10 @@
45 49
 import com.perm.kate.api.response.social.CommentResponseHandler;
46 50
 import com.perm.kate.api.response.social.CountersResponseHandler;
47 51
 import com.perm.kate.api.response.social.FriendsResponseHandler;
  52
+import com.perm.kate.api.response.social.GroupResponseHandler;
48 53
 import com.perm.kate.api.response.social.LastActivityResponseHandler;
  54
+import com.perm.kate.api.response.social.MessageResponseHandler;
  55
+import com.perm.kate.api.response.social.NewsFeedResponseHandler;
49 56
 import com.perm.kate.api.response.social.PollResponseHandler;
50 57
 import com.perm.kate.api.response.social.UserResponseHandler;
51 58
 import com.perm.kate.api.response.social.WallMessageResponseHandler;
@@ -1727,5 +1734,304 @@ public String editAlbum(long albumId, String title, String privacy, String comme
1727 1734
         }
1728 1735
 		return comments;
1729 1736
 	}
  1737
+	
  1738
+	public Collection<Message> getMessagesById(ArrayList<Long> messageIds) throws JSONException{
  1739
+		Params params = new Params("messages.getById");
  1740
+        params.put("mids", arrayToString(messageIds));
  1741
+        JSONObject root = RequestHelper.sendRequest(params);
  1742
+        JSONArray array = root.optJSONArray("response");
  1743
+        ArrayList<Message> messages = new ArrayList<Message>();
  1744
+        messages.addAll(parseMessages(array, false, 0, false, 0));
  1745
+		return messages;
  1746
+	}
  1747
+	
  1748
+	public Collection<Message> getMessagesDialogs(long offset, int count) throws JSONException{
  1749
+		Params params = new Params("messages.getDialogs");
  1750
+		if (offset != 0){
  1751
+            params.put("offset", offset);
  1752
+		}
  1753
+        if (count != 0){
  1754
+            params.put("count", count);
  1755
+        }
  1756
+        params.put("preview_length","0");
  1757
+        JSONObject root = RequestHelper.sendRequest(params);
  1758
+        JSONArray array = root.optJSONArray("response");
  1759
+        ArrayList<Message> messages = new ArrayList<Message>();
  1760
+        messages.addAll(parseMessages(array, false, 0, false ,0));
  1761
+        
  1762
+		return messages;
  1763
+	}
  1764
+	
  1765
+	public Collection<Message> getMessagesHistory(long userId, long chatId, long me, 
  1766
+			Long offset, int count) throws JSONException{
  1767
+		Params params = new Params("messages.getHistory");
  1768
+		if(chatId <= 0){
  1769
+			params.put("uid", userId);
  1770
+		} else {
  1771
+			params.put("chat_id", chatId);
  1772
+		}
  1773
+		params.put("offset", offset);
  1774
+		if (count != 0){
  1775
+			params.put("count", count);
  1776
+		}
  1777
+		JSONObject root = RequestHelper.sendRequest(params);
  1778
+		JSONArray array = root.optJSONArray("response");
  1779
+		ArrayList<Message> messages = new ArrayList<Message>();
  1780
+		messages.addAll(parseMessages(array, chatId <= 0, userId, chatId > 0, me));
  1781
+		
  1782
+		return messages;
  1783
+	}
  1784
+	
  1785
+	public Collection<SearchDialogItem> searchDialogs(String q, String fields) throws JSONException{
  1786
+		Params params = new Params("messages.searchDialogs");
  1787
+        params.put("q", q);
  1788
+        params.put("fields", fields);
  1789
+        JSONObject root = RequestHelper.sendRequest(params);
  1790
+        JSONArray array = root.optJSONArray("response");
  1791
+        MessageResponseHandler handler = new MessageResponseHandler();
  1792
+        
  1793
+        return handler.parseDialogItems(array);
  1794
+	}
  1795
+	
  1796
+	public Collection<Message> searchMessages(String q, int offset, int count) throws JSONException{
  1797
+		Params params = new Params("messages.search");
  1798
+        params.put("q", q);
  1799
+        params.put("count", count);
  1800
+        params.put("offset", offset);
  1801
+        JSONObject root = RequestHelper.sendRequest(params);
  1802
+        JSONArray array = root.optJSONArray("response");
  1803
+        ArrayList<Message> messages = new ArrayList<Message>();
  1804
+        messages.addAll(parseMessages(array, false, 0, false, 0));
  1805
+        
  1806
+		return messages;
  1807
+	}
  1808
+	
  1809
+	public Collection<WallMessage> getFavePosts(Integer count, Integer offset) throws JSONException{
  1810
+		 Params params = new Params("fave.getPosts");
  1811
+		 //params.put("extended", extended);
  1812
+	     params.put("count", count);
  1813
+	     params.put("offset", offset);
  1814
+	     JSONObject root = RequestHelper.sendRequest(params);
  1815
+	     JSONArray array = root.optJSONArray("response");
  1816
+	     //JSONArray array = response.optJSONArray("wall");
  1817
+	     //JSONArray profiles_array = response.optJSONArray("profiles");
  1818
+	     //JSONArray groups_array = response.optJSONArray("groups");
  1819
+	     ArrayList<WallMessage> messages = new ArrayList<WallMessage>();
  1820
+	     if (array == null){
  1821
+	    	 return null;
  1822
+	     }
  1823
+	     int counts = array.length();
  1824
+	     for(int i = 0; i < counts; ++i) {
  1825
+	    	 JSONObject o = (JSONObject)array.get(i);
  1826
+	    	 WallMessageResponseHandler handler = new WallMessageResponseHandler();
  1827
+	    	 messages.add(handler.parse(o));
  1828
+	     }
  1829
+		return messages;
  1830
+	}
  1831
+	
  1832
+	public Collection<Message> getMessages(long timeOffset, boolean isOut, int count) throws JSONException{
  1833
+		Params params = new Params("messages.get");
  1834
+		if(isOut){
  1835
+			params.put("out","1");
  1836
+		}
  1837
+		if(timeOffset != 0){
  1838
+			params.put("time_offset", timeOffset);
  1839
+		}
  1840
+		if(count != 0){
  1841
+			params.put("count", count);
  1842
+		}
  1843
+		params.put("preview_length","0");
  1844
+        JSONObject root = RequestHelper.sendRequest(params);
  1845
+        JSONArray array = root.optJSONArray("response");
  1846
+        ArrayList<Message> messages = new ArrayList<Message>();
  1847
+        messages.addAll(parseMessages(array, false, 0, false, 0));
  1848
+        
  1849
+		return messages;
  1850
+	}
  1851
+	
  1852
+	public Collection<Video> searchVideo(String q, String sort, String hd, Long count, Long offset) 
  1853
+			throws JSONException{
  1854
+		Params params = new Params("video.search");
  1855
+        params.put("q", q);
  1856
+        params.put("sort", sort);
  1857
+        params.put("hd", hd);
  1858
+        params.put("count", count);
  1859
+        params.put("offset", offset);
  1860
+        JSONObject root = RequestHelper.sendRequest(params);
  1861
+        JSONArray array = root.optJSONArray("response");
  1862
+        ArrayList<Video> videos = new ArrayList<Video>();
  1863
+        if(array != null){
  1864
+        	for(int i = 0; i < array.length(); ++i){
  1865
+        		JSONObject o = (JSONObject)array.get(i);
  1866
+        		VideoResponseHandler handler = new VideoResponseHandler();
  1867
+        		videos.add(handler.parse(o));
  1868
+        	}
  1869
+        }
  1870
+        //String video_ids = "";
  1871
+//        for (Video v:videoss) {
  1872
+//            video_ids = video_ids + String.valueOf(v.owner_id) + "_" + String.valueOf(v.vid) + ","; 
  1873
+//        }
  1874
+//        return getVideo(video_ids, null, null, null, null, null);
  1875
+		return videos;
  1876
+	}
  1877
+	
  1878
+	public Collection<Group> getUserGroups(Long userId) throws JSONException{
  1879
+		Params params = new Params("groups.get");
  1880
+        params.put("extended","1");
  1881
+        params.put("uid",userId);
  1882
+        JSONObject root = RequestHelper.sendRequest(params);
  1883
+        ArrayList<Group> groups = new ArrayList<Group>();
  1884
+        JSONArray array = root.optJSONArray("response");
  1885
+        if(array == null){
  1886
+        	return null;
  1887
+        }
  1888
+        GroupResponseHandler handler = new GroupResponseHandler();
  1889
+        groups.addAll(handler.parse(array));
  1890
+        
  1891
+		return groups;
  1892
+	}
  1893
+	
  1894
+	public Notifications getNotifications(String filters, Long startTime, Long endTime, 
  1895
+			Integer offset, Integer count) throws JSONException{
  1896
+		Params params = new Params("notifications.get");
  1897
+        params.put("filters", filters);
  1898
+        params.put("start_time", startTime);
  1899
+        params.put("end_time", endTime);
  1900
+        params.put("offset", offset);
  1901
+        params.put("count", count);
  1902
+        JSONObject root = RequestHelper.sendRequest(params);
  1903
+        JSONObject response = root.optJSONObject("response");
  1904
+        NotificationsResponseHandler handler = new NotificationsResponseHandler();
  1905
+        
  1906
+        return handler.parse(response);
  1907
+	}
  1908
+	
  1909
+	public Collection<Group> searchGroup(String q, Long count, Long offset) throws JSONException{
  1910
+		Params params = new Params("groups.search");
  1911
+        params.put("q", q);
  1912
+        params.put("count", count);
  1913
+        params.put("offset", offset);
  1914
+        JSONObject root = RequestHelper.sendRequest(params);
  1915
+        JSONArray array = root.optJSONArray("response");
  1916
+        ArrayList<Group> groups = new ArrayList<Group>();  
  1917
+        if(array == null){
  1918
+        	return null;
  1919
+        }
  1920
+        GroupResponseHandler groupResponseHandler = new GroupResponseHandler();
  1921
+        groups.addAll(groupResponseHandler.parse(array));
  1922
+        
  1923
+		return groups;
  1924
+	}
  1925
+	
  1926
+	public Collection<Group> getGroups(Collection<Long> uids, String domain, String fields) throws JSONException{
  1927
+		if (uids == null && domain == null){
  1928
+            return null;
  1929
+		}
  1930
+        if (uids.size() == 0 && domain == null){
  1931
+            return null;
  1932
+        }
  1933
+        Params params = new Params("groups.getById");
  1934
+        String str_uids;
  1935
+        if (uids != null && uids.size() > 0) {
  1936
+            str_uids=arrayToString(uids);
  1937
+        }
  1938
+        else {
  1939
+            str_uids = domain;
  1940
+        }
  1941
+        params.put("gids", str_uids);
  1942
+        params.put("fields", fields); //Possible values: place,wiki_page,city,country,description,start_date,finish_date,site
  1943
+        JSONObject root = RequestHelper.sendRequest(params);
  1944
+        JSONArray array=root.optJSONArray("response");
  1945
+        GroupResponseHandler handler = new GroupResponseHandler();
  1946
+        
  1947
+        return handler.parse(array);
  1948
+	}
  1949
+	
  1950
+	public NewsFeed getNews(long startTime, long count, long end_time){
  1951
+		Params params = new Params("newsfeed.get");
  1952
+        params.put("filters","post,photo,photo_tag,friend,note");
  1953
+        params.put("start_time",(startTime==-1)?getDefaultStartTime():startTime);
  1954
+        if(end_time != -1){
  1955
+            params.put("end_time",end_time);
  1956
+        }
  1957
+        if(count != 0){
  1958
+            params.put("count",count);
  1959
+        }
  1960
+        JSONObject root = RequestHelper.sendRequest(params);
  1961
+        NewsFeedResponseHandler handler = new NewsFeedResponseHandler();
  1962
+        //TODO
  1963
+        //return handler.parse(root,true);
  1964
+		return null;
  1965
+	}
  1966
+	
  1967
+	public NewsFeed getNewsComments(){
  1968
+		Params params = new Params("newsfeed.getComments");
  1969
+        params.put("last_comments","1");
  1970
+        params.put("count","50");
  1971
+        JSONObject root = RequestHelper.sendRequest(params);
  1972
+        NewsFeedResponseHandler handler = new NewsFeedResponseHandler();
  1973
+        //TODO
  1974
+        //return handler.parse(root, true);
  1975
+		return null;
  1976
+	}
  1977
+	
  1978
+	public CommentList getWallComments(Long owner_id, Long post_id, int offset, int count) throws JSONException{
  1979
+		Params params = new Params("wall.getComments");
  1980
+        params.put("post_id", post_id);
  1981
+        params.put("owner_id", owner_id);
  1982
+        /*
  1983
+        if (sort != null)
  1984
+            params.put("sort", sort);
  1985
+            //asc - хронологический
  1986
+            //desc - антихронологический
  1987
+        */
  1988
+        if (offset > 0) {
  1989
+            params.put("offset", offset);
  1990
+        }
  1991
+        if (count > 0) {
  1992
+            params.put("count", count);
  1993
+        }
  1994
+        params.put("preview_length", "0");
  1995
+        params.put("need_likes", "1");
  1996
+        JSONObject root = RequestHelper.sendRequest(params);
  1997
+        JSONArray array = root.getJSONArray("response");
  1998
+        CommentList comments = new CommentList();
  1999
+        comments.setCount(array.getInt(0));
  2000
+        int category_count = array.length();
  2001
+        for(int i = 1; i<category_count; ++i){
  2002
+        	CommentResponseHandler handler = new CommentResponseHandler();
  2003
+        	comments.getArrayList().add(handler.parse((JSONObject)array.get(i)));
  2004
+        }
  2005
+		return comments;
  2006
+	}
  2007
+	
  2008
+	public CommentList getGroupTopicComments(long gid, long tid, int photo_sizes, int extended, 
  2009
+			int count, int offset) throws JSONException{
  2010
+		Params params = new Params("board.getComments");
  2011
+        params.put("gid", gid);
  2012
+        params.put("tid", tid);
  2013
+        if (photo_sizes == 1)
  2014
+            params.put("photo_sizes", "1");
  2015
+        if (extended == 1)
  2016
+            params.put("extended", "1");
  2017
+        if (count > 0)
  2018
+            params.put("count", count);
  2019
+        if (offset > 0)
  2020
+            params.put("offset", offset);
  2021
+        JSONObject root = RequestHelper.sendRequest(params);
  2022
+        JSONObject response = root.optJSONObject("response");
  2023
+        CommentList result = new CommentList();
  2024
+        if (response != null) {
  2025
+            JSONArray comments = response.optJSONArray("comments");
  2026
+            int category_count = comments.length();
  2027
+            result.setCount(comments.getInt(0));
  2028
+            for (int i=1; i<category_count; ++i) { //get(0) is integer, it is comments count
  2029
+                JSONObject o = comments.getJSONObject(i);
  2030
+                CommentResponseHandler commentResponseHandler = new CommentResponseHandler();
  2031
+                result.getArrayList().add(commentResponseHandler.parse(o));
  2032
+            }
  2033
+        }
  2034
+		return result;
  2035
+	}
1730 2036
 }
1731 2037
 
16  AndroidVkSdk/src/com/perm/kate/api/BaseApiHelper.java
@@ -15,11 +15,13 @@
15 15
 import com.perm.kate.api.models.media.Link;
16 16
 import com.perm.kate.api.models.media.Photo;
17 17
 import com.perm.kate.api.models.media.PhotoTag;
  18
+import com.perm.kate.api.models.social.Message;
18 19
 import com.perm.kate.api.request.RequestHelper;
19 20
 import com.perm.kate.api.response.media.AudioResponseHandler;
20 21
 import com.perm.kate.api.response.media.PhotoResponseHandler;
21 22
 import com.perm.kate.api.response.media.PhotoTagResponseHandler;
22 23
 import com.perm.kate.api.response.social.LinkResponseHandler;
  24
+import com.perm.kate.api.response.social.MessageResponseHandler;
23 25
 
24 26
 public abstract class BaseApiHelper {
25 27
 
@@ -192,4 +194,18 @@ public int setMessageActivity(long userId, long chatId, boolean isTyping) {
192 194
         }
193 195
         return photos;
194 196
     }
  197
+	
  198
+	protected Collection<Message> parseMessages(JSONArray array, boolean fromHistory, long historyUserId, 
  199
+			boolean fromChat, long me) throws JSONException{
  200
+		ArrayList<Message> messages = new ArrayList<Message>();
  201
+		if (array != null) {
  202
+			int count = array.length();
  203
+			for(int i = 0; i < count; i++){
  204
+				JSONObject o = (JSONObject)array.get(i);
  205
+				MessageResponseHandler handler = new MessageResponseHandler();
  206
+				messages.add(handler.parse(o, fromHistory, historyUserId, fromChat, me));
  207
+			}
  208
+		}
  209
+		return messages;
  210
+	}
195 211
 }
310  AndroidVkSdk/src/com/perm/kate/api/deprecated/Api.java
@@ -18,169 +18,6 @@
18 18
 
19 19
 public class Api {
20 20
 	
21  
-    /*** methods for messages 
22  
-     * @throws KException ***/
23  
-    //http://vkontakte.ru/developers.php?o=-1&p=messages.get
24  
-    public ArrayList<Message> getMessages(long time_offset, boolean is_out, int count) throws MalformedURLException, IOException, JSONException, KException{
25  
-        Params params = new Params("messages.get");
26  
-        if (is_out)
27  
-            params.put("out","1");
28  
-        if (time_offset!=0)
29  
-            params.put("time_offset", time_offset);
30  
-        if (count != 0)
31  
-            params.put("count", count);
32  
-        params.put("preview_length","0");
33  
-        JSONObject root = sendRequest(params);
34  
-        JSONArray array = root.optJSONArray("response");
35  
-        ArrayList<Message> messages = parseMessages(array, false, 0, false, 0);
36  
-        return messages;
37  
-    }
38  
-    
39  
-    //http://vkontakte.ru/developers.php?o=-1&p=messages.getHistory
40  
-    public ArrayList<Message> getMessagesHistory(long uid, long chat_id, long me, Long offset, int count) throws MalformedURLException, IOException, JSONException, KException{
41  
-        Params params = new Params("messages.getHistory");
42  
-        if(chat_id<=0)
43  
-            params.put("uid",uid);
44  
-        else
45  
-            params.put("chat_id",chat_id);
46  
-        params.put("offset", offset);
47  
-        if (count != 0)
48  
-            params.put("count", count);
49  
-        JSONObject root = sendRequest(params);
50  
-        JSONArray array = root.optJSONArray("response");
51  
-        ArrayList<Message> messages = parseMessages(array, chat_id<=0, uid, chat_id>0, me);
52  
-        return messages;
53  
-    }
54  
-    
55  
-    //http://vkontakte.ru/developers.php?o=-1&p=messages.getDialogs
56  
-    public ArrayList<Message> getMessagesDialogs(long offset, int count) throws MalformedURLException, IOException, JSONException, KException{
57  
-        Params params = new Params("messages.getDialogs");
58  
-        if (offset!=0)
59  
-            params.put("offset", offset);
60  
-        if (count != 0)
61  
-            params.put("count", count);
62  
-        params.put("preview_length","0");
63  
-        JSONObject root = sendRequest(params);
64  
-        JSONArray array = root.optJSONArray("response");
65  
-        ArrayList<Message> messages = parseMessages(array, false, 0, false ,0);
66  
-        return messages;
67  
-    }
68  
-
69  
-    private ArrayList<Message> parseMessages(JSONArray array, boolean from_history, long history_uid, boolean from_chat, long me) throws JSONException {
70  
-        ArrayList<Message> messages = new ArrayList<Message>();
71  
-        if (array != null) {
72  
-            int category_count = array.length();
73  
-            for(int i = 1; i < category_count; ++i) {
74  
-                JSONObject o = (JSONObject)array.get(i);
75  
-                Message m = Message.parse(o, from_history, history_uid, from_chat, me);
76  
-                messages.add(m);
77  
-            }
78  
-        }
79  
-        return messages;
80  
-    }
81  
-
82  
-    /*** methods for news 
83  
-     * @throws KException ***/
84  
-    //http://vkontakte.ru/developers.php?o=-1&p=newsfeed.get
85  
-    //always returns about 33-35 items
86  
-//    public Newsfeed getNews(long start_time, long count, long end_time) throws MalformedURLException, IOException, JSONException, KException{
87  
-//        Params params = new Params("newsfeed.get");
88  
-//        params.put("filters","post,photo,photo_tag,friend,note");
89  
-//        params.put("start_time",(start_time==-1)?getDefaultStartTime():start_time);
90  
-//        if(end_time!=-1)
91  
-//            params.put("end_time",end_time);
92  
-//        if(count!=0)
93  
-//            params.put("count",count);
94  
-//        JSONObject root = sendRequest(params);
95  
-//        return Newsfeed.parse(root, false);
96  
-//    }
97  
-//
98  
-//    //Новости-Комментарии. Описания нет.
99  
-//    public Newsfeed  throws MalformedURLException, IOException, JSONException, KException{
100  
-//        Params params = new Params("newsfeed.getComments");
101  
-//        params.put("last_comments","1");
102  
-//        params.put("count","50");
103  
-//        JSONObject root = sendRequest(params);
104  
-//        return Newsfeed.parse(root, true);
105  
-//    }
106  
-
107  
-    /*** for notes ***/
108  
-   
109  
-    
110  
-    
111  
-    //http://vkontakte.ru/developers.php?o=-1&p=wall.getComments
112  
-    public CommentList getWallComments(Long owner_id, Long post_id, int offset, int count) throws MalformedURLException, IOException, JSONException, KException{
113  
-        Params params = new Params("wall.getComments");
114  
-        params.put("post_id", post_id);
115  
-        params.put("owner_id", owner_id);
116  
-        /*
117  
-        if (sort != null)
118  
-            params.put("sort", sort);
119  
-            //asc - хронологический
120  
-            //desc - антихронологический
121  
-        */
122  
-        if (offset > 0)
123  
-            params.put("offset", offset);
124  
-        if (count > 0)
125  
-            params.put("count", count);
126  
-        params.put("preview_length", "0");
127  
-        params.put("need_likes", "1");
128  
-        JSONObject root = sendRequest(params);
129  
-        JSONArray array = root.getJSONArray("response");
130  
-        CommentList commnets = new CommentList();
131  
-        commnets.count=array.getInt(0);
132  
-        int category_count = array.length();
133  
-        for(int i = 1; i<category_count; ++i) //get(0) is integer, it is comments count
134  
-            commnets.comments.add(Comment.parse((JSONObject)array.get(i)));
135  
-        return commnets;
136  
-    }
137  
-    
138  
-   
139  
-    //http://vkontakte.ru/developers.php?oid=-1&p=groups.get
140  
-    public ArrayList<Group> getUserGroups(Long user_id) throws MalformedURLException, IOException, JSONException, KException{
141  
-        Params params = new Params("groups.get");
142  
-        params.put("extended","1");
143  
-        params.put("uid",user_id);
144  
-        JSONObject root = sendRequest(params);
145  
-        ArrayList<Group> groups=new ArrayList<Group>();
146  
-        JSONArray array=root.optJSONArray("response");
147  
-        //if there are no groups "response" will not be array
148  
-        if(array==null)
149  
-            return groups;
150  
-        groups = Group.parseGroups(array);
151  
-        return groups;
152  
-    }
153  
-
154  
-    //http://vkontakte.ru/developers.php?o=-1&p=video.search
155  
-    public ArrayList<Video> searchVideo(String q, String sort, String hd, Long count, Long offset) throws MalformedURLException, IOException, JSONException, KException {
156  
-        Params params = new Params("video.search");
157  
-        params.put("q", q);
158  
-        params.put("sort", sort);
159  
-        params.put("hd", hd);
160  
-        params.put("count", count);
161  
-        params.put("offset", offset);
162  
-        JSONObject root = sendRequest(params);
163  
-        JSONArray array = root.optJSONArray("response");
164  
-        ArrayList<Video> videoss = new ArrayList<Video>();
165  
-        if (array != null) {
166  
-            for(int i = 0; i<array.length(); ++i) {
167  
-                JSONObject o = (JSONObject)array.get(i);
168  
-                Video video = Video.parse(o);
169  
-                videoss.add(video);
170  
-            }
171  
-        }
172  
-        
173  
-        //TODO Это вроде лишнее. В результатах поиска не хватает только link, но ведь он составляется из owner_id+video_id
174  
-        String video_ids = "";
175  
-        for (Video v:videoss) {
176  
-            video_ids = video_ids + String.valueOf(v.owner_id) + "_" + String.valueOf(v.vid) + ","; 
177  
-        }
178  
-        return getVideo(video_ids, null, null, null, null, null);
179  
-    }
180  
-   
181  
-    //http://vkontakte.ru/developers.php?o=-1&p=video.delete
182  
-    
183  
-   
184 21
     /*** topics region ***/
185 22
     //http://kate1.unfuddle.com/a#/projects/2/tickets/by_number/340?cycle=true
186 23
     public ArrayList<GroupTopic> getGroupTopics(long gid, int extended, int count, int offset) throws MalformedURLException, IOException, JSONException, KException {
@@ -208,151 +45,4 @@ public CommentList getWallComments(Long owner_id, Long post_id, int offset, int
208 45
         }
209 46
         return result;
210 47
     }
211  
-    
212  
-    public CommentList getGroupTopicComments(long gid, long tid, int photo_sizes, int extended, int count, int offset) throws MalformedURLException, IOException, JSONException, KException{
213  
-        Params params = new Params("board.getComments");
214  
-        params.put("gid", gid);
215  
-        params.put("tid", tid);
216  
-        if (photo_sizes == 1)
217  
-            params.put("photo_sizes", "1");
218  
-        if (extended == 1)
219  
-            params.put("extended", "1");
220  
-        if (count > 0)
221  
-            params.put("count", count);
222  
-        if (offset > 0)
223  
-            params.put("offset", offset);
224  
-        JSONObject root = sendRequest(params);
225  
-        JSONObject response = root.optJSONObject("response");
226  
-        CommentList result = new CommentList();
227  
-        if (response != null) {
228  
-            JSONArray comments = response.optJSONArray("comments");
229  
-            int category_count = comments.length();
230  
-            result.count=comments.getInt(0);
231  
-            for (int i=1; i<category_count; ++i) { //get(0) is integer, it is comments count
232  
-                JSONObject o = comments.getJSONObject(i);
233  
-                Comment c = Comment.parseTopicComment(o);
234  
-                result.comments.add(c);
235  
-            }
236  
-        }
237  
-        return result;
238  
-    }
239  
-    
240  
-    /*** end topics region ***/
241  
-    
242  
-    //http://vk.com/developers.php?oid=-1&p=groups.getById
243  
-    public ArrayList<Group> getGroups(Collection<Long> uids, String domain, String fields) throws MalformedURLException, IOException, JSONException, KException{
244  
-        if (uids == null && domain == null)
245  
-            return null;
246  
-        if (uids.size() == 0 && domain == null)
247  
-            return null;
248  
-        Params params = new Params("groups.getById");
249  
-        String str_uids;
250  
-        if (uids != null && uids.size() > 0)
251  
-            str_uids=arrayToString(uids);
252  
-        else
253  
-            str_uids = domain;
254  
-        params.put("gids", str_uids);
255  
-        params.put("fields", fields); //Possible values: place,wiki_page,city,country,description,start_date,finish_date,site
256  
-        JSONObject root = sendRequest(params);
257  
-        JSONArray array=root.optJSONArray("response");
258  
-        return Group.parseGroups(array);
259  
-    }
260  
-
261  
-    
262  
-    //no documentation
263  
-    public ArrayList<Group> searchGroup(String q, Long count, Long offset) throws MalformedURLException, IOException, JSONException, KException {
264  
-        Params params = new Params("groups.search");
265  
-        params.put("q", q);
266  
-        params.put("count", count);
267  
-        params.put("offset", offset);
268  
-        JSONObject root = sendRequest(params);
269  
-        JSONArray array=root.optJSONArray("response");
270  
-        ArrayList<Group> groups = new ArrayList<Group>();  
271  
-        //if there are no groups "response" will not be array
272  
-        if (array==null)
273  
-            return groups;
274  
-        groups = Group.parseGroups(array);
275  
-        return groups;
276  
-    }
277  
-    
278  
-    //http://vk.com/pages?oid=-1&p=account.registerDevice
279  
-    
280  
-    //http://vk.com/pages?oid=-1&p=account.unregisterDevice
281  
-    //http://vk.com/developers.php?oid=-1&p=notifications.get
282  
-    public Notifications getNotifications(String filters, Long start_time, Long end_time, Integer offset, Integer count) throws MalformedURLException, IOException, JSONException, KException {
283  
-        Params params = new Params("notifications.get");
284  
-        params.put("filters", filters);
285  
-        params.put("start_time", start_time);
286  
-        params.put("end_time", end_time);
287  
-        params.put("offset", offset);
288  
-        params.put("count", count);
289  
-        JSONObject root = sendRequest(params);
290  
-        JSONObject response = root.optJSONObject("response");
291  
-        return Notifications.parse(response);
292  
-    }
293  
-    
294  
-    //http://vk.com/developers.php?oid=-1&p=notifications.markAsViewed
295  
-    //http://vk.com/developers.php?oid=-1&p=messages.getById
296  
-    public ArrayList<Message> getMessagesById(ArrayList<Long> message_ids) throws MalformedURLException, IOException, JSONException, KException{
297  
-        Params params = new Params("messages.getById");
298  
-        params.put("mids", arrayToString(message_ids));
299  
-        JSONObject root = sendRequest(params);
300  
-        JSONArray array = root.optJSONArray("response");
301  
-        ArrayList<Message> messages = parseMessages(array, false, 0, false, 0);
302  
-        return messages;
303  
-    }
304  
-    
305  
-    /*** faves ***/
306  
-    
307  
-    
308  
-    
309  
-    //http://vk.com/developers.php?oid=-1&p=fave.getPosts
310  
-    public ArrayList<WallMessage> getFavePosts(Integer count, Integer offset) throws MalformedURLException, IOException, JSONException, KException{
311  
-        Params params = new Params("fave.getPosts");
312  
-        //params.put("extended", extended);
313  
-        params.put("count", count);
314  
-        params.put("offset", offset);
315  
-        JSONObject root = sendRequest(params);
316  
-        JSONArray array = root.optJSONArray("response");
317  
-        //JSONArray array = response.optJSONArray("wall");
318  
-        //JSONArray profiles_array = response.optJSONArray("profiles");
319  
-        //JSONArray groups_array = response.optJSONArray("groups");
320  
-        ArrayList<WallMessage> wmessages = new ArrayList<WallMessage>();
321  
-        if (array == null)
322  
-            return wmessages;
323  
-        int category_count = array.length();
324  
-        for(int i = 1; i < category_count; ++i) {
325  
-            JSONObject o = (JSONObject)array.get(i);
326  
-            WallMessage wm = WallMessage.parse(o);
327  
-            wmessages.add(wm);
328  
-        }
329  
-        return wmessages;
330  
-    }
331  
-
332  
-    /*** end faves  ***/
333  
-    
334  
-    /*** chat methods ***/
335  
-
336  
-    /*** methods for messages search ***/      
337  
-    //http://vk.com/pages?oid=-1&p=messages.search
338  
-    public ArrayList<Message> searchMessages(String q, int offset, int count) throws MalformedURLException, IOException, JSONException, KException{
339  
-        Params params = new Params("messages.search");
340  
-        params.put("q", q);
341  
-        params.put("count", count);
342  
-        params.put("offset", offset);
343  
-        JSONObject root = sendRequest(params);
344  
-        JSONArray array = root.optJSONArray("response");
345  
-        ArrayList<Message> messages = parseMessages(array, false, 0, false, 0);
346  
-        return messages;
347  
-    }
348  
-    
349  
-    //http://vk.com/pages?oid=-1&p=messages.searchDialogs
350  
-    public ArrayList<SearchDialogItem> searchDialogs(String q, String fields) throws MalformedURLException, IOException, JSONException, KException{
351  
-        Params params = new Params("messages.searchDialogs");
352  
-        params.put("q", q);
353  
-        params.put("fields", fields);
354  
-        JSONObject root = sendRequest(params);
355  
-        JSONArray array = root.optJSONArray("response");
356  
-        return Message.parseSearchedDialogs(array);
357  
-    }
358 48
 }
65  AndroidVkSdk/src/com/perm/kate/api/deprecated/Group.java
@@ -8,70 +8,5 @@
8 8
 import org.json.JSONObject;
9 9
 
10 10
 public class Group implements Serializable {
11  
-    
12  
-    private static final long serialVersionUID = 1L;
13  
-    public long gid;
14  
-    public String name;
15  
-    public String photo;//50*50
16  
-    public Boolean is_closed;
17  
-    public Boolean is_member;
18  
-    
19  
-    //это новые поля, которых у нас пока нет в базе
20  
-    //public String screen_name;
21  
-    //public Boolean is_admin;
22  
-    public String photo_medium;//100*100
23  
-    public String photo_big;//200*200
24  
-    public String description;
25 11
 
26  
-    public static Group parse(JSONObject o) throws JSONException{
27  
-        Group g=new Group();
28  
-        g.gid = o.getLong("gid");
29  
-        g.name = Api.unescape(o.getString("name"));
30  
-        g.photo = o.optString("photo");
31  
-        g.photo_medium = o.optString("photo_medium");
32  
-        g.photo_big = o.optString("photo_big");
33  
-        String is_closed = o.optString("is_closed");
34  
-        if(is_closed != null)
35  
-            g.is_closed = is_closed.equals("1");
36  
-        String is_member = o.optString("is_member");
37  
-        if(is_member != null)
38  
-            g.is_member = is_member.equals("1");
39  
-        String description_text = o.optString("description");
40  
-        if (description_text != null)
41  
-            g.description = Api.unescape(description_text);
42  
-        
43  
-        //это новые поля, которых у нас пока нет в базе
44  
-        //g.screen_name=o.optString("screen_name");
45  
-        //String is_admin=o.optString("is_admin");
46  
-        //if(is_admin!=null)
47  
-        //    g.is_admin=is_admin.equals("1");
48  
-        //g.photo_medium = o.getString("photo_medium");
49  
-        //g.photo_big = o.getString("photo_big");
50  
-        return g;
51  
-    }
52  
-    
53  
-    public static ArrayList<Group> parseGroups(JSONArray jgroups) throws JSONException {
54  
-        ArrayList<Group> groups=new ArrayList<Group>();
55  
-        for(int i = 0; i < jgroups.length(); i++) {
56  
-            //для метода groups.get первый элемент - количество
57  
-            if(!(jgroups.get(i) instanceof JSONObject))
58  
-                continue;
59  
-            JSONObject jgroup = (JSONObject)jgroups.get(i);
60  
-            Group group = Group.parse(jgroup);
61  
-            groups.add(group);
62  
-        }
63  
-        return groups;
64  
-    }
65  
-    
66  
-    public static Group parseFaveGroup(JSONObject o) throws JSONException{
67  
-        Group g = new Group();
68  
-        String url = o.getString("url");
69  
-        g.gid = Long.parseLong(url.replace("/club", ""));
70  
-        g.name = Api.unescape(o.getString("title"));
71  
-        g.photo_medium = o.optString("image_src");        
72  
-        String description_text = o.optString("description");
73  
-        if (description_text != null)
74  
-            g.description = Api.unescape(description_text);
75  
-        return g;
76  
-    }
77 12
 }
53  AndroidVkSdk/src/com/perm/kate/api/deprecated/Message.java
... ...
@@ -1,53 +0,0 @@
1  
-package com.perm.kate.api.deprecated;
2  
-
3  
-import java.util.ArrayList;
4  
-import org.json.JSONArray;
5  
-import org.json.JSONException;
6  
-import org.json.JSONObject;
7  
-
8  
-import com.perm.kate.api.deprecated.SearchDialogItem.SDIType;
9  
-
10  
-public class Message {
11  
-    
12  
-    
13  
-    public static ArrayList<SearchDialogItem> parseSearchedDialogs(JSONArray array) {
14  
-        ArrayList<SearchDialogItem> items = new ArrayList<SearchDialogItem>();
15  
-        if (array == null)
16  
-            return items;
17  
-        try {
18  
-            int category_count = array.length();
19  
-            for (int i=0; i<category_count; ++i) {
20  
-                if (array.get(i)==null || ((array.get(i) instanceof JSONObject) == false))
21  
-                    continue;
22  
-                JSONObject o = (JSONObject)array.get(i);
23  
-                SearchDialogItem item = new SearchDialogItem();
24  
-                String type = o.getString("type");
25  
-                item.str_type = type;
26  
-                if (type.equals("profile")) {
27  
-                    item.type = SDIType.USER;
28  
-                    item.user = User.parse(o);
29  
-                } else if (type.equals("chat")) {
30  
-                    item.type = SDIType.CHAT;
31  
-                    Message m = new Message();
32  
-                    m.chat_id = o.getLong("chat_id");
33  
-                    m.admin_id = o.getLong("admin_id");
34  
-                    m.title = o.getString("title");
35  
-                    JSONArray users = o.optJSONArray("users");
36  
-                    if(users != null && users.length() != 0) {
37  
-                        m.chat_members = new ArrayList<Long>();
38  
-                        for (int j=0;j<users.length();j++)
39  
-                            m.chat_members.add(users.getLong(j));
40  
-                    }
41  
-                    item.chat = m;
42  
-                } else {
43  
-                    item.type = SDIType.EMAIL;
44  
-                    item.email = o.optString("email");
45  
-                }
46  
-                items.add(item);
47  
-            }
48  
-        } catch (JSONException e) {
49  
-            e.printStackTrace();
50  
-        }
51  
-        return items;
52  
-    }
53  
-}
18  AndroidVkSdk/src/com/perm/kate/api/deprecated/Notification.java
@@ -9,23 +9,7 @@
9 9
 public class Notification implements Serializable {
10 10
     
11 11
     private static final long serialVersionUID = 1L;
12  
-    public static final String FOLLOW = "follow";
13  
-    public static final String FRIEND_ACCEPTED = "friend_accepted";
14  
-    public static final String MENTION = "mention";
15  
-    public static final String MENTION_COMMENTS = "mention_comments";
16  
-    public static final String WALL = "wall";
17  
-    public static final String COMMENT_POST = "comment_post";
18  
-    public static final String COMMENT_PHOTO = "comment_photo";
19  
-    public static final String COMMENT_VIDEO = "comment_video";
20  
-    public static final String REPLY_COMMENT = "reply_comment";
21  
-    public static final String REPLY_TOPIC = "reply_topic";
22  
-    public static final String LIKE_POST = "like_post";
23  
-    public static final String LIKE_COMMENT = "like_comment";
24  
-    public static final String LIKE_PHOTO = "like_photo";
25  
-    public static final String LIKE_VIDEO = "like_video";
26  
-    public static final String COPY_POST = "copy_post";
27  
-    public static final String COPY_PHOTO = "copy_photo";
28  
-    public static final String COPY_VIDEO = "copy_video";
  12
+    
29 13
     
30 14
     public String type;
31 15
     public Long date;
22  AndroidVkSdk/src/com/perm/kate/api/deprecated/Notifications.java
@@ -8,27 +8,5 @@
8 8
 
9 9
 public class Notifications implements Serializable {
10 10
     
11  
-    private static final long serialVersionUID = 1L;
12  
-    public ArrayList<Notification> notifications=new ArrayList<Notification>();
13  
-    public ArrayList<User> profiles=new ArrayList<User>();
14  
-    public ArrayList<Group> groups=new ArrayList<Group>();
15  
-    
16  
-    public static Notifications parse(JSONObject response) throws JSONException{
17  
-        Notifications full_notifications = new Notifications();
18  
-        full_notifications.notifications = new ArrayList<Notification>();
19  
-        if (response==null)
20  
-            return full_notifications;
21  
-        JSONArray array = response.optJSONArray("items");
22  
-        JSONArray profiles_array = response.optJSONArray("profiles");
23  
-        JSONArray groups_array = response.optJSONArray("groups");
24  
-        if (array==null)
25  
-            return full_notifications;
26  
-        if (profiles_array != null)
27  
-            full_notifications.profiles = User.parseUsers(profiles_array);
28  
-        if (groups_array != null)
29  
-            full_notifications.groups = Group.parseGroups(groups_array);
30  
-        full_notifications.notifications = Notification.parseNotifications(array);
31  
-        return full_notifications;
32  
-    }
33 11
     
34 12
 }
20  AndroidVkSdk/src/com/perm/kate/api/models/Constants.java
@@ -79,4 +79,24 @@
79 79
 	    public static int MEDIA = 512;		//сообщение содержит медиаконтент
80 80
 	    public static int BESEDA = 8192;    //беседа
81 81
 	}
  82
+	
  83
+	public static final class NotificationConstants {
  84
+		public static final String FOLLOW = "follow";
  85
+	    public static final String FRIEND_ACCEPTED = "friend_accepted";
  86
+	    public static final String MENTION = "mention";
  87
+	    public static final String MENTION_COMMENTS = "mention_comments";
  88
+	    public static final String WALL = "wall";
  89
+	    public static final String COMMENT_POST = "comment_post";
  90
+	    public static final String COMMENT_PHOTO = "comment_photo";
  91
+	    public static final String COMMENT_VIDEO = "comment_video";
  92
+	    public static final String REPLY_COMMENT = "reply_comment";
  93
+	    public static final String REPLY_TOPIC = "reply_topic";
  94
+	    public static final String LIKE_POST = "like_post";
  95
+	    public static final String LIKE_COMMENT = "like_comment";
  96
+	    public static final String LIKE_PHOTO = "like_photo";
  97
+	    public static final String LIKE_VIDEO = "like_video";
  98
+	    public static final String COPY_POST = "copy_post";
  99
+	    public static final String COPY_PHOTO = "copy_photo";
  100
+	    public static final String COPY_VIDEO = "copy_video";
  101
+	}
82 102
 }
20  AndroidVkSdk/src/com/perm/kate/api/models/social/SearchDialogItem.java
@@ -17,43 +17,43 @@ public SearchDialogItem() {
17 17
 		// TODO Auto-generated constructor stub
18 18
 	}
19 19
 
20  
-	public String getmType() {
  20
+	public String getType() {
21 21
 		return mType;
22 22
 	}
23 23
 
24  
-	public void setmType(String mType) {
  24
+	public void setType(String mType) {
25 25
 		this.mType = mType;
26 26
 	}
27 27
 
28  
-	public SearchDialogItemType getmItemType() {
  28
+	public SearchDialogItemType getItemType() {
29 29
 		return mItemType;
30 30
 	}
31 31
 
32  
-	public void setmItemType(SearchDialogItemType mItemType) {
  32
+	public void setItemType(SearchDialogItemType mItemType) {
33 33
 		this.mItemType = mItemType;
34 34
 	}
35 35
 
36  
-	public String getmEmail() {
  36
+	public String getEmail() {
37 37
 		return mEmail;
38 38
 	}
39 39
 
40  
-	public void setmEmail(String mEmail) {
  40
+	public void setEmail(String mEmail) {
41 41
 		this.mEmail = mEmail;
42 42
 	}
43 43
 
44  
-	public User getmUser() {
  44
+	public User getUser() {
45 45
 		return mUser;
46 46
 	}
47 47
 
48  
-	public void setmUser(User mUser) {
  48
+	public void setUser(User mUser) {
49 49
 		this.mUser = mUser;
50 50
 	}
51 51
 
52  
-	public Message getmMessage() {
  52
+	public Message getMessage() {
53 53
 		return mMessage;
54 54
 	}
55 55
 
56  
-	public void setmMessage(Message mMessage) {
  56
+	public void setMessage(Message mMessage) {
57 57
 		this.mMessage = mMessage;
58 58
 	}
59 59
 }
25  AndroidVkSdk/src/com/perm/kate/api/response/NotificationResponseHandler.java
... ...
@@ -0,0 +1,25 @@
  1
+package com.perm.kate.api.response;
  2
+
  3
+import java.util.Collection;
  4
+
  5
+import org.json.JSONArray;
  6
+import org.json.JSONException;
  7
+import org.json.JSONObject;
  8
+
  9
+import com.perm.kate.api.models.Parseable;
  10
+import com.perm.kate.api.models.ParseableCollection;
  11
+import com.perm.kate.api.models.social.Notification;
  12
+
  13
+public class NotificationResponseHandler implements Parseable<Notification>, ParseableCollection<Notification>{
  14
+
  15
+	public Notification parse(JSONObject jsonObject) throws JSONException {
  16
+		// TODO
  17
+		return null;
  18
+	}
  19
+
  20
+	public Collection<Notification> parse(JSONArray array) throws JSONException {
  21
+		// TODO Auto-generated method stub
  22
+		return null;
  23
+	}
  24
+
  25
+}
41  AndroidVkSdk/src/com/perm/kate/api/response/NotificationsResponseHandler.java
... ...
@@ -0,0 +1,41 @@
  1
+package com.perm.kate.api.response;
  2
+
  3
+import java.util.ArrayList;
  4
+
  5
+import org.json.JSONArray;
  6
+import org.json.JSONException;
  7
+import org.json.JSONObject;
  8
+
  9
+import com.perm.kate.api.models.Parseable;
  10
+import com.perm.kate.api.models.social.Notification;
  11
+import com.perm.kate.api.models.social.Notifications;
  12
+import com.perm.kate.api.response.social.GroupResponseHandler;
  13
+import com.perm.kate.api.response.social.UserResponseHandler;
  14
+
  15
+public class NotificationsResponseHandler implements Parseable<Notifications>{
  16
+
  17
+	public Notifications parse(JSONObject jsonObject) throws JSONException {
  18
+		Notifications fullNotifications = new Notifications();
  19
+		fullNotifications.setNotifications(new ArrayList<Notification>());
  20
+		if(jsonObject == null){
  21
+			return null;
  22
+		}
  23
+		JSONArray array = jsonObject.optJSONArray("items");
  24
+        JSONArray profiles = jsonObject.optJSONArray("profiles");
  25
+        JSONArray groups = jsonObject.optJSONArray("groups");
  26
+        if(array == null){
  27
+        	return null;
  28
+        }
  29
+        if(profiles != null){
  30
+        	UserResponseHandler handler = new UserResponseHandler();
  31
+        	fullNotifications.getProfiles().addAll(handler.parse(array));
  32
+        }
  33
+        if(groups != null){
  34
+        	GroupResponseHandler groupResponseHandler = new GroupResponseHandler();
  35
+        	fullNotifications.getGroups().addAll(groupResponseHandler.parse(groups));
  36
+        }
  37
+        NotificationResponseHandler notificationResponseHandler = new NotificationResponseHandler();
  38
+        fullNotifications.getNotifications().addAll(notificationResponseHandler.parse(array));
  39
+		return fullNotifications;
  40
+	}
  41
+}
72  AndroidVkSdk/src/com/perm/kate/api/response/social/GroupResponseHandler.java
... ...
@@ -0,0 +1,72 @@
  1
+package com.perm.kate.api.response.social;