bug fix
This commit is contained in:
parent
9a7b95408d
commit
37f14a8948
|
@ -30,7 +30,7 @@ public abstract class AsyncExecutor<Parameter, Result> {
|
|||
/**
|
||||
* timeout for queued processes
|
||||
*/
|
||||
private static final long P_TIMEOUT = 10L;
|
||||
private static final long P_TIMEOUT = 4L;
|
||||
|
||||
/**
|
||||
* thread pool executor
|
||||
|
@ -42,15 +42,10 @@ public abstract class AsyncExecutor<Parameter, Result> {
|
|||
*/
|
||||
private Handler uiHandler = new Handler(Looper.getMainLooper());
|
||||
|
||||
/**
|
||||
* callback to activity/fragment
|
||||
*/
|
||||
private WeakReference<AsyncCallback<Result>> callback;
|
||||
|
||||
/**
|
||||
* contains all tasks used by an instance
|
||||
*/
|
||||
private Queue<Future<?>> queue = new LinkedBlockingQueue<>();
|
||||
private Queue<Future<?>> futureTasks = new LinkedBlockingQueue<>();
|
||||
|
||||
/**
|
||||
* start packground task
|
||||
|
@ -59,23 +54,23 @@ public abstract class AsyncExecutor<Parameter, Result> {
|
|||
* @param callback result from the background task
|
||||
*/
|
||||
public final void execute(final Parameter parameter, @Nullable AsyncCallback<Result> callback) {
|
||||
this.callback = new WeakReference<>(callback);
|
||||
final WeakReference<AsyncCallback<Result>> callbackReference = new WeakReference<>(callback);
|
||||
Future<?> future = THREAD_POOL.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Result result = doInBackground(parameter);
|
||||
onPostExecute(result);
|
||||
onPostExecute(result, callbackReference);
|
||||
}
|
||||
});
|
||||
queue.add(future);
|
||||
futureTasks.add(future);
|
||||
}
|
||||
|
||||
/**
|
||||
* send signal to the tasks executed by this instance
|
||||
*/
|
||||
public final void cancel() {
|
||||
while (!queue.isEmpty()) {
|
||||
Future<?> future = queue.remove();
|
||||
while (!futureTasks.isEmpty()) {
|
||||
Future<?> future = futureTasks.remove();
|
||||
future.cancel(true);
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +81,7 @@ public abstract class AsyncExecutor<Parameter, Result> {
|
|||
* @return true if there aren't any tasks
|
||||
*/
|
||||
public final boolean isIdle() {
|
||||
return queue.isEmpty();
|
||||
return futureTasks.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -94,13 +89,13 @@ public abstract class AsyncExecutor<Parameter, Result> {
|
|||
*
|
||||
* @param result result of the background task
|
||||
*/
|
||||
private void onPostExecute(final Result result) {
|
||||
private synchronized void onPostExecute(final Result result, WeakReference<AsyncCallback<Result>> callbackReference) {
|
||||
uiHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!queue.isEmpty())
|
||||
queue.remove();
|
||||
AsyncCallback<Result> reference = callback.get();
|
||||
if (!futureTasks.isEmpty())
|
||||
futureTasks.remove();
|
||||
AsyncCallback<Result> reference = callbackReference.get();
|
||||
if (reference != null && result != null) {
|
||||
reference.onResult(result);
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ public class TextWithEmoji {
|
|||
* @param emojis a map of emoji tags & bitmap. every emoji bitmap has its own tag
|
||||
*/
|
||||
public static Spannable addEmojis(Context context, Spannable spannable, Map<String, Bitmap> emojis) {
|
||||
if (spannable.length() > 0) {
|
||||
if (spannable.length() > 0 && !emojis.isEmpty()) {
|
||||
SpannableStringBuilder builder = new SpannableStringBuilder(spannable);
|
||||
Matcher matcher = EMOJI_PATTERN.matcher(spannable);
|
||||
Stack<Integer> indexes = new Stack<>();
|
||||
|
@ -44,8 +44,10 @@ public class TextWithEmoji {
|
|||
String tag = builder.subSequence(start + 1, end - 1).toString();
|
||||
Bitmap emoji = emojis.get(tag);
|
||||
if (emoji != null) {
|
||||
ImageSpan imgSpan = new ImageSpan(context, emoji);
|
||||
ImageSpan imgSpan = new ImageSpan(context, emoji.copy(Bitmap.Config.ARGB_8888, true));
|
||||
builder.setSpan(imgSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
} else {
|
||||
builder.delete(start, end);
|
||||
}
|
||||
}
|
||||
return builder;
|
||||
|
|
|
@ -777,12 +777,6 @@ public class ProfileActivity extends AppCompatActivity implements ActivityResult
|
|||
} else {
|
||||
user_location.setVisibility(GONE);
|
||||
}
|
||||
if (!user.getDescription().isEmpty()) {
|
||||
description.setVisibility(VISIBLE);
|
||||
description.setText(descriptionSpan);
|
||||
} else {
|
||||
description.setVisibility(GONE);
|
||||
}
|
||||
if (!user.getProfileUrl().isEmpty()) {
|
||||
String link = user.getProfileUrl();
|
||||
if (link.startsWith("http://"))
|
||||
|
|
Loading…
Reference in New Issue