mirror of https://github.com/M66B/FairEmail.git
Show hourglass when busy
This commit is contained in:
parent
ed29b6e29b
commit
9382b98a63
|
@ -21,9 +21,11 @@ package eu.faircode.email;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
@ -59,6 +61,7 @@ import android.widget.ArrayAdapter;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
|
import android.widget.ImageView;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
@ -120,6 +123,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
||||||
private ImageButton ibHintSwipe;
|
private ImageButton ibHintSwipe;
|
||||||
private ImageButton ibHintSelect;
|
private ImageButton ibHintSelect;
|
||||||
private TextView tvNoEmail;
|
private TextView tvNoEmail;
|
||||||
|
private ImageView ivBusy;
|
||||||
private FixedRecyclerView rvMessage;
|
private FixedRecyclerView rvMessage;
|
||||||
private SeekBar seekBar;
|
private SeekBar seekBar;
|
||||||
private ImageButton ibDown;
|
private ImageButton ibDown;
|
||||||
|
@ -168,6 +172,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
||||||
private boolean manual = false;
|
private boolean manual = false;
|
||||||
private Integer lastUnseen = null;
|
private Integer lastUnseen = null;
|
||||||
private boolean swiping = false;
|
private boolean swiping = false;
|
||||||
|
private int busy = 0;
|
||||||
|
|
||||||
private AdapterMessage adapter;
|
private AdapterMessage adapter;
|
||||||
|
|
||||||
|
@ -265,6 +270,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
||||||
ibHintSwipe = view.findViewById(R.id.ibHintSwipe);
|
ibHintSwipe = view.findViewById(R.id.ibHintSwipe);
|
||||||
ibHintSelect = view.findViewById(R.id.ibHintSelect);
|
ibHintSelect = view.findViewById(R.id.ibHintSelect);
|
||||||
tvNoEmail = view.findViewById(R.id.tvNoEmail);
|
tvNoEmail = view.findViewById(R.id.tvNoEmail);
|
||||||
|
ivBusy = view.findViewById(R.id.ivBusy);
|
||||||
rvMessage = view.findViewById(R.id.rvMessage);
|
rvMessage = view.findViewById(R.id.rvMessage);
|
||||||
seekBar = view.findViewById(R.id.seekBar);
|
seekBar = view.findViewById(R.id.seekBar);
|
||||||
ibDown = view.findViewById(R.id.ibDown);
|
ibDown = view.findViewById(R.id.ibDown);
|
||||||
|
@ -749,9 +755,40 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
||||||
|
|
||||||
updateSwipeRefresh();
|
updateSwipeRefresh();
|
||||||
|
|
||||||
|
ivBusy.setVisibility(View.GONE);
|
||||||
|
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
|
||||||
|
IntentFilter iff = new IntentFilter();
|
||||||
|
iff.addAction(SimpleTask.ACTION_TASK_COUNT);
|
||||||
|
lbm.registerReceiver(receiver, iff);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
|
||||||
|
lbm.unregisterReceiver(receiver);
|
||||||
|
|
||||||
|
super.onDestroyView();
|
||||||
|
}
|
||||||
|
|
||||||
|
private BroadcastReceiver receiver = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
busy = intent.getIntExtra("count", 0);
|
||||||
|
if (busy == 0)
|
||||||
|
ivBusy.setVisibility(View.GONE);
|
||||||
|
else
|
||||||
|
new Handler().postDelayed(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (busy > 0)
|
||||||
|
ivBusy.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}, 1500);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
|
|
@ -20,6 +20,7 @@ package eu.faircode.email;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
|
||||||
|
@ -31,6 +32,7 @@ import androidx.lifecycle.LifecycleObserver;
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
import androidx.lifecycle.LifecycleService;
|
import androidx.lifecycle.LifecycleService;
|
||||||
import androidx.lifecycle.OnLifecycleEvent;
|
import androidx.lifecycle.OnLifecycleEvent;
|
||||||
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -47,6 +49,8 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||||
private static final ExecutorService executor = Executors.newFixedThreadPool(
|
private static final ExecutorService executor = Executors.newFixedThreadPool(
|
||||||
Runtime.getRuntime().availableProcessors(), Helper.backgroundThreadFactory);
|
Runtime.getRuntime().availableProcessors(), Helper.backgroundThreadFactory);
|
||||||
|
|
||||||
|
static final String ACTION_TASK_COUNT = BuildConfig.APPLICATION_ID + ".ACTION_TASK_COUNT";
|
||||||
|
|
||||||
public void execute(Context context, LifecycleOwner owner, @NonNull Bundle args, @NonNull String name) {
|
public void execute(Context context, LifecycleOwner owner, @NonNull Bundle args, @NonNull String name) {
|
||||||
run(context, owner, args, name);
|
run(context, owner, args, name);
|
||||||
}
|
}
|
||||||
|
@ -71,10 +75,15 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||||
final Handler handler = new Handler();
|
final Handler handler = new Handler();
|
||||||
|
|
||||||
// prevent garbage collection
|
// prevent garbage collection
|
||||||
|
int count;
|
||||||
synchronized (tasks) {
|
synchronized (tasks) {
|
||||||
tasks.add(this);
|
tasks.add(this);
|
||||||
|
count = tasks.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
||||||
|
lbm.sendBroadcast(new Intent(ACTION_TASK_COUNT).putExtra("count", count));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
onPreExecute(args);
|
onPreExecute(args);
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
|
@ -104,12 +113,12 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||||
Lifecycle.State state = owner.getLifecycle().getCurrentState();
|
Lifecycle.State state = owner.getLifecycle().getCurrentState();
|
||||||
if (state.equals(Lifecycle.State.DESTROYED)) {
|
if (state.equals(Lifecycle.State.DESTROYED)) {
|
||||||
// No delivery
|
// No delivery
|
||||||
cleanup();
|
cleanup(context);
|
||||||
} else if (state.isAtLeast(Lifecycle.State.RESUMED)) {
|
} else if (state.isAtLeast(Lifecycle.State.RESUMED)) {
|
||||||
// Inline delivery
|
// Inline delivery
|
||||||
Log.i("Deliver task " + name);
|
Log.i("Deliver task " + name);
|
||||||
deliver();
|
deliver();
|
||||||
cleanup();
|
cleanup(context);
|
||||||
} else
|
} else
|
||||||
owner.getLifecycle().addObserver(new LifecycleObserver() {
|
owner.getLifecycle().addObserver(new LifecycleObserver() {
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||||
|
@ -118,7 +127,7 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||||
Log.i("Resume task " + name);
|
Log.i("Resume task " + name);
|
||||||
owner.getLifecycle().removeObserver(this);
|
owner.getLifecycle().removeObserver(this);
|
||||||
deliver();
|
deliver();
|
||||||
cleanup();
|
cleanup(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
||||||
|
@ -126,7 +135,7 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||||
// No delivery
|
// No delivery
|
||||||
Log.i("Destroy task " + name);
|
Log.i("Destroy task " + name);
|
||||||
owner.getLifecycle().removeObserver(this);
|
owner.getLifecycle().removeObserver(this);
|
||||||
cleanup();
|
cleanup(context);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -154,11 +163,16 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cleanup() {
|
private void cleanup(Context context) {
|
||||||
|
int count;
|
||||||
synchronized (tasks) {
|
synchronized (tasks) {
|
||||||
tasks.remove(this);
|
tasks.remove(this);
|
||||||
Log.i("Remaining tasks=" + tasks.size());
|
count = tasks.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
||||||
|
lbm.sendBroadcast(new Intent(ACTION_TASK_COUNT).putExtra("count", count));
|
||||||
|
Log.i("Remaining tasks=" + count);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onPreExecute(Bundle args) {
|
protected void onPreExecute(Bundle args) {
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24.0"
|
||||||
|
android:viewportHeight="24.0"
|
||||||
|
android:tint="?attr/colorControlNormal">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M6,2v6h0.01L6,8.01 10,12l-4,4 0.01,0.01H6V22h12v-5.99h-0.01L18,16l-4,-4 4,-3.99 -0.01,-0.01H18V2H6z"/>
|
||||||
|
</vector>
|
|
@ -143,6 +143,16 @@
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/vSeparatorHintSelect" />
|
app:layout_constraintTop_toBottomOf="@id/vSeparatorHintSelect" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/ivBusy"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:src="@drawable/baseline_hourglass_full_24"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/seekBar"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/vSeparatorHintSelect" />
|
||||||
|
|
||||||
<eu.faircode.email.FixedRecyclerView
|
<eu.faircode.email.FixedRecyclerView
|
||||||
android:id="@+id/rvMessage"
|
android:id="@+id/rvMessage"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
|
|
Loading…
Reference in New Issue