1b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy/******************************************************************************* 2b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy * Copyright (C) 2013 Google Inc. 3b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy * Licensed to The Android Open Source Project. 4b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy * 5b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy * Licensed under the Apache License, Version 2.0 (the "License"); 6b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy * you may not use this file except in compliance with the License. 7b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy * You may obtain a copy of the License at 8b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy * 9b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy * http://www.apache.org/licenses/LICENSE-2.0 10b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy * 11b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy * Unless required by applicable law or agreed to in writing, software 12b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy * distributed under the License is distributed on an "AS IS" BASIS, 13b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy * See the License for the specific language governing permissions and 15b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy * limitations under the License. 16b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy *******************************************************************************/ 17b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedypackage com.android.mail.browse; 18b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy 19b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedyimport android.database.Cursor; 20b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedyimport android.database.CursorWrapper; 21b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy 227ee089ea2ef96e31504e88637b5f3b0969b3c7c1Scott Kennedypublic interface ConversationCursorOperationListener { 23b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy /** 24b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy * Marks all contents of this cursor as seen. 25b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy */ 26b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy void markContentsSeen(); 27b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy 287ee089ea2ef96e31504e88637b5f3b0969b3c7c1Scott Kennedy /** 297ee089ea2ef96e31504e88637b5f3b0969b3c7c1Scott Kennedy * Empties the folder of all messages, if possible. 307ee089ea2ef96e31504e88637b5f3b0969b3c7c1Scott Kennedy */ 317ee089ea2ef96e31504e88637b5f3b0969b3c7c1Scott Kennedy void emptyFolder(); 327ee089ea2ef96e31504e88637b5f3b0969b3c7c1Scott Kennedy 337ee089ea2ef96e31504e88637b5f3b0969b3c7c1Scott Kennedy public class OperationHelper { 34b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy /** 357ee089ea2ef96e31504e88637b5f3b0969b3c7c1Scott Kennedy * Invokes {@link ConversationCursorOperationListener#markContentsSeen(Cursor)} on the 36b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy * specified {@link Cursor}, recursively calls {@link #markContentsSeen(Cursor)} on a 37b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy * wrapped cursor, or returns. 38b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy */ 39b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy public static void markContentsSeen(final Cursor cursor) { 40b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy if (cursor == null) { 41b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy return; 42b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy } 43b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy 447ee089ea2ef96e31504e88637b5f3b0969b3c7c1Scott Kennedy if (cursor instanceof ConversationCursorOperationListener) { 457ee089ea2ef96e31504e88637b5f3b0969b3c7c1Scott Kennedy ((ConversationCursorOperationListener) cursor).markContentsSeen(); 46b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy } else if (cursor instanceof CursorWrapper) { 47b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy markContentsSeen(((CursorWrapper) cursor).getWrappedCursor()); 48b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy } 49b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy } 507ee089ea2ef96e31504e88637b5f3b0969b3c7c1Scott Kennedy 517ee089ea2ef96e31504e88637b5f3b0969b3c7c1Scott Kennedy /** 527ee089ea2ef96e31504e88637b5f3b0969b3c7c1Scott Kennedy * Invokes {@link ConversationCursorOperationListener#emptyFolder(Cursor)} on the 537ee089ea2ef96e31504e88637b5f3b0969b3c7c1Scott Kennedy * specified {@link Cursor}, recursively calls {@link #emptyFolder(Cursor)} on a 547ee089ea2ef96e31504e88637b5f3b0969b3c7c1Scott Kennedy * wrapped cursor, or returns. 557ee089ea2ef96e31504e88637b5f3b0969b3c7c1Scott Kennedy */ 567ee089ea2ef96e31504e88637b5f3b0969b3c7c1Scott Kennedy public static void emptyFolder(final Cursor cursor) { 577ee089ea2ef96e31504e88637b5f3b0969b3c7c1Scott Kennedy if (cursor == null) { 587ee089ea2ef96e31504e88637b5f3b0969b3c7c1Scott Kennedy return; 597ee089ea2ef96e31504e88637b5f3b0969b3c7c1Scott Kennedy } 607ee089ea2ef96e31504e88637b5f3b0969b3c7c1Scott Kennedy 617ee089ea2ef96e31504e88637b5f3b0969b3c7c1Scott Kennedy if (cursor instanceof ConversationCursorOperationListener) { 627ee089ea2ef96e31504e88637b5f3b0969b3c7c1Scott Kennedy ((ConversationCursorOperationListener) cursor).emptyFolder(); 637ee089ea2ef96e31504e88637b5f3b0969b3c7c1Scott Kennedy } else if (cursor instanceof CursorWrapper) { 647ee089ea2ef96e31504e88637b5f3b0969b3c7c1Scott Kennedy emptyFolder(((CursorWrapper) cursor).getWrappedCursor()); 657ee089ea2ef96e31504e88637b5f3b0969b3c7c1Scott Kennedy } 667ee089ea2ef96e31504e88637b5f3b0969b3c7c1Scott Kennedy } 67b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy } 68b1e21487e18503cc110e1cf8726b835e048ab1c1Scott Kennedy} 69