email: return default folder name for subfolders

For subfolders of system folder type return the remote folder name instead of translate
it to the default folder type resource name. Subfolders shouldn't be considered as
system folders. For example a SPAM folder of a SPAM root folder (Junk/Ham should
be displayed as  Ham instead of Junk).

Change-Id: I2644b8da336e3f0983d24355aefe961aa8acf30b
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
(cherry picked from commit db1ca54cd325c64971240d92ed11dad175d83579)
This commit is contained in:
Jorge Ruesga 2015-10-22 02:18:40 +02:00
parent fab6ba77a4
commit c929853c2d

View File

@ -4033,7 +4033,8 @@ public class EmailProvider extends ContentProvider
values[i] = combinedUriString("uifolder", idString); values[i] = combinedUriString("uifolder", idString);
} else if (column.equals(UIProvider.FolderColumns.NAME)) { } else if (column.equals(UIProvider.FolderColumns.NAME)) {
// default empty string since all of these should use resource strings // default empty string since all of these should use resource strings
values[i] = getFolderDisplayName(getFolderTypeFromMailboxType(mailboxType), ""); values[i] = getFolderDisplayName(
getFolderTypeFromMailboxType(mailboxType), "", false);
} else if (column.equals(UIProvider.FolderColumns.HAS_CHILDREN)) { } else if (column.equals(UIProvider.FolderColumns.HAS_CHILDREN)) {
values[i] = 0; values[i] = 0;
} else if (column.equals(UIProvider.FolderColumns.CAPABILITIES)) { } else if (column.equals(UIProvider.FolderColumns.CAPABILITIES)) {
@ -4517,7 +4518,7 @@ public class EmailProvider extends ContentProvider
*/ */
private Cursor getUiFolderCursorRowFromMailboxCursorRow( private Cursor getUiFolderCursorRowFromMailboxCursorRow(
MatrixCursor mc, int projectionLength, Cursor mailboxCursor, MatrixCursor mc, int projectionLength, Cursor mailboxCursor,
int nameColumn, int typeColumn) { int nameColumn, int typeColumn, int parentUriColumn) {
final MatrixCursor.RowBuilder builder = mc.newRow(); final MatrixCursor.RowBuilder builder = mc.newRow();
for (int i = 0; i < projectionLength; i++) { for (int i = 0; i < projectionLength; i++) {
// If we are at the name column, get the type // If we are at the name column, get the type
@ -4529,7 +4530,9 @@ public class EmailProvider extends ContentProvider
// type has also been requested. If not, this will // type has also been requested. If not, this will
// error in unknown ways. // error in unknown ways.
final int type = mailboxCursor.getInt(typeColumn); final int type = mailboxCursor.getInt(typeColumn);
builder.add(getFolderDisplayName(type, mailboxCursor.getString(i))); final boolean rootFolder = parentUriColumn == -1 ||
TextUtils.isEmpty(mailboxCursor.getString(parentUriColumn));
builder.add(getFolderDisplayName(type, mailboxCursor.getString(i), rootFolder));
} else { } else {
builder.add(mailboxCursor.getString(i)); builder.add(mailboxCursor.getString(i));
} }
@ -4565,6 +4568,7 @@ public class EmailProvider extends ContentProvider
final int idColumn = inputCursor.getColumnIndex(BaseColumns._ID); final int idColumn = inputCursor.getColumnIndex(BaseColumns._ID);
final int typeColumn = inputCursor.getColumnIndex(UIProvider.FolderColumns.TYPE); final int typeColumn = inputCursor.getColumnIndex(UIProvider.FolderColumns.TYPE);
final int nameColumn = inputCursor.getColumnIndex(UIProvider.FolderColumns.NAME); final int nameColumn = inputCursor.getColumnIndex(UIProvider.FolderColumns.NAME);
final int parentUriColumn = inputCursor.getColumnIndex(UIProvider.FolderColumns.PARENT_URI);
final int capabilitiesColumn = final int capabilitiesColumn =
inputCursor.getColumnIndex(UIProvider.FolderColumns.CAPABILITIES); inputCursor.getColumnIndex(UIProvider.FolderColumns.CAPABILITIES);
final int persistentIdColumn = final int persistentIdColumn =
@ -4582,6 +4586,7 @@ public class EmailProvider extends ContentProvider
while (inputCursor.moveToNext()) { while (inputCursor.moveToNext()) {
final MatrixCursor.RowBuilder builder = outputCursor.newRow(); final MatrixCursor.RowBuilder builder = outputCursor.newRow();
final int folderType = inputCursor.getInt(typeColumn); final int folderType = inputCursor.getInt(typeColumn);
final boolean rootFolder = TextUtils.isEmpty(inputCursor.getString(parentUriColumn));
for (int i = 0; i < uiProjection.length; i++) { for (int i = 0; i < uiProjection.length; i++) {
// Find the index in the input cursor corresponding the column requested in the // Find the index in the input cursor corresponding the column requested in the
// output projection. // output projection.
@ -4596,7 +4601,7 @@ public class EmailProvider extends ContentProvider
final boolean remapped; final boolean remapped;
if (nameColumn == index) { if (nameColumn == index) {
// Remap folder name for system folders. // Remap folder name for system folders.
builder.add(getFolderDisplayName(folderType, value)); builder.add(getFolderDisplayName(folderType, value, rootFolder));
remapped = true; remapped = true;
} else if (capabilitiesColumn == index) { } else if (capabilitiesColumn == index) {
// Get the correct capabilities for this folder. // Get the correct capabilities for this folder.
@ -4646,9 +4651,15 @@ public class EmailProvider extends ContentProvider
* @param folderType {@link UIProvider.FolderType} value for the folder * @param folderType {@link UIProvider.FolderType} value for the folder
* @param defaultName a {@link String} to use in case the {@link UIProvider.FolderType} * @param defaultName a {@link String} to use in case the {@link UIProvider.FolderType}
* provided is not a system folder. * provided is not a system folder.
* @param rootFolder whether the folder is a root folder
* @return a {@link String} to use as the display name for the folder * @return a {@link String} to use as the display name for the folder
*/ */
private String getFolderDisplayName(int folderType, String defaultName) { private String getFolderDisplayName(int folderType, String defaultName, boolean rootFolder) {
if (!rootFolder && !TextUtils.isEmpty(defaultName)) {
// If the folder is not a root, we must use the provided folder name
return defaultName;
}
final int resId; final int resId;
switch (folderType) { switch (folderType) {
case UIProvider.FolderType.INBOX: case UIProvider.FolderType.INBOX:
@ -4903,12 +4914,15 @@ public class EmailProvider extends ContentProvider
final List<String> projectionList = Arrays.asList(uiProjection); final List<String> projectionList = Arrays.asList(uiProjection);
final int nameColumn = projectionList.indexOf(UIProvider.FolderColumns.NAME); final int nameColumn = projectionList.indexOf(UIProvider.FolderColumns.NAME);
final int typeColumn = projectionList.indexOf(UIProvider.FolderColumns.TYPE); final int typeColumn = projectionList.indexOf(UIProvider.FolderColumns.TYPE);
final int parentUriColumn =
projectionList.indexOf(UIProvider.FolderColumns.PARENT_URI);
if (c.moveToFirst()) { if (c.moveToFirst()) {
final Cursor closeThis = c; final Cursor closeThis = c;
try { try {
c = getUiFolderCursorRowFromMailboxCursorRow( c = getUiFolderCursorRowFromMailboxCursorRow(
new MatrixCursorWithCachedColumns(uiProjection), new MatrixCursorWithCachedColumns(uiProjection),
uiProjection.length, c, nameColumn, typeColumn); uiProjection.length, c, nameColumn,
typeColumn, parentUriColumn);
} finally { } finally {
closeThis.close(); closeThis.close();
} }