mirror of https://github.com/M66B/FairEmail.git
Added swipe refresh to unified accounts
This commit is contained in:
parent
dd2f217c48
commit
852b2d5579
|
@ -24,6 +24,7 @@ import android.animation.ValueAnimator;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
|
@ -44,8 +45,10 @@ import androidx.preference.PreferenceManager;
|
|||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -55,6 +58,8 @@ public class FragmentAccounts extends FragmentBase {
|
|||
|
||||
private boolean cards;
|
||||
|
||||
private ViewGroup view;
|
||||
private SwipeRefreshLayout swipeRefresh;
|
||||
private RecyclerView rvAccount;
|
||||
private ContentLoadingProgressBar pbWait;
|
||||
private Group grpReady;
|
||||
|
@ -82,9 +87,10 @@ public class FragmentAccounts extends FragmentBase {
|
|||
setSubtitle(R.string.title_list_accounts);
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
View view = inflater.inflate(R.layout.fragment_accounts, container, false);
|
||||
view = (ViewGroup) inflater.inflate(R.layout.fragment_accounts, container, false);
|
||||
|
||||
// Get controls
|
||||
swipeRefresh = view.findViewById(R.id.swipeRefresh);
|
||||
rvAccount = view.findViewById(R.id.rvAccount);
|
||||
pbWait = view.findViewById(R.id.pbWait);
|
||||
grpReady = view.findViewById(R.id.grpReady);
|
||||
|
@ -93,6 +99,17 @@ public class FragmentAccounts extends FragmentBase {
|
|||
|
||||
// Wire controls
|
||||
|
||||
int colorPrimary = Helper.resolveColor(getContext(), R.attr.colorPrimary);
|
||||
swipeRefresh.setColorSchemeColors(Color.WHITE, Color.WHITE, Color.WHITE);
|
||||
swipeRefresh.setProgressBackgroundColorSchemeColor(colorPrimary);
|
||||
swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
onSwipeRefresh();
|
||||
}
|
||||
});
|
||||
swipeRefresh.setEnabled(!settings);
|
||||
|
||||
rvAccount.setHasFixedSize(false);
|
||||
LinearLayoutManager llm = new LinearLayoutManager(getContext());
|
||||
rvAccount.setLayoutManager(llm);
|
||||
|
@ -279,4 +296,68 @@ public class FragmentAccounts extends FragmentBase {
|
|||
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
}
|
||||
|
||||
private void onSwipeRefresh() {
|
||||
Bundle args = new Bundle();
|
||||
|
||||
new SimpleTask<Void>() {
|
||||
@Override
|
||||
protected void onPostExecute(Bundle args) {
|
||||
swipeRefresh.setRefreshing(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void onExecute(Context context, Bundle args) {
|
||||
if (!ConnectionHelper.getNetworkState(context).isSuitable())
|
||||
throw new IllegalStateException(context.getString(R.string.title_no_internet));
|
||||
|
||||
boolean now = true;
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
try {
|
||||
db.beginTransaction();
|
||||
|
||||
// Unified inbox
|
||||
List<EntityFolder> folders = db.folder().getFoldersSynchronizingUnified(null);
|
||||
for (EntityFolder folder : folders) {
|
||||
EntityOperation.sync(context, folder.id, true);
|
||||
|
||||
if (folder.account != null) {
|
||||
EntityAccount account = db.account().getAccount(folder.account);
|
||||
if (account != null && !"connected".equals(account.state))
|
||||
now = false;
|
||||
}
|
||||
}
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
|
||||
if (!now)
|
||||
throw new IllegalArgumentException(context.getString(R.string.title_no_connection));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
if (ex instanceof IllegalStateException) {
|
||||
Snackbar snackbar = Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG);
|
||||
snackbar.setAction(R.string.title_fix, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
getContext().startActivity(
|
||||
new Intent(getContext(), ActivitySetup.class)
|
||||
.putExtra("tab", "connection"));
|
||||
}
|
||||
});
|
||||
snackbar.show();
|
||||
} else if (ex instanceof IllegalArgumentException)
|
||||
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
|
||||
else
|
||||
Helper.unexpectedError(getFragmentManager(), ex);
|
||||
}
|
||||
}.execute(this, args, "folders:refresh");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,11 @@
|
|||
android:layout_height="match_parent"
|
||||
tools:context=".ActivitySetup">
|
||||
|
||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
android:id="@+id/swipeRefresh"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
@ -41,6 +46,7 @@
|
|||
android:layout_height="0dp"
|
||||
app:constraint_referenced_ids="rvAccount" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fabCompose"
|
||||
|
|
Loading…
Reference in New Issue