Created
October 14, 2018 20:20
-
-
Save ermolnik/397e43701c9ec9b60d2fbaa3cfa1c571 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by ermolnik on 21.11.16. | |
*/ | |
public class Wall { | |
public static Thread wallDeketeThread; | |
static ArrayList<Integer> postList; | |
public static void PostsDelete(){ | |
AntiSpamVK.isStop = false; | |
AntiSpamVK.adsShow = false; | |
postList = new ArrayList<>(); | |
final BlockingQueue queue = new LinkedBlockingQueue(1); | |
wallDeketeThread = new Thread(){ | |
private void waitResult() { | |
boolean done = false; | |
while (!done) { | |
try { | |
queue.take(); | |
done = true; | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
long start = System.nanoTime(); | |
while (((System.nanoTime() - start) / 1000000L) < 334L) { | |
try { | |
sleep(AntiSpamVK.scanTime - ((System.nanoTime() - start) / 1000000L)); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
public void run(){ | |
AntiSpamVK.isDone = false; | |
for (int i = 0; i < 10000; i=i+100) { | |
if (AntiSpamVK.isStop == true){ | |
break; | |
} | |
AntiSpamVK.postProgress = ((i*50)/10000); | |
final VKRequest request = VKApi.wall().get(VKParameters.from( | |
VKApiConst.COUNT, 100, | |
VKApiConst.OFFSET, i | |
)); | |
request.executeWithListener(new VKRequest.VKRequestListener() { | |
@Override | |
public void onComplete(VKResponse response) { | |
super.onComplete(response); | |
JSONArray arrayPost; | |
try { | |
arrayPost = response.json.getJSONObject("response").getJSONArray("items"); | |
for (int j = 0; j < arrayPost.length(); j++) { | |
JSONObject arr = arrayPost.getJSONObject(j); | |
postList.add(arr.getInt("id")); | |
} | |
} catch (JSONException e) { | |
e.printStackTrace(); | |
} | |
Toast toast = Toast.makeText(getApplicationContext(), | |
"Подготовка к удалению", Toast.LENGTH_SHORT); | |
toast.show(); | |
queue.add(1); | |
} | |
@Override | |
public void onError(VKError error) { | |
super.onError(error); | |
Toast toast = Toast.makeText(getApplicationContext(), | |
error.toString(), Toast.LENGTH_SHORT); | |
toast.show(); | |
queue.add(1); | |
} | |
}); | |
waitResult(); | |
} | |
for (int i = 0; i < postList.size(); i++) { | |
if (AntiSpamVK.isStop == true){ | |
break; | |
} | |
AntiSpamVK.postProgress = 50 + (i*50/postList.size()); | |
VKRequest request = VKApi.wall().delete(VKParameters.from( | |
VKApiConst.POST_ID, postList.get(i) | |
)); | |
request.executeWithListener(new VKRequest.VKRequestListener() { | |
@Override | |
public void onComplete(VKResponse response) { | |
super.onComplete(response); | |
Toast toast = Toast.makeText(getApplicationContext(), | |
"удаление записей", Toast.LENGTH_SHORT); | |
toast.show(); | |
queue.add(1); | |
} | |
@Override | |
public void onError(VKError error) { | |
super.onError(error); | |
Toast toast = Toast.makeText(getApplicationContext(), | |
error.toString(), Toast.LENGTH_SHORT); | |
toast.show(); | |
AntiSpamVK.isStop = true; | |
queue.add(1); | |
} | |
}); | |
waitResult(); | |
} | |
AntiSpamVK.isDone = true; | |
AntiSpamVK.postProgress = 0; | |
AntiSpamVK.adsShow = true; | |
} | |
}; | |
wallDeketeThread.start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment