mirror of https://github.com/M66B/FairEmail.git
Reset pull down to refresh on no connectivity
This commit is contained in:
parent
9576f34b3c
commit
0ee61448a8
|
@ -251,21 +251,24 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
|||
args.putLong("account", folder.account == null ? -1 : folder.account);
|
||||
args.putLong("folder", folder.id);
|
||||
|
||||
new SimpleTask<EntityAccount>() {
|
||||
new SimpleTask<Boolean>() {
|
||||
@Override
|
||||
protected EntityAccount onLoad(Context context, Bundle args) {
|
||||
long account = args.getLong("account");
|
||||
long folder = args.getLong("folder");
|
||||
protected Boolean onLoad(Context context, Bundle args) {
|
||||
long aid = args.getLong("account");
|
||||
long fid = args.getLong("folder");
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
EntityOperation.sync(db, folder);
|
||||
EntityOperation.sync(db, fid);
|
||||
|
||||
return (account < 0 ? null : db.account().getAccount(account));
|
||||
if (aid < 0) // outbox
|
||||
return "connected".equals(db.folder().getFolder(fid).state);
|
||||
else
|
||||
return "connected".equals(db.account().getAccount(aid).state);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLoaded(Bundle args, EntityAccount account) {
|
||||
if (account != null && !"connected".equals(account.state))
|
||||
protected void onLoaded(Bundle args, Boolean connected) {
|
||||
if (!connected)
|
||||
Snackbar.make(itemView, R.string.title_sync_queued, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ public interface DaoFolder {
|
|||
" AND type = '" + EntityFolder.USER + "'")
|
||||
List<EntityFolder> getUserFolders(long account);
|
||||
|
||||
@Query("SELECT folder.*, account.name AS accountName, account.color AS accountColor" +
|
||||
@Query("SELECT folder.*, account.name AS accountName, account.color AS accountColor, account.state AS accountState" +
|
||||
", COUNT(message.id) AS messages" +
|
||||
", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" +
|
||||
", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" +
|
||||
|
@ -66,7 +66,7 @@ public interface DaoFolder {
|
|||
" AND type <> '" + EntityFolder.USER + "'")
|
||||
LiveData<List<EntityFolder>> liveSystemFolders(long account);
|
||||
|
||||
@Query("SELECT folder.*, account.name AS accountName, account.color AS accountColor" +
|
||||
@Query("SELECT folder.*, account.name AS accountName, account.color AS accountColor, account.state AS accountState" +
|
||||
", COUNT(message.id) AS messages" +
|
||||
", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" +
|
||||
", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" +
|
||||
|
@ -84,7 +84,7 @@ public interface DaoFolder {
|
|||
" AND (account.id = :account OR (:account IS NULL AND account.`primary`))")
|
||||
LiveData<EntityFolder> liveDrafts(Long account);
|
||||
|
||||
@Query("SELECT folder.*, account.name AS accountName, account.color AS accountColor" +
|
||||
@Query("SELECT folder.*, account.name AS accountName, account.color AS accountColor, account.state AS accountState" +
|
||||
", COUNT(message.id) AS messages" +
|
||||
", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" +
|
||||
", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" +
|
||||
|
|
|
@ -43,6 +43,7 @@ import android.widget.TextView;
|
|||
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -195,28 +196,51 @@ public class FragmentMessages extends FragmentEx {
|
|||
args.putLong("account", account);
|
||||
args.putLong("folder", folder);
|
||||
|
||||
new SimpleTask<Void>() {
|
||||
new SimpleTask<Boolean>() {
|
||||
@Override
|
||||
protected Void onLoad(Context context, Bundle args) {
|
||||
long account = args.getLong("account");
|
||||
long folder = args.getLong("folder");
|
||||
protected Boolean onLoad(Context context, Bundle args) {
|
||||
long aid = args.getLong("account");
|
||||
long fid = args.getLong("folder");
|
||||
|
||||
boolean connected = false;
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
try {
|
||||
db.beginTransaction();
|
||||
|
||||
if (account < 0) {
|
||||
for (EntityFolder unified : db.folder().getUnifiedFolders())
|
||||
EntityOperation.sync(db, unified.id);
|
||||
} else
|
||||
EntityOperation.sync(db, folder);
|
||||
List<EntityFolder> folders = new ArrayList<>();
|
||||
if (aid < 0)
|
||||
folders.addAll(db.folder().getUnifiedFolders());
|
||||
else
|
||||
folders.add(db.folder().getFolder(fid));
|
||||
|
||||
for (EntityFolder folder : folders) {
|
||||
EntityOperation.sync(db, folder.id);
|
||||
|
||||
if (folder.account == null) { // outbox
|
||||
if ("connected".equals(folder.state))
|
||||
connected = true;
|
||||
} else {
|
||||
EntityAccount account = db.account().getAccount(folder.account);
|
||||
if ("connected".equals(account.state))
|
||||
connected = true;
|
||||
}
|
||||
}
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
|
||||
return null;
|
||||
return connected;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLoaded(Bundle args, Boolean connected) {
|
||||
if (!connected) {
|
||||
swipeRefresh.setRefreshing(false);
|
||||
Snackbar.make(view, R.string.title_sync_queued, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}.load(FragmentMessages.this, args);
|
||||
}
|
||||
|
@ -1191,10 +1215,11 @@ public class FragmentMessages extends FragmentEx {
|
|||
|
||||
boolean refreshing = false;
|
||||
for (TupleFolderEx folder : folders)
|
||||
if (folder.sync_state != null) {
|
||||
if (folder.sync_state != null && "connected".equals(folder.accountState)) {
|
||||
refreshing = true;
|
||||
break;
|
||||
}
|
||||
|
||||
swipeRefresh.setRefreshing(refreshing);
|
||||
}
|
||||
});
|
||||
|
@ -1217,7 +1242,10 @@ public class FragmentMessages extends FragmentEx {
|
|||
getActivity().invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
swipeRefresh.setRefreshing(folder != null && folder.sync_state != null);
|
||||
swipeRefresh.setRefreshing(
|
||||
folder != null && folder.sync_state != null &&
|
||||
"connected".equals(EntityFolder.OUTBOX.equals(folder.type)
|
||||
? folder.state : folder.accountState));
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
|
|
@ -22,6 +22,7 @@ package eu.faircode.email;
|
|||
public class TupleFolderEx extends EntityFolder {
|
||||
public String accountName;
|
||||
public Integer accountColor;
|
||||
public String accountState;
|
||||
public int messages;
|
||||
public int content;
|
||||
public int unseen;
|
||||
|
@ -33,6 +34,7 @@ public class TupleFolderEx extends EntityFolder {
|
|||
return (super.equals(obj) &&
|
||||
(this.accountName == null ? other.accountName == null : accountName.equals(other.accountName)) &&
|
||||
(this.accountColor == null ? other.accountColor == null : this.accountColor.equals(other.accountColor)) &&
|
||||
(this.accountState == null ? other.accountState == null : accountState.equals(other.accountState)) &&
|
||||
this.messages == other.messages &&
|
||||
this.content == other.content &&
|
||||
this.unseen == other.unseen);
|
||||
|
|
|
@ -1,91 +1,97 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ActivityView">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvHintActions"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="6dp"
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_marginEnd="6dp"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="33dp"
|
||||
android:text="@string/title_hint_folder_actions"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
app:layout_constraintEnd_toStartOf="@+id/ibHintActions"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/ibHintActions"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/baseline_close_24"
|
||||
app:layout_constraintBottom_toBottomOf="@id/tvHintActions"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/tvHintActions" />
|
||||
|
||||
<View
|
||||
android:id="@+id/vSeparator"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginTop="6dp"
|
||||
android:background="?attr/colorSeparator"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvHintActions" />
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ActivityView">
|
||||
|
||||
<ToggleButton
|
||||
android:id="@+id/tbShowHidden"
|
||||
style="@style/buttonStyleSmall"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minWidth="0dp"
|
||||
android:minHeight="0dp"
|
||||
android:textOff="@string/title_show_folders"
|
||||
android:textOn="@string/title_hide_folders"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/vSeparator" />
|
||||
<TextView
|
||||
android:id="@+id/tvHintActions"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="6dp"
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_marginEnd="6dp"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="33dp"
|
||||
android:text="@string/title_hint_folder_actions"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
app:layout_constraintEnd_toStartOf="@+id/ibHintActions"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rvFolder"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:scrollbarStyle="outsideOverlay"
|
||||
android:scrollbars="vertical"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tbShowHidden" />
|
||||
<ImageButton
|
||||
android:id="@+id/ibHintActions"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/baseline_close_24"
|
||||
app:layout_constraintBottom_toBottomOf="@id/tvHintActions"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/tvHintActions" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/pbWait"
|
||||
style="@style/Base.Widget.AppCompat.ProgressBar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminate="true"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
<View
|
||||
android:id="@+id/vSeparator"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginTop="6dp"
|
||||
android:background="?attr/colorSeparator"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvHintActions" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:id="@+id/grpHintActions"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:constraint_referenced_ids="tvHintActions,ibHintActions,vSeparator" />
|
||||
<ToggleButton
|
||||
android:id="@+id/tbShowHidden"
|
||||
style="@style/buttonStyleSmall"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minWidth="0dp"
|
||||
android:minHeight="0dp"
|
||||
android:textOff="@string/title_show_folders"
|
||||
android:textOn="@string/title_hide_folders"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/vSeparator" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:id="@+id/grpReady"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:constraint_referenced_ids="rvFolder" />
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rvFolder"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:scrollbarStyle="outsideOverlay"
|
||||
android:scrollbars="vertical"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tbShowHidden" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/pbWait"
|
||||
style="@style/Base.Widget.AppCompat.ProgressBar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminate="true"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:id="@+id/grpHintActions"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:constraint_referenced_ids="tvHintActions,ibHintActions,vSeparator" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:id="@+id/grpReady"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:constraint_referenced_ids="rvFolder" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
|
@ -98,4 +104,4 @@
|
|||
app:backgroundTint="?attr/colorAccent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
|
Loading…
Reference in New Issue