Skip to content

Commit 2a1d261

Browse files
committed
Build 208: authorization fix and more improvements
1 parent c8f3209 commit 2a1d261

File tree

15 files changed

+128
-85
lines changed

15 files changed

+128
-85
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ android {
9696
//noinspection OldTargetApi
9797
targetSdkVersion 29
9898
versionCode 208
99-
versionName "1.1.207-beta"
99+
versionName "1.1.208-beta"
100100
signingConfig signingConfigs.debug
101101
}
102102
releaseConfig {

app/src/main/java/uk/openvk/android/legacy/Global.java

Lines changed: 35 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package uk.openvk.android.legacy;
22

3-
import android.accounts.Account;
4-
import android.accounts.AccountAuthenticatorResponse;
53
import android.accounts.AccountManager;
64
import android.annotation.SuppressLint;
75
import android.app.Activity;
86
import android.app.AlertDialog;
9-
import android.content.ContentResolver;
107
import android.content.Context;
118
import android.content.DialogInterface;
129
import android.content.Intent;
@@ -16,12 +13,7 @@
1613
import android.content.res.TypedArray;
1714
import android.net.Uri;
1815
import android.os.Build;
19-
import android.os.Bundle;
20-
import android.os.Handler;
21-
import android.os.Message;
22-
import android.os.Parcel;
2316
import android.provider.Settings;
24-
import android.support.annotation.IdRes;
2517
import android.support.annotation.PluralsRes;
2618
import android.support.v7.preference.PreferenceManager;
2719
import android.text.Html;
@@ -34,17 +26,13 @@
3426
import android.view.ViewGroup;
3527
import android.view.Window;
3628
import android.view.WindowManager;
37-
import android.webkit.MimeTypeMap;
3829
import android.widget.Button;
3930
import android.widget.EditText;
40-
import android.widget.ImageButton;
41-
import android.widget.ListView;
4231
import android.widget.Toast;
4332

4433
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
4534

4635
import java.io.File;
47-
import java.io.UnsupportedEncodingException;
4836
import java.lang.reflect.Field;
4937
import java.lang.reflect.Method;
5038
import java.security.MessageDigest;
@@ -54,34 +42,15 @@
5442
import java.util.regex.Pattern;
5543

5644
import uk.openvk.android.legacy.api.OpenVKAPI;
57-
import uk.openvk.android.legacy.api.entities.Group;
5845
import uk.openvk.android.legacy.api.entities.OvkExpandableText;
5946
import uk.openvk.android.legacy.api.entities.OvkLink;
6047
import uk.openvk.android.legacy.api.entities.WallPost;
61-
import uk.openvk.android.legacy.api.enumerations.HandlerMessages;
62-
import uk.openvk.android.legacy.api.wrappers.DownloadManager;
63-
import uk.openvk.android.legacy.api.wrappers.OvkAPIWrapper;
6448
import uk.openvk.android.legacy.ui.OvkAlertDialog;
6549
import uk.openvk.android.legacy.ui.core.activities.AppActivity;
6650
import uk.openvk.android.legacy.ui.core.activities.AuthActivity;
67-
import uk.openvk.android.legacy.ui.core.activities.ConversationActivity;
68-
import uk.openvk.android.legacy.ui.core.activities.DebugMenuActivity;
69-
import uk.openvk.android.legacy.ui.core.activities.GroupMembersActivity;
70-
import uk.openvk.android.legacy.ui.core.activities.MainActivity;
7151
import uk.openvk.android.legacy.ui.core.activities.NewPostActivity;
72-
import uk.openvk.android.legacy.ui.core.activities.QuickSearchActivity;
73-
import uk.openvk.android.legacy.ui.core.activities.WallPostActivity;
74-
import uk.openvk.android.legacy.ui.core.activities.intents.FriendsIntentActivity;
75-
import uk.openvk.android.legacy.ui.core.activities.intents.GroupIntentActivity;
76-
import uk.openvk.android.legacy.ui.core.activities.intents.NotesIntentActivity;
77-
import uk.openvk.android.legacy.ui.core.activities.intents.PhotoAlbumIntentActivity;
78-
import uk.openvk.android.legacy.ui.core.activities.intents.ProfileIntentActivity;
79-
import uk.openvk.android.legacy.ui.core.fragments.app.NewsfeedFragment;
80-
import uk.openvk.android.legacy.ui.core.fragments.app.ProfileFragment;
81-
import uk.openvk.android.legacy.ui.list.adapters.SlidingMenuAdapter;
8252
import uk.openvk.android.legacy.ui.list.items.InstanceAccount;
8353
import uk.openvk.android.legacy.ui.list.items.SlidingMenuItem;
84-
import uk.openvk.android.legacy.ui.view.layouts.WallLayout;
8554

8655
/** Global.java - global methods for application
8756
*
@@ -212,7 +181,8 @@ public static Spanned formatLinksAsHtml(String original_text) {
212181
if(block.startsWith("[") && block.endsWith("]")) {
213182
OvkLink link = new OvkLink();
214183
String[] markup = block.replace("[", "").replace("]", "")
215-
.replace("<", "").replace("\"", "").replace(">", "")
184+
.replace("<", "").replace("\"", "")
185+
.replace(">", "")
216186
.split("\\|");
217187
link.screen_name = markup[0];
218188
if (markup.length == 2) {
@@ -249,7 +219,8 @@ public static OvkExpandableText formatLinksAsHtml(String original_text, int end_
249219
"\\+~#?&//=]{1,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%._\\+~#?&//=]*)");
250220
Matcher matcher = pattern.matcher(original_text);
251221
boolean regexp_search = matcher.find();
252-
String text = original_text.replaceAll("&lt;", "<").replaceAll("&gt;", ">")
222+
String text = original_text.replaceAll("&lt;", "<")
223+
.replaceAll("&gt;", ">")
253224
.replaceAll("&amp;", "&").replaceAll("&quot;", "\"");
254225
text = text.replace("\r\n", "<br>").replace("\n", "<br>");
255226
int regexp_results = 0;
@@ -258,8 +229,10 @@ public static OvkExpandableText formatLinksAsHtml(String original_text, int end_
258229
String block = matcher.group();
259230
if (block.startsWith("[") && block.endsWith("]")) {
260231
OvkLink link = new OvkLink();
261-
String[] markup = block.replace("[", "").replace("]", "")
262-
.replace("<", "").replace(">", "").replace("\"", "")
232+
String[] markup = block.replace("[", "")
233+
.replace("]", "")
234+
.replace("<", "").replace(">", "")
235+
.replace("\"", "")
263236
.split("\\|");
264237
link.screen_name = markup[0];
265238
if (markup.length == 2) {
@@ -272,11 +245,13 @@ public static OvkExpandableText formatLinksAsHtml(String original_text, int end_
272245
}
273246
link.name = markup[1];
274247
if (markup[0].startsWith("id") || markup[0].startsWith("club")) {
275-
text = text.replace(block, String.format("<a href=\"%s\">%s</a>", link.url, link.name));
248+
text = text.replace(block, String.format("<a href=\"%s\">%s</a>",
249+
link.url, link.name));
276250
}
277251
}
278252
} else if (block.startsWith("https://") || block.startsWith("http://")) {
279-
text = text.replace(block, String.format("<a href=\"%s\">%s</a>", block, block));
253+
text = text.replace(block, String.format("<a href=\"%s\">%s</a>",
254+
block, block));
280255
}
281256
}
282257
regexp_results = regexp_results + 1;
@@ -286,7 +261,8 @@ public static OvkExpandableText formatLinksAsHtml(String original_text, int end_
286261
Spanned html;
287262
if(text.length() >= end_number) {
288263
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
289-
html = Html.fromHtml(text.substring(0, end_number - 1) + "...", Html.FROM_HTML_MODE_COMPACT);
264+
html = Html.fromHtml(text.substring(0, end_number - 1) + "...",
265+
Html.FROM_HTML_MODE_COMPACT);
290266
} else {
291267
html = Html.fromHtml(text.substring(0, end_number - 1) + "...");
292268
}
@@ -314,7 +290,9 @@ public static void fixWindowPadding(View view, Resources.Theme theme) {
314290
public static void fixWindowPadding(Window window, Resources.Theme theme) {
315291
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
316292
View view = window.getDecorView();
317-
int actionBarId = view.getContext().getResources().getIdentifier("action_bar", "id", "android");
293+
int actionBarId =
294+
view.getContext().getResources()
295+
.getIdentifier("action_bar", "id", "android");
318296
ViewGroup actionBarView = (ViewGroup) view.findViewById(actionBarId);
319297
Resources res = view.getContext().getResources();
320298
try {
@@ -568,9 +546,12 @@ public void onClick(DialogInterface dialog, int which) {
568546
new DialogInterface.OnClickListener() {
569547
@Override
570548
public void onClick(DialogInterface dialog, int which) {
571-
SharedPreferences.Editor editor = finalGlobal_prefs.edit();
572-
editor.putString("current_instance", accountArray.get(selectedPosition[0]).instance);
573-
editor.putLong("current_uid", accountArray.get(selectedPosition[0]).id);
549+
SharedPreferences.Editor editor =
550+
finalGlobal_prefs.edit();
551+
editor.putString("current_instance",
552+
accountArray.get(selectedPosition[0]).instance);
553+
editor.putLong("current_uid",
554+
accountArray.get(selectedPosition[0]).id);
574555
editor.commit();
575556
dialog.dismiss();
576557
if(ctx instanceof Activity) {
@@ -664,13 +645,16 @@ public void onClick(DialogInterface dialog, int which) {
664645
OvkAlertDialog dialog = new OvkAlertDialog(ctx);
665646
dialog.build(builder, ctx.getResources().getString(R.string.sett_account), "", null, "listDlg");
666647
final SharedPreferences finalGlobal_prefs = global_prefs;
667-
dialog.setButton(DialogInterface.BUTTON_POSITIVE, ctx.getResources().getString(android.R.string.ok),
648+
dialog.setButton(DialogInterface.BUTTON_POSITIVE,
649+
ctx.getResources().getString(android.R.string.ok),
668650
new DialogInterface.OnClickListener() {
669651
@Override
670652
public void onClick(DialogInterface dialog, int which) {
671653
SharedPreferences.Editor editor = finalGlobal_prefs.edit();
672-
editor.putString("current_instance", accountArray.get(selectedPosition[0]).instance);
673-
editor.putLong("current_uid", accountArray.get(selectedPosition[0]).id);
654+
editor.putString("current_instance",
655+
accountArray.get(selectedPosition[0]).instance);
656+
editor.putLong("current_uid",
657+
accountArray.get(selectedPosition[0]).id);
674658
editor.commit();
675659
dialog.dismiss();
676660
if (ctx instanceof Activity) {
@@ -793,10 +777,12 @@ public void onClick(DialogInterface dialogInterface, int i) {
793777
dialog.show();
794778
}
795779

796-
public static void openRepostDialog(Context ctx, final OpenVKAPI ovk_api, String where, final WallPost post) {
780+
public static void openRepostDialog(Context ctx,
781+
final OpenVKAPI ovk_api, String where, final WallPost post) {
797782
if(where.equals("own_wall")) {
798783
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
799-
final View repost_view = ((Activity)ctx).getLayoutInflater().inflate(R.layout.dialog_repost_msg,
784+
final View repost_view =
785+
((Activity)ctx).getLayoutInflater().inflate(R.layout.dialog_repost_msg,
800786
null, false);
801787
final EditText text_edit = ((EditText) repost_view.findViewById(R.id.text_edit));
802788
builder.setView(repost_view);
@@ -817,7 +803,8 @@ public void onClick(View view) {
817803
String msg_text = ((EditText)
818804
repost_view.findViewById(R.id.text_edit)).getText()
819805
.toString();
820-
ovk_api.wall.repost(ovk_api.wrapper, post.owner_id, post.post_id, msg_text);
806+
ovk_api.wall.repost
807+
(ovk_api.wrapper, post.owner_id, post.post_id, msg_text);
821808
dialog.close();
822809
} catch (Exception ex) {
823810
ex.printStackTrace();

app/src/main/java/uk/openvk/android/legacy/api/enumerations/HandlerMessages.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,15 @@ public class HandlerMessages {
123123
public static int COMMENT_AVATARS = 2009;
124124
public static int COMMENT_PHOTOS = 2010;
125125
public static int COMMENT_VIDEO_THUMBNAILS = 2011;
126-
public static int PHOTO_ALBUM_THUMBNAILS = 2012;
127-
public static int CONVERSATIONS_AVATARS = 2013;
128-
public static int LONGPOLL = 2014;
129-
public static int ORIGINAL_PHOTO = 2015;
130-
public static int VIDEO_THUMBNAILS = 2016;
131-
public static int PARSE_JSON = 2017;
132-
public static int UPLOAD_PROGRESS = 2018;
133-
public static int UPLOADED_SUCCESSFULLY = 2019;
126+
public static int ALBUM_PHOTOS = 2012;
127+
public static int PHOTO_ALBUM_THUMBNAILS = 2013;
128+
public static int CONVERSATIONS_AVATARS = 2014;
129+
public static int LONGPOLL = 2015;
130+
public static int ORIGINAL_PHOTO = 2016;
131+
public static int VIDEO_THUMBNAILS = 2017;
132+
public static int PARSE_JSON = 2018;
133+
public static int UPLOAD_PROGRESS = 2019;
134+
public static int UPLOADED_SUCCESSFULLY = 2020;
134135

135136
// Errors
136137
public static int NO_INTERNET_CONNECTION = -1;

app/src/main/java/uk/openvk/android/legacy/api/models/Newsfeed.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ public ArrayList<Attachment> createAttachmentsList(long owner_id, long post_id,
289289
String photo_original_size;
290290
String attachment_status;
291291
JSONObject attachment = attachments.getJSONObject(attachments_index);
292+
if(attachment.isNull("type")) {
293+
continue;
294+
}
292295
if (attachment.getString("type").equals("photo")) {
293296
JSONObject photo = attachment.getJSONObject("photo");
294297
PhotoAttachment photoAttachment = new PhotoAttachment();

app/src/main/java/uk/openvk/android/legacy/api/models/Photos.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public void parse(String response, PhotoAlbum album, DownloadManager dlman) {
102102
JSONObject json = jsonParser.parseJSON(response);
103103
album.size = json.getJSONObject("response").getInt("count");
104104
JSONArray photos = json.getJSONObject("response").getJSONArray("items");
105+
ArrayList<PhotoAttachment> photoAttachs = new ArrayList<>();
105106
for(int i = 0; i < photos.length(); i++) {
106107
JSONObject item = photos.getJSONObject(i);
107108
Photo photo = new Photo();
@@ -117,33 +118,30 @@ public void parse(String response, PhotoAlbum album, DownloadManager dlman) {
117118
}
118119
photo.owner_id = item.getLong("owner_id");
119120
if(dlman != null && item.has("sizes")) {
121+
PhotoAttachment attach = new PhotoAttachment();
120122
if(item.getJSONObject("sizes").has("q")) {
121123
photo.url = item.getJSONObject("sizes").getJSONObject("q").getString("url");
122-
dlman.downloadOnePhotoToCache(
123-
photo.url,
124-
String.format(
125-
"photo%s_a%s_o%s",
126-
photo.id,
127-
photo.album_id,
128-
photo.owner_id),
129-
"album_photos");
124+
attach.url = photo.url;
125+
attach.filename = String.format(
126+
"photo%s_a%s_o%s",
127+
photo.id,
128+
photo.album_id,
129+
photo.owner_id);
130+
130131
}
131132
if(item.getJSONObject("sizes").has("UPLOADED_MAXRES")) {
132133
photo.original_url =
133134
item.getJSONObject("sizes")
134135
.getJSONObject("UPLOADED_MAXRES").getString("url");
135-
dlman.downloadOnePhotoToCache(
136-
photo.url,
137-
String.format(
138-
"photo%s_a%s_o%s",
139-
photo.id,
140-
photo.album_id,
141-
photo.owner_id),
142-
"original_photos");
136+
attach.original_url = photo.original_url;
143137
}
138+
photoAttachs.add(attach);
144139
}
145140
album.photos.add(photo);
146141
}
142+
if(dlman != null) {
143+
dlman.downloadPhotosToCache(photoAttachs, "album_photos");
144+
}
147145
} catch (Exception ex) {
148146
ex.printStackTrace();
149147
}

app/src/main/java/uk/openvk/android/legacy/api/wrappers/DownloadManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,9 @@ public void run() {
380380
case "comment_photos":
381381
sendMessage(HandlerMessages.COMMENT_PHOTOS, where);
382382
break;
383+
case "album_photos":
384+
sendMessage(HandlerMessages.ALBUM_PHOTOS, where);
385+
break;
383386
case "conversations_avatars":
384387
sendMessage(HandlerMessages.CONVERSATIONS_AVATARS, where);
385388
break;
@@ -559,6 +562,9 @@ public void run() {
559562
case "comment_photos":
560563
sendMessage(HandlerMessages.COMMENT_PHOTOS, where);
561564
break;
565+
case "album_photos":
566+
sendMessage(HandlerMessages.ALBUM_PHOTOS, where);
567+
break;
562568
case "video_thumbnails":
563569
sendMessage(HandlerMessages.VIDEO_THUMBNAILS, where);
564570
break;

app/src/main/java/uk/openvk/android/legacy/receivers/OvkAPIReceiver.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ public Message parseJSONData(OvkAPIWrapper wrapper, Handler handler, Bundle data
111111
.getApplicationContext()).getCurrentInstance());
112112
if (activity instanceof AuthActivity) {
113113
AuthActivity auth_a = (AuthActivity) activity;
114-
downloadManager = auth_a.ovk_api.dlman;
115114
assert method != null;
116115
switch (method) {
117116
case "Account.getProfileInfo":

0 commit comments

Comments
 (0)