Merge pull request #4473 from k9mail/message_list_progress

Display progress when syncing a folder
This commit is contained in:
cketti 2020-01-26 01:22:37 +01:00 committed by GitHub
commit 1bac774a60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 13 deletions

View file

@ -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

View file

@ -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;
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;
}
}
}
@ -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);

View file

@ -7,6 +7,18 @@
<include layout="@layout/toolbar" />
<ProgressBar
android:id="@+id/message_list_progress"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-2dp"
android:elevation="4dp"
android:max="10000"
android:maxHeight="2dp"
android:minHeight="2dp"
android:visibility="invisible" />
<com.fsck.k9.view.ViewSwitcher
android:id="@+id/container"
android:layout_width="match_parent"

View file

@ -8,6 +8,18 @@
<include layout="@layout/toolbar" />
<ProgressBar
android:id="@+id/message_list_progress"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-2dp"
android:elevation="4dp"
android:max="10000"
android:maxHeight="2dp"
android:minHeight="2dp"
android:visibility="invisible" />
<LinearLayout
android:id="@+id/container"
android:layout_width="fill_parent"