mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 01:28:52 -06:00
Fix view tests
This commit is contained in:
@@ -21,13 +21,10 @@ package org.isoron.uhabits.tasks;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
public class BaseTask extends AsyncTask<Void, Void, Void>
|
||||
{
|
||||
private static CountDownLatch latch;
|
||||
private static int activeTaskCount;
|
||||
|
||||
@Override
|
||||
@@ -40,22 +37,27 @@ public class BaseTask extends AsyncTask<Void, Void, Void>
|
||||
protected void onPreExecute()
|
||||
{
|
||||
activeTaskCount++;
|
||||
latch = new CountDownLatch(activeTaskCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid)
|
||||
{
|
||||
activeTaskCount--;
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
public static void waitForTasks(long timeout, TimeUnit unit)
|
||||
public static void waitForTasks(long timeout)
|
||||
throws TimeoutException, InterruptedException
|
||||
{
|
||||
if(activeTaskCount == 0) return;
|
||||
int poolInterval = 100;
|
||||
|
||||
boolean successful = latch.await(timeout, unit);
|
||||
if(!successful) throw new TimeoutException();
|
||||
while(timeout > 0)
|
||||
{
|
||||
if(activeTaskCount == 0) return;
|
||||
|
||||
timeout -= poolInterval;
|
||||
Thread.sleep(poolInterval);
|
||||
}
|
||||
|
||||
throw new TimeoutException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.helpers.ColorHelper;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
|
||||
public class CheckmarkView extends View
|
||||
public class CheckmarkView extends View implements HabitDataView
|
||||
{
|
||||
private Paint pCard;
|
||||
private Paint pIcon;
|
||||
|
||||
@@ -401,6 +401,7 @@ public class HabitHistoryView extends ScrollableDataView implements HabitDataVie
|
||||
protected void onPostExecute(Void aVoid)
|
||||
{
|
||||
invalidate();
|
||||
super.onPostExecute(null);
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user