Skip to content

Commit

Permalink
Build 31
Browse files Browse the repository at this point in the history
  • Loading branch information
tretdm committed Apr 30, 2023
1 parent b2ee57a commit 814b936
Show file tree
Hide file tree
Showing 71 changed files with 1,804 additions and 822 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "uk.openvk.android.refresh"
minSdk 21
targetSdk 33
versionCode 30
versionName "0.9.30.alpha"
versionCode 31
versionName "0.9.31.alpha"
}

buildTypes {
Expand Down
120 changes: 85 additions & 35 deletions app/src/main/java/uk/openvk/android/refresh/api/Newsfeed.java

Large diffs are not rendered by default.

90 changes: 71 additions & 19 deletions app/src/main/java/uk/openvk/android/refresh/api/Wall.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,28 +96,40 @@ public void parse(Context ctx, DownloadManager downloadManager, String quality,
String author_avatar_url = "";
String content = post.getString("text");
boolean isLiked = false;
boolean verified_author;
if(likes.getInt("user_likes") > 0) {
isLiked = true;
} else {
isLiked = false;
}
PostCounters counters = new PostCounters(likes.getInt("count"), comments.getInt("count"), reposts.getInt("count"), isLiked, false);
PostCounters counters = new PostCounters(likes.getInt("count"),
comments.getInt("count"), reposts.getInt("count"), isLiked,
false);

ArrayList<Attachment> attachments_list = createAttachmentsList(owner_id, post_id, quality, attachments);
ArrayList<Attachment> attachments_list = createAttachmentsList(owner_id, post_id,
quality, attachments);

WallPost item = new WallPost(String.format("(Unknown author: %s)", author_id), dt_sec, null, content, counters, "", attachments_list, owner_id, post_id, ctx);
WallPost item = new WallPost(String.format("(Unknown author: %s)", author_id),
dt_sec, null, content, counters, "", attachments_list,
owner_id, post_id, ctx);
if(post.has("post_source") && !post.isNull("post_source")) {
if(post.getJSONObject("post_source").getString("type").equals("api")) {
item.post_source = new WallPostSource(post.getJSONObject("post_source").getString("type"), post.getJSONObject("post_source").getString("platform"));
item.post_source = new WallPostSource(
post.getJSONObject("post_source").getString("type"),
post.getJSONObject("post_source").getString("platform"));
} else {
item.post_source = new WallPostSource(post.getJSONObject("post_source").getString("type"), null);
item.post_source = new WallPostSource(
post.getJSONObject("post_source").getString("type"), null);
}
}
if(post.getJSONArray("copy_history").length() > 0) {
JSONObject repost = post.getJSONArray("copy_history").getJSONObject(0);
WallPost repost_item = new WallPost(String.format("(Unknown author: %s)", repost.getInt("from_id")), repost.getInt("date"), null, repost.getString("text"), null, "",
WallPost repost_item = new WallPost(String.format("(Unknown author: %s)",
repost.getInt("from_id")), repost.getInt("date"), null,
repost.getString("text"), null, "",
null, repost.getInt("owner_id"), repost.getInt("id"), ctx);
RepostInfo repostInfo = new RepostInfo(String.format("(Unknown author: %s)", repost.getInt("from_id")), repost.getInt("date"), ctx);
RepostInfo repostInfo = new RepostInfo(String.format("(Unknown author: %s)",
repost.getInt("from_id")), repost.getInt("date"), ctx);
repostInfo.newsfeed_item = repost_item;
item.repost = repostInfo;
JSONArray repost_attachments = repost.getJSONArray("attachments");
Expand All @@ -131,11 +143,23 @@ public void parse(Context ctx, DownloadManager downloadManager, String quality,
for (int profiles_index = 0; profiles_index < profiles.length(); profiles_index++) {
JSONObject profile = profiles.getJSONObject(profiles_index);
if (profile.getInt("id") == author_id) {
author_name = String.format("%s %s", profile.getString("first_name"), profile.getString("last_name"));
author_name = String.format("%s %s", profile.getString("first_name"),
profile.getString("last_name"));
author_avatar_url = profile.getString("photo_50");
if(profile.get("verified") instanceof Integer) {
verified_author = profile.getInt("verified") == 1;
} else {
verified_author = profile.getBoolean("verified");
}
} else if (profile.getInt("id") == owner_id) {
owner_name = String.format("%s %s", profile.getString("first_name"), profile.getString("last_name"));
owner_name = String.format("%s %s", profile.getString("first_name"),
profile.getString("last_name"));
owner_avatar_url = profile.getString("photo_50");
if(profile.get("verified") instanceof Integer) {
verified_author = profile.getInt("verified") == 1;
} else {
verified_author = profile.getBoolean("verified");
}
}
}
if(author_avatar_url.length() > 0)
Expand All @@ -149,6 +173,11 @@ public void parse(Context ctx, DownloadManager downloadManager, String quality,
if (-group.getInt("id") == owner_id) {
owner_name = group.getString("name");
avatar_url = group.getString("photo_50");
if (group.getBoolean("verified")) {
verified_author = true;
} else {
verified_author = false;
}
}
}
}
Expand All @@ -167,6 +196,11 @@ public void parse(Context ctx, DownloadManager downloadManager, String quality,
if (-group.getInt("id") == author_id) {
item.name = group.getString("name");
avatar_url = group.getString("photo_50");
if (group.getBoolean("verified")) {
verified_author = true;
} else {
verified_author = false;
}
}
}
}
Expand Down Expand Up @@ -224,7 +258,8 @@ public ArrayList<Comment> parseComments(Context ctx, DownloadManager downloadMan
for (int profiles_index = 0; profiles_index < profiles.length(); profiles_index++) {
JSONObject profile = profiles.getJSONObject(profiles_index);
if (profile.getLong("id") == author_id) {
comment.author = String.format("%s %s", profile.getString("first_name"), profile.getString("last_name"));
comment.author = String.format("%s %s", profile.getString("first_name"),
profile.getString("last_name"));
if(profile.has("photo_100")) {
comment.avatar_url = profile.getString("photo_100");
}
Expand Down Expand Up @@ -260,7 +295,8 @@ public ArrayList<Comment> parseComments(Context ctx, DownloadManager downloadMan
return comments;
}

public ArrayList<Attachment> createAttachmentsList(long owner_id, long post_id, String quality, JSONArray attachments) {
public ArrayList<Attachment> createAttachmentsList(long owner_id, long post_id, String quality,
JSONArray attachments) {
ArrayList<Attachment> attachments_list = new ArrayList<>();
try {
for (int attachments_index = 0; attachments_index < attachments.length(); attachments_index++) {
Expand Down Expand Up @@ -338,7 +374,8 @@ public ArrayList<Attachment> createAttachmentsList(long owner_id, long post_id,
if(video.has("image")) {
JSONArray thumb_array = video.getJSONArray("image");
videoAttachment.url_thumb = thumb_array.getJSONObject(0).getString("url");
dlm.downloadOnePhotoToCache(videoAttachment.url_thumb, String.format("thumbnail_%s", video.getLong("id")), "video_thumbnails");
dlm.downloadOnePhotoToCache(videoAttachment.url_thumb, String.format("thumbnail_%s",
video.getLong("id")), "video_thumbnails");
}
videoAttachment.duration = video.getInt("duration");
attachment_status = "done";
Expand All @@ -348,7 +385,12 @@ public ArrayList<Attachment> createAttachmentsList(long owner_id, long post_id,
attachments_list.add(attachment_obj);
} else if (attachment.getString("type").equals("poll")) {
JSONObject poll_attachment = attachment.getJSONObject("poll");
PollAttachment pollAttachment = new PollAttachment(poll_attachment.getString("question"), poll_attachment.getInt("id"), poll_attachment.getLong("end_date"), poll_attachment.getBoolean("multiple"), poll_attachment.getBoolean("can_vote"),
PollAttachment pollAttachment = new PollAttachment(poll_attachment
.getString("question"),
poll_attachment.getInt("id"), poll_attachment
.getLong("end_date"),
poll_attachment.getBoolean("multiple"), poll_attachment
.getBoolean("can_vote"),
poll_attachment.getBoolean("anonymous"));
JSONArray answers = poll_attachment.getJSONArray("answers");
JSONArray votes = poll_attachment.getJSONArray("answer_ids");
Expand All @@ -358,7 +400,9 @@ public ArrayList<Attachment> createAttachmentsList(long owner_id, long post_id,
pollAttachment.votes = poll_attachment.getInt("votes");
for (int answers_index = 0; answers_index < answers.length(); answers_index++) {
JSONObject answer = answers.getJSONObject(answers_index);
PollAnswer pollAnswer = new PollAnswer(answer.getInt("id"), answer.getInt("rate"), answer.getInt("votes"), answer.getString("text"));
PollAnswer pollAnswer = new PollAnswer(answer.getInt("id"),
answer.getInt("rate"),
answer.getInt("votes"), answer.getString("text"));
for (int votes_index = 0; votes_index < votes.length(); votes_index++) {
if (answer.getInt("id") == votes.getInt(votes_index)) {
pollAnswer.is_voted = true;
Expand All @@ -385,27 +429,35 @@ public ArrayList<Attachment> createAttachmentsList(long owner_id, long post_id,
}

public void get(OvkAPIWrapper ovk, long owner_id, int count) {
ovk.sendAPIMethod("Wall.get", String.format("owner_id=%s&count=%s&extended=1", owner_id, count));
ovk.sendAPIMethod("Wall.get", String.format("owner_id=%s&count=%s&extended=1",
owner_id, count));
}

public ArrayList<WallPost> getWallItems() {
return items;
}

public void post(OvkAPIWrapper ovk, long owner_id, String post) {
ovk.sendAPIMethod("Wall.post", String.format("owner_id=%s&message=%s", owner_id, Strings.urlEncode(post)));
ovk.sendAPIMethod("Wall.post", String.format("owner_id=%s&message=%s", owner_id,
Strings.urlEncode(post)));
}

public void getComments(OvkAPIWrapper ovk, long owner_id, long post_id) {
ovk.sendAPIMethod("Wall.getComments", String.format("owner_id=%s&post_id=%s&extended=1&count=50", owner_id, post_id));
ovk.sendAPIMethod("Wall.getComments", String.format("owner_id=%s&post_id=%s&extended=1" +
"&count=50",
owner_id, post_id));
}

public void createComment(OvkAPIWrapper ovk, long owner_id, long post_id, String text) {
ovk.sendAPIMethod("Wall.createComment", String.format("owner_id=%s&post_id=%s&message=%s", owner_id, post_id, Strings.urlEncode(text)));
ovk.sendAPIMethod("Wall.createComment", String.format("owner_id=%s&post_id=%s&message=%s",
owner_id,
post_id, Strings.urlEncode(text)));
}

public void repost(OvkAPIWrapper ovk, long owner_id, long post_id, String text) {
ovk.sendAPIMethod("Wall.repost", String.format("object=wall%s_%s&message=%s", owner_id, post_id, Strings.urlEncode(text)));
ovk.sendAPIMethod("Wall.repost", String.format("object=wall%s_%s&message=%s", owner_id,
post_id,
Strings.urlEncode(text)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public VideoAttachment() {

}

public VideoAttachment(long id, String title, VideoFiles files, String url_thumb, int duration, String filename) {
public VideoAttachment(long id, String title, VideoFiles files, String url_thumb, int duration,
String filename) {
this.id = id;
this.title = title;
this.files = files;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public class PostCounters implements Parcelable {
public boolean isReposted;
public boolean enabled = true;

public PostCounters(int likes_count, int comments_count, int reposts_count, boolean likes_selected, boolean reposts_selected) {
public PostCounters(int likes_count, int comments_count, int reposts_count, boolean likes_selected,
boolean reposts_selected) {
likes = likes_count;
comments = comments_count;
reposts = reposts_count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public Conversation() {

public void getHistory(OvkAPIWrapper ovk, long peer_id) {
this.peer_id = peer_id;
ovk.sendAPIMethod("Messages.getHistory", String.format("peer_id=%s&count=150&rev=1", peer_id));
ovk.sendAPIMethod("Messages.getHistory",
String.format("peer_id=%s&count=150&rev=1", peer_id));
}

@SuppressLint("SimpleDateFormat")
Expand All @@ -63,7 +64,8 @@ public ArrayList<Message> parseHistory(Context ctx, String response) {
type = 0;
}
if(prevItem != null) {
Date startOfDay = new Date(TimeUnit.SECONDS.toMillis(item.getLong("date")));
Date startOfDay = new Date(TimeUnit.SECONDS.toMillis(
item.getLong("date")));
Calendar startOfDay_calendar = Calendar.getInstance();
startOfDay_calendar.setTime(startOfDay);
startOfDay_calendar.set(Calendar.HOUR_OF_DAY, 0);
Expand All @@ -73,7 +75,8 @@ public ArrayList<Message> parseHistory(Context ctx, String response) {
Date prev_startOfDay = null;
Calendar prevStartOfDay_calendar = Calendar.getInstance();
if (i > 1) {
prevStartOfDay_calendar.setTime(new Date(TimeUnit.SECONDS.toMillis(prevItem.getLong("date"))));
prevStartOfDay_calendar.setTime(new Date(TimeUnit.SECONDS.toMillis(
prevItem.getLong("date"))));
prevStartOfDay_calendar.set(Calendar.HOUR_OF_DAY, 0);
prevStartOfDay_calendar.set(Calendar.MINUTE, 0);
prevStartOfDay_calendar.set(Calendar.SECOND, 0);
Expand All @@ -82,17 +85,24 @@ public ArrayList<Message> parseHistory(Context ctx, String response) {
if(prev_startOfDay != null) {
Log.d("compare", String.format("%s", startOfDay.compareTo(prev_startOfDay)));
if (startOfDay.compareTo(prev_startOfDay) > 0) {
history.add(new Message(2, 0, false, false, item.getLong("date"), new SimpleDateFormat("d MMMM yyyy").format(startOfDay), ctx));
history.add(new Message(2, 0, false, false,
item.getLong("date"), new SimpleDateFormat("d MMMM yyyy")
.format(startOfDay), ctx));
}
} else {
history.add(new Message(2, 0, false, false, item.getLong("date"), new SimpleDateFormat("d MMMM yyyy").format(startOfDay), ctx));
history.add(new Message(2, 0, false, false,
item.getLong("date"), new SimpleDateFormat("d MMMM yyyy")
.format(startOfDay), ctx));
}
} else {
history.add(new Message(2, 0, false, false, item.getLong("date"), new SimpleDateFormat("d MMMM yyyy").format(
history.add(new Message(2, 0, false, false,
item.getLong("date"), new SimpleDateFormat("d MMMM yyyy").format(
new Date(TimeUnit.SECONDS.toMillis(item.getLong("date")))), ctx));
}
Message message = new Message(type, item.getLong("id"), incoming, false, item.getLong("date"), item.getString("text"), ctx);
message.timestamp = new SimpleDateFormat("HH:mm").format(TimeUnit.SECONDS.toMillis(item.getLong("date")));
Message message = new Message(type, item.getLong("id"), incoming, false,
item.getLong("date"), item.getString("text"), ctx);
message.timestamp = new SimpleDateFormat("HH:mm").format(TimeUnit.SECONDS.toMillis(
item.getLong("date")));
message.author_id = item.getLong("from_id");
prevItem = item;
history.add(message);
Expand All @@ -105,6 +115,7 @@ public ArrayList<Message> parseHistory(Context ctx, String response) {
}

public void sendMessage(OvkAPIWrapper ovk, String text) {
ovk.sendAPIMethod("Messages.send", String.format("peer_id=%s&message=%s", peer_id, Strings.urlEncode(text)));
ovk.sendAPIMethod("Messages.send", String.format("peer_id=%s&message=%s", peer_id,
Strings.urlEncode(text)));
}
}
Loading

0 comments on commit 814b936

Please sign in to comment.