From 937882f836ec8dc110e93560bd188b039a95a56d Mon Sep 17 00:00:00 2001 From: cketti Date: Mon, 20 Jan 2020 17:16:19 +0100 Subject: [PATCH 1/2] Display progress when syncing a folder --- .../com/fsck/k9/activity/MessageList.java | 11 +++++++++-- .../fsck/k9/fragment/MessageListFragment.java | 19 +++++++++++-------- app/ui/src/main/res/layout/message_list.xml | 12 ++++++++++++ .../main/res/layout/split_message_list.xml | 12 ++++++++++++ 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java b/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java index 0ddfb272a..bc18cc9a3 100644 --- a/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java +++ b/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java @@ -28,6 +28,7 @@ import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.animation.AnimationUtils; +import android.widget.ProgressBar; import android.widget.Toast; import com.fsck.k9.Account; @@ -68,7 +69,6 @@ import de.cketti.library.changelog.ChangeLog; import timber.log.Timber; - /** * MessageList is the primary user interface for the program. This Activity * shows a list of messages. @@ -185,6 +185,7 @@ public class MessageList extends K9Activity implements MessageListFragmentListen private FragmentTransaction openFolderTransaction; private Menu menu; + private ProgressBar progressBar; private ViewGroup messageViewContainer; private View messageViewPlaceHolder; @@ -394,6 +395,7 @@ public class MessageList extends K9Activity implements MessageListFragmentListen } private void initializeLayout() { + progressBar = findViewById(R.id.message_list_progress); messageViewContainer = findViewById(R.id.message_view_container); LayoutInflater layoutInflater = getLayoutInflater(); @@ -1202,9 +1204,14 @@ public class MessageList extends K9Activity implements MessageListFragmentListen } } + @Override + public void setMessageListProgressEnabled(boolean enable) { + progressBar.setVisibility(enable ? View.VISIBLE : View.INVISIBLE); + } + @Override public void setMessageListProgress(int progress) { - setProgress(progress); + progressBar.setProgress(progress); } @Override diff --git a/app/ui/src/main/java/com/fsck/k9/fragment/MessageListFragment.java b/app/ui/src/main/java/com/fsck/k9/fragment/MessageListFragment.java index 13cf14017..87cbfaf26 100644 --- a/app/ui/src/main/java/com/fsck/k9/fragment/MessageListFragment.java +++ b/app/ui/src/main/java/com/fsck/k9/fragment/MessageListFragment.java @@ -29,7 +29,6 @@ import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; -import android.view.Window; import android.widget.AdapterView; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; @@ -74,6 +73,7 @@ import net.jcip.annotations.GuardedBy; import timber.log.Timber; import static com.fsck.k9.Account.Expunge.EXPUNGE_MANUALLY; +import static com.fsck.k9.fragment.MessageListFragment.MessageListFragmentListener.MAX_PROGRESS; import static com.fsck.k9.search.LocalSearchExtensions.getAccountsFromLocalSearch; @@ -203,14 +203,14 @@ public class MessageListFragment extends Fragment implements OnItemClickListener } private void setWindowProgress() { - int level = Window.PROGRESS_END; + int level = MAX_PROGRESS; if (currentFolder != null && currentFolder.loading && activityListener.getFolderTotal() > 0) { int divisor = activityListener.getFolderTotal(); if (divisor != 0) { - level = (Window.PROGRESS_END / divisor) * (activityListener.getFolderCompleted()) ; - if (level > Window.PROGRESS_END) { - level = Window.PROGRESS_END; + level = (MAX_PROGRESS / divisor) * (activityListener.getFolderCompleted()) ; + if (level > MAX_PROGRESS) { + level = MAX_PROGRESS; } } } @@ -238,6 +238,7 @@ public class MessageListFragment extends Fragment implements OnItemClickListener if (swipeRefreshLayout != null && !progress) { swipeRefreshLayout.setRefreshing(false); } + fragmentListener.setMessageListProgressEnabled(progress); } @Override @@ -1147,8 +1148,6 @@ public class MessageListFragment extends Fragment implements OnItemClickListener } else { handler.updateFooter(null); } - fragmentListener.setMessageListProgress(Window.PROGRESS_END); - } @Override @@ -1161,7 +1160,8 @@ public class MessageListFragment extends Fragment implements OnItemClickListener handler.updateFooter(context.getResources().getQuantityString(R.plurals.remote_search_downloading, numResults, numResults)); } - fragmentListener.setMessageListProgress(Window.PROGRESS_START); + + informUserOfStatus(); } private void informUserOfStatus() { @@ -2181,6 +2181,9 @@ public class MessageListFragment extends Fragment implements OnItemClickListener } public interface MessageListFragmentListener { + int MAX_PROGRESS = 10000; + + void setMessageListProgressEnabled(boolean enable); void setMessageListProgress(int level); void showThread(Account account, String folderServerId, long rootId); void showMoreFromSameSender(String senderAddress); diff --git a/app/ui/src/main/res/layout/message_list.xml b/app/ui/src/main/res/layout/message_list.xml index 3d7915218..12fa7c604 100644 --- a/app/ui/src/main/res/layout/message_list.xml +++ b/app/ui/src/main/res/layout/message_list.xml @@ -7,6 +7,18 @@ + + + + Date: Mon, 20 Jan 2020 17:30:36 +0100 Subject: [PATCH 2/2] Clean up MessageListFragment.setWindowProgress() --- .../java/com/fsck/k9/fragment/MessageListFragment.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/ui/src/main/java/com/fsck/k9/fragment/MessageListFragment.java b/app/ui/src/main/java/com/fsck/k9/fragment/MessageListFragment.java index 87cbfaf26..a59630b55 100644 --- a/app/ui/src/main/java/com/fsck/k9/fragment/MessageListFragment.java +++ b/app/ui/src/main/java/com/fsck/k9/fragment/MessageListFragment.java @@ -205,10 +205,10 @@ public class MessageListFragment extends Fragment implements OnItemClickListener private void setWindowProgress() { int level = MAX_PROGRESS; - if (currentFolder != null && currentFolder.loading && activityListener.getFolderTotal() > 0) { - int divisor = activityListener.getFolderTotal(); - if (divisor != 0) { - level = (MAX_PROGRESS / divisor) * (activityListener.getFolderCompleted()) ; + if (currentFolder != null && currentFolder.loading) { + int folderTotal = activityListener.getFolderTotal(); + if (folderTotal > 0) { + level = (MAX_PROGRESS * activityListener.getFolderCompleted()) / folderTotal; if (level > MAX_PROGRESS) { level = MAX_PROGRESS; }