fixed all issues with voting
This commit is contained in:
@@ -42,14 +42,15 @@ public final class AdMarkHolder extends BaseNewsEntryHolder<NewsEntry> {
|
||||
drawable = VKThemeHelper.a(R.drawable.marked_as_ads, R.attr.icon_tertiary);
|
||||
int ownerId = post.b();
|
||||
int postId = post.P1();
|
||||
int date = post.K();
|
||||
String text = post.getText();
|
||||
|
||||
if (PostsPreferences.isPostAd(ownerId, postId)) {
|
||||
disclamer = "SponsorPost: Реклама";
|
||||
this.F.setOnClickListener(listener -> voteDialog(ownerId, postId, this.F.getContext()));
|
||||
this.F.setOnClickListener(listener -> voteDialog(ownerId, postId, date, this.F.getContext()));
|
||||
} else if (VotesPreferences.isPostAd(ownerId, postId)) {
|
||||
disclamer = "SponsorPost: Возможно реклама";
|
||||
this.F.setOnClickListener(listener -> voteDialog(ownerId, postId, this.F.getContext()));
|
||||
this.F.setOnClickListener(listener -> voteDialog(ownerId, postId, date, this.F.getContext()));
|
||||
} else if (NewsFeedFiltersUtils.sponsorFilters(text)) {
|
||||
disclamer = "SponsorPost: Заблокировано фильтрами";
|
||||
} else {
|
||||
@@ -71,12 +72,12 @@ public final class AdMarkHolder extends BaseNewsEntryHolder<NewsEntry> {
|
||||
this.F.setText(disclamer);
|
||||
}
|
||||
|
||||
public static void voteDialog(int ownerId, int postId, Context ctx) {
|
||||
public static void voteDialog(int ownerId, int postId, int date, Context ctx) {
|
||||
new VkAlertDialog.Builder(ctx)
|
||||
.setTitle("SponsorPost")
|
||||
.setMessage("Этот пост является рекламным?")
|
||||
.setPositiveButton("Да", ((dialog, which) -> {
|
||||
int resp = VotesService.ratePost(ownerId, postId, true).optInt("code");
|
||||
int resp = VotesService.ratePost(ownerId, postId, date, true).optInt("code");
|
||||
|
||||
if (resp == 201 || resp == 100) {
|
||||
AndroidUtils.sendToast("Спасибо за голос!");
|
||||
@@ -85,7 +86,7 @@ public final class AdMarkHolder extends BaseNewsEntryHolder<NewsEntry> {
|
||||
}
|
||||
}))
|
||||
.setNeutralButton("Нет", ((dialog, which) -> {
|
||||
int resp = VotesService.ratePost(ownerId, postId, false).optInt("code");
|
||||
int resp = VotesService.ratePost(ownerId, postId, date, false).optInt("code");
|
||||
|
||||
if (resp == 201 || resp == 100) {
|
||||
AndroidUtils.sendToast("Спасибо за голос!");
|
||||
|
||||
@@ -26,8 +26,9 @@ public class PostsMenuHook {
|
||||
Post post = (Post) newsEntry;
|
||||
int ownerId = post.b();
|
||||
int postId = post.P1();
|
||||
int date = post.K();
|
||||
|
||||
AdMarkHolder.voteDialog(ownerId, postId, context);
|
||||
AdMarkHolder.voteDialog(ownerId, postId, date, context);
|
||||
} else {
|
||||
Log.d("PostsMenuHook", "unsupported instance");
|
||||
}
|
||||
|
||||
@@ -229,6 +229,20 @@ public class SponsorPostFragment extends TrackedMaterialPreferenceToolbarFragmen
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (Preferences.dev()) {
|
||||
PreferenceFragmentUtils.addPreference(
|
||||
getPreferenceScreen(),
|
||||
"",
|
||||
"Сбросить токен пользователя",
|
||||
null,
|
||||
null,
|
||||
preference -> {
|
||||
VotesPreferences.remUserToken();
|
||||
return false;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -35,6 +35,12 @@ public class VotesPreferences {
|
||||
.apply();
|
||||
}
|
||||
|
||||
public static void remUserToken() {
|
||||
preferences.edit()
|
||||
.remove("token")
|
||||
.apply();
|
||||
}
|
||||
|
||||
public static String getUserToken() {
|
||||
return preferences.getString("token", "");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package ru.vtosters.sponsorpost.internal;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
@@ -117,9 +118,9 @@ public class VotesService {
|
||||
}
|
||||
}
|
||||
|
||||
public static JSONObject ratePost(int ownerId, int postId, boolean isAd) {
|
||||
public static JSONObject ratePost(int ownerId, int postId, int date, boolean isAd) {
|
||||
String token = VotesPreferences.getUserToken() == null || VotesPreferences.getUserToken().isEmpty() ? getVoteToken() : VotesPreferences.getUserToken();
|
||||
String requestUrl = apiPath + (isAd ? "/dislike" : "/like") + "?ownerId=" + ownerId + "&postId=" + postId + "&token=" + token;
|
||||
String requestUrl = apiPath + (isAd ? "/dislike" : "/like") + "?ownerId=" + ownerId + "&postId=" + postId+ "&postDate=" + date + "&token=" + Uri.encode(token);
|
||||
Request request = new Request.a()
|
||||
.b(requestUrl)
|
||||
.a("Content-Type", "application/json")
|
||||
@@ -137,7 +138,7 @@ public class VotesService {
|
||||
}
|
||||
|
||||
public static String getVoteToken() {
|
||||
String requestUrl = userPath + "/getUserToken" + "?private_key=" + Native.pkey();
|
||||
String requestUrl = userPath + "/getUserToken" + "?private_key=" + Uri.encode(Native.pkey());
|
||||
Request request = new Request.a()
|
||||
.b(requestUrl)
|
||||
.a("Content-Type", "application/json")
|
||||
|
||||
Reference in New Issue
Block a user