getInfo -> execute + VKMeHandler codebase
This commit is contained in:
@@ -53,14 +53,12 @@ public class ContactsUtils{
|
||||
}
|
||||
|
||||
public static void getContactsStatus(Context ctx){
|
||||
var enabledsync = false;
|
||||
|
||||
final ProgressDialog progressDialog = new ProgressDialog(ctx);
|
||||
progressDialog.setMessage("Загрузка данных о контактах...");
|
||||
progressDialog.show();
|
||||
|
||||
var request = new okhttp3.Request.a()
|
||||
.b("https://" + getApi() + "/method/account.getInfo?&https=1&v=5.153&access_token=" + getUserToken())
|
||||
.b("https://" + getApi() + "/method/execute?https=1&v=5.153&code=return%20API.account.getInfo().settings%5B44%5D.value%3B&access_token=" + getUserToken())
|
||||
.a(Headers.a("User-Agent", Network.l.c().a(), "Content-Type", "application/x-www-form-urlencoded; charset=utf-8"))
|
||||
.a();
|
||||
|
||||
@@ -69,28 +67,18 @@ public class ContactsUtils{
|
||||
progressDialog.cancel();
|
||||
|
||||
try {
|
||||
JSONObject mainJson = new JSONObject(response).optJSONObject("response");
|
||||
JSONArray settings = mainJson != null ? mainJson.optJSONArray("settings") : null;
|
||||
String resp = new JSONObject(response).optString("response");
|
||||
|
||||
for (int i = 0; i < (settings != null ? settings.length() : 0); i++) {
|
||||
JSONObject obj = settings.optJSONObject(i);
|
||||
String name = obj.optString("name");
|
||||
String value = obj.optString("value");
|
||||
Log.d("ContactsUtils", new JSONObject(response).toString());
|
||||
|
||||
if (name.contains("im_user_name_type") && value.equals("contact")) {
|
||||
enabledsync = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
boolean finalEnabledsync = !enabledsync;
|
||||
boolean enabledsync = resp.equals("contact");
|
||||
|
||||
VkAlertDialog.Builder builder = new VkAlertDialog.Builder(ctx);
|
||||
builder.setTitle("Синхронизация контактов");
|
||||
builder.setMessage("Статус синхронизации: " + (enabledsync ? "Включена" : "Отключена"));
|
||||
builder.setCancelable(true);
|
||||
builder.setPositiveButton((finalEnabledsync ? "Включить" : "Отключить"), (dialog, which) -> {
|
||||
setContactsSync(finalEnabledsync);
|
||||
builder.setPositiveButton((!enabledsync ? "Включить" : "Отключить"), (dialog, which) -> {
|
||||
setContactsSync(!enabledsync);
|
||||
});
|
||||
builder.setNegativeButton("Импортировать контакты", (dialog, which) -> {
|
||||
uploadContacts();
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package ru.vtosters.lite.utils;
|
||||
import static ru.vtosters.lite.net.Request.makeRequest;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.getOauth;
|
||||
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserToken;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.edit;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getPrefsValue;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.sendToast;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class VKMeHandler{
|
||||
public static void getVkMeToken(String username, String password){
|
||||
makeRequest("https://" +
|
||||
getOauth() +
|
||||
"/token?" +
|
||||
"grant_type=password&client_id=6146827&client_secret=qVxWRF1CwHERuIrKBnqe&username=" +
|
||||
username +
|
||||
"&password=" +
|
||||
password +
|
||||
"&v=5.131&2fa_supported=1",
|
||||
response -> {
|
||||
try {
|
||||
JSONObject mainJson = new JSONObject(response);
|
||||
|
||||
if (mainJson.has("redirect_uri")){
|
||||
String redirect_uri = mainJson.getString("redirect_uri");
|
||||
// TODO open redirect_uri and get token
|
||||
} else if (mainJson.has("access_token")){
|
||||
setToken(mainJson.getString("access_token"));
|
||||
} else if (mainJson.has("error_description")){
|
||||
Log.d("VKMeHandler", mainJson.getString("error_description"));
|
||||
sendToast("Ошибка входа: " + mainJson.getString("error_description"));
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
Log.d("VKMeHandler", e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void setToken(String token){
|
||||
edit().putString("vkmetoken", token).commit();
|
||||
}
|
||||
|
||||
public static void removeToken(){
|
||||
edit().remove("vkmetoken").commit();
|
||||
}
|
||||
|
||||
public static String getToken(){
|
||||
return getPrefsValue("vkmetoken");
|
||||
}
|
||||
|
||||
public static void setPrivacyStatus(String status){
|
||||
// all, friends_and_contacts, only_me
|
||||
makeRequest("https://" + getApi() + "/method/account.setPrivacy?" + "v=5.140&key=online&value=" + status + "&https=1&access_token=" + getToken(),
|
||||
response -> {
|
||||
try {
|
||||
JSONObject mainJson = new JSONObject(response);
|
||||
} catch (JSONException e) {
|
||||
Log.d("VKMeHandler", e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void getPrivacyStatus(){
|
||||
makeRequest("https://" + getApi() + "/method/execute?v=5.140&code=return API.account.getPrivacySettings().settings[22].value.category;&access_token=" + getToken(),
|
||||
response -> {
|
||||
try {
|
||||
String resp = new JSONObject(response).optString("response");
|
||||
|
||||
switch (resp){ // TODO make support for privacy
|
||||
case "all":
|
||||
case "friends_and_contacts":
|
||||
case "friends":
|
||||
case "only_me":
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
Log.d("VKMeHandler", e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user