mirror of
https://github.com/moparisthebest/k-9
synced 2025-01-08 20:28:34 -05:00
Prevent the display of the message list before the folder list has initially been retrieved from the server after account setup.
This commit is contained in:
parent
ba6fc665a8
commit
474780cbf4
@ -4,34 +4,6 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical">
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_height="fill_parent"
|
||||
android:padding="6dip"
|
||||
android:layout_width="fill_parent">
|
||||
<View
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="100sp" />
|
||||
<TextView
|
||||
android:id="@+id/message"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent"
|
||||
android:gravity="center_horizontal"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:paddingBottom="6dip"
|
||||
android:focusable="true"
|
||||
/>
|
||||
<ProgressBar
|
||||
android:id="@+id/progress"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:focusable="true" />
|
||||
<View
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="0dip"
|
||||
android:layout_weight="1" />
|
||||
</LinearLayout>
|
||||
<include layout="@layout/wizard_cancel" />
|
||||
<include layout="@layout/progress_bar"/>
|
||||
<include layout="@layout/wizard_cancel"/>
|
||||
</LinearLayout>
|
||||
|
@ -6,7 +6,12 @@
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
/>
|
||||
|
||||
android:layout_height="fill_parent"/>
|
||||
<LinearLayout
|
||||
android:id="@android:id/empty"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
<include layout="@layout/progress_bar"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
32
res/layout/progress_bar.xml
Normal file
32
res/layout/progress_bar.xml
Normal file
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_width="fill_parent"
|
||||
android:padding="6dip">
|
||||
<View
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="100sp"/>
|
||||
<TextView
|
||||
android:id="@+id/message"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent"
|
||||
android:gravity="center_horizontal"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:paddingBottom="6dip"
|
||||
android:focusable="true"/>
|
||||
<ProgressBar
|
||||
android:id="@+id/progress"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:indeterminate="true"
|
||||
android:focusable="true"/>
|
||||
<View
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="0dip"
|
||||
android:layout_weight="1"/>
|
||||
</LinearLayout>
|
||||
</merge>
|
@ -842,6 +842,7 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
|
||||
<string name="folder_list_display_mode_first_class">Display only 1st Class folders</string>
|
||||
<string name="folder_list_display_mode_first_and_second_class">Display 1st and 2nd Class folders</string>
|
||||
<string name="folder_list_display_mode_not_second_class">Display all except 2nd Class folders</string>
|
||||
<string name="folder_list_loading_folders">Loading folder list\u2026</string>
|
||||
|
||||
<string name="account_settings_signature__location_label">Signature position</string>
|
||||
<string name="account_settings_signature__location_before_quoted_text">Before quoted text</string>
|
||||
|
@ -78,6 +78,7 @@ import com.fsck.k9.controller.MessagingController;
|
||||
import com.fsck.k9.controller.MessagingListener;
|
||||
import com.fsck.k9.helper.SizeFormatter;
|
||||
import com.fsck.k9.mail.Flag;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mail.ServerSettings;
|
||||
import com.fsck.k9.mail.Store;
|
||||
import com.fsck.k9.mail.Transport;
|
||||
@ -566,10 +567,16 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
|
||||
Log.i(K9.LOG_TAG, "refusing to open account that is not available");
|
||||
return false;
|
||||
}
|
||||
if (K9.FOLDER_NONE.equals(realAccount.getAutoExpandFolderName())) {
|
||||
FolderList.actionHandleAccount(this, realAccount);
|
||||
} else {
|
||||
MessageList.actionHandleFolder(this, realAccount, realAccount.getAutoExpandFolderName());
|
||||
try {
|
||||
if (K9.FOLDER_NONE.equals(realAccount.getAutoExpandFolderName()) ||
|
||||
realAccount.getLocalStore().getFolderCount() == 0) {
|
||||
FolderList.actionHandleAccount(this, realAccount);
|
||||
} else {
|
||||
MessageList.actionHandleFolder(this, realAccount, realAccount.getAutoExpandFolderName());
|
||||
}
|
||||
}
|
||||
catch (MessagingException e) {
|
||||
Log.e(K9.LOG_TAG, "Exception while getting local folder count", e);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -83,8 +83,6 @@ public class FolderList extends K9ListActivity {
|
||||
public void run() {
|
||||
String dispString = mAdapter.mListener.formatHeader(FolderList.this,
|
||||
getString(R.string.folder_list_title, mAccount.getDescription()), mUnreadMessageCount, getTimeFormat());
|
||||
|
||||
|
||||
setTitle(dispString);
|
||||
}
|
||||
});
|
||||
@ -116,7 +114,6 @@ public class FolderList extends K9ListActivity {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
String toastText = getString(R.string.account_size_changed, mAccount.getDescription(), SizeFormatter.formatSize(getApplication(), oldSize), SizeFormatter.formatSize(getApplication(), newSize));
|
||||
|
||||
Toast toast = Toast.makeText(getApplication(), toastText, Toast.LENGTH_LONG);
|
||||
toast.show();
|
||||
}
|
||||
@ -127,12 +124,9 @@ public class FolderList extends K9ListActivity {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
FolderInfoHolder folderHolder = mAdapter.getFolder(folder);
|
||||
|
||||
|
||||
if (folderHolder != null) {
|
||||
folderHolder.loading = loading;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -253,7 +247,10 @@ public class FolderList extends K9ListActivity {
|
||||
}
|
||||
});
|
||||
registerForContextMenu(mListView);
|
||||
|
||||
|
||||
TextView progressMsg = (TextView)findViewById(R.id.message);
|
||||
progressMsg.setText(getString(R.string.folder_list_loading_folders));
|
||||
|
||||
mListView.setSaveEnabled(true);
|
||||
|
||||
mInflater = getLayoutInflater();
|
||||
|
@ -139,7 +139,9 @@ public class MessagingController implements Runnable {
|
||||
|
||||
private final ConcurrentHashMap<String, AtomicInteger> sendCount = new ConcurrentHashMap<String, AtomicInteger>();
|
||||
|
||||
ConcurrentHashMap<Account, Pusher> pushers = new ConcurrentHashMap<Account, Pusher>();
|
||||
private ConcurrentHashMap<Account, Pusher> pushers = new ConcurrentHashMap<Account, Pusher>();
|
||||
|
||||
private Set<Account> mCurrentlyRefreshing = Collections.synchronizedSet(new HashSet<Account>());
|
||||
|
||||
private final ExecutorService threadPool = Executors.newCachedThreadPool();
|
||||
|
||||
@ -448,81 +450,93 @@ public class MessagingController implements Runnable {
|
||||
}
|
||||
|
||||
private void doRefreshRemote(final Account account, MessagingListener listener) {
|
||||
put("doRefreshRemote", listener, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
List <? extends Folder > localFolders = null;
|
||||
try {
|
||||
Store store = account.getRemoteStore();
|
||||
// It is possible that multiple threads may try to refresh the same account at the same time.
|
||||
// Currently, this can happen immediately after the account is setup initially, and is
|
||||
// generally a bad thing. Let's use a hack to prevent this from happening.
|
||||
if (!mCurrentlyRefreshing.contains(account)) {
|
||||
mCurrentlyRefreshing.add(account);
|
||||
put("doRefreshRemote", listener, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
doRefreshRemoteSynchronous(account);
|
||||
mCurrentlyRefreshing.remove(account);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void doRefreshRemoteSynchronous(final Account account) {
|
||||
List<? extends Folder> localFolders = null;
|
||||
try {
|
||||
Store remoteStore = account.getRemoteStore();
|
||||
List<? extends Folder> remoteFolders = remoteStore.getPersonalNamespaces(true);
|
||||
|
||||
List <? extends Folder > remoteFolders = store.getPersonalNamespaces(true);
|
||||
LocalStore localStore = account.getLocalStore();
|
||||
localFolders = localStore.getPersonalNamespaces(false);
|
||||
|
||||
syncLocalFoldersWithRemoteFolders(localFolders, remoteFolders, account);
|
||||
|
||||
LocalStore localStore = account.getLocalStore();
|
||||
HashSet<String> remoteFolderNames = new HashSet<String>();
|
||||
List<LocalFolder> foldersToCreate = new LinkedList<LocalFolder>();
|
||||
// Get the updated local folder list.
|
||||
localFolders = localStore.getPersonalNamespaces(false);
|
||||
Folder[] folderArray = localFolders.toArray(EMPTY_FOLDER_ARRAY);
|
||||
|
||||
localFolders = localStore.getPersonalNamespaces(false);
|
||||
HashSet<String> localFolderNames = new HashSet<String>();
|
||||
for (Folder localFolder : localFolders) {
|
||||
localFolderNames.add(localFolder.getRemoteName());
|
||||
}
|
||||
for (Folder remoteFolder : remoteFolders) {
|
||||
LocalFolder localFolder = null;
|
||||
if (localFolderNames.contains(remoteFolder.getRemoteName()) == false) {
|
||||
localFolder = localStore.getFolder(remoteFolder.getRemoteName(),
|
||||
remoteFolder.getName());
|
||||
foldersToCreate.add(localFolder);
|
||||
} else {
|
||||
for (Folder folder : localFolders) {
|
||||
if (folder.getRemoteName().equals(remoteFolder.getRemoteName())) {
|
||||
localFolder = (LocalFolder)folder;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
remoteFolderNames.add(remoteFolder.getRemoteName());
|
||||
|
||||
if (remoteFolder instanceof EasFolder) {
|
||||
((EasFolder)remoteFolder).setLocalFolder(localFolder, false);
|
||||
}
|
||||
}
|
||||
localStore.createFolders(foldersToCreate, account.getDisplayCount());
|
||||
|
||||
localFolders = localStore.getPersonalNamespaces(false);
|
||||
|
||||
/*
|
||||
* Clear out any folders that are no longer on the remote store.
|
||||
*/
|
||||
for (Folder localFolder : localFolders) {
|
||||
if (!account.isSpecialFolder(localFolder.getRemoteName()) &&
|
||||
!remoteFolderNames.contains(localFolder.getRemoteName())) {
|
||||
localFolder.delete(false);
|
||||
}
|
||||
}
|
||||
|
||||
localFolders = localStore.getPersonalNamespaces(false);
|
||||
Folder[] folderArray = localFolders.toArray(EMPTY_FOLDER_ARRAY);
|
||||
|
||||
for (MessagingListener l : getListeners()) {
|
||||
l.listFolders(account, folderArray);
|
||||
}
|
||||
for (MessagingListener l : getListeners()) {
|
||||
l.listFoldersFinished(account);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
for (MessagingListener l : getListeners()) {
|
||||
l.listFoldersFailed(account, "");
|
||||
}
|
||||
addErrorMessage(account, null, e);
|
||||
} finally {
|
||||
if (localFolders != null) {
|
||||
for (Folder localFolder : localFolders) {
|
||||
closeFolder(localFolder);
|
||||
}
|
||||
}
|
||||
for (MessagingListener l : getListeners()) {
|
||||
l.listFolders(account, folderArray);
|
||||
}
|
||||
for (MessagingListener l : getListeners()) {
|
||||
l.listFoldersFinished(account);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
for (MessagingListener l : getListeners()) {
|
||||
l.listFoldersFailed(account, "");
|
||||
}
|
||||
addErrorMessage(account, null, e);
|
||||
} finally {
|
||||
if (localFolders != null) {
|
||||
for (Folder localFolder : localFolders) {
|
||||
closeFolder(localFolder);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void syncLocalFoldersWithRemoteFolders(List<? extends Folder> localFolders,
|
||||
List<? extends Folder> remoteFolders, final Account account) throws MessagingException {
|
||||
HashSet<String> remoteFolderNames = new HashSet<String>();
|
||||
HashMap<String, Folder> localFolderNames = new HashMap<String, Folder>();
|
||||
|
||||
List<LocalFolder> foldersToCreate = new LinkedList<LocalFolder>();
|
||||
LocalStore localStore = account.getLocalStore();
|
||||
|
||||
for (Folder localFolder : localFolders) {
|
||||
localFolderNames.put(localFolder.getRemoteName(), localFolder);
|
||||
}
|
||||
|
||||
// Add any new folders in the remote store to the local store.
|
||||
for (Folder remoteFolder : remoteFolders) {
|
||||
LocalFolder localFolder = (LocalFolder)localFolderNames.get(remoteFolder.getRemoteName());
|
||||
if (localFolder == null) {
|
||||
localFolder = localStore.getFolder(remoteFolder.getRemoteName(),
|
||||
remoteFolder.getName());
|
||||
foldersToCreate.add(localFolder);
|
||||
}
|
||||
remoteFolderNames.add(remoteFolder.getRemoteName());
|
||||
|
||||
if (remoteFolder instanceof EasFolder) {
|
||||
((EasFolder)remoteFolder).setLocalFolder(localFolder, false);
|
||||
}
|
||||
}
|
||||
|
||||
localStore.createFolders(foldersToCreate, account.getDisplayCount());
|
||||
localFolders = localStore.getPersonalNamespaces(false);
|
||||
|
||||
// Delete any folders in the local store that are no longer in the remote store.
|
||||
for (Folder localFolder : localFolders) {
|
||||
if (!account.isSpecialFolder(localFolder.getRemoteName()) &&
|
||||
!remoteFolderNames.contains(localFolder.getRemoteName())) {
|
||||
localFolder.delete(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -562,10 +576,6 @@ public class MessagingController implements Runnable {
|
||||
new MessageRetrievalListener() {
|
||||
List<Message> pendingMessages = new ArrayList<Message>();
|
||||
|
||||
|
||||
int totalDone = 0;
|
||||
|
||||
|
||||
@Override
|
||||
public void messageStarted(String message, int number, int ofTotal) {}
|
||||
@Override
|
||||
@ -573,7 +583,6 @@ public class MessagingController implements Runnable {
|
||||
|
||||
if (!isMessageSuppressed(account, folder, message)) {
|
||||
pendingMessages.add(message);
|
||||
totalDone++;
|
||||
if (pendingMessages.size() > 10) {
|
||||
addPendingMessages();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user