Skip to content

Commit

Permalink
Added a simple realization of Paging v3. Temporary disabled some func…
Browse files Browse the repository at this point in the history
…tionality. Refactored code.| #1806
  • Loading branch information
DenBond7 committed May 18, 2022
1 parent 275290c commit 31b184f
Show file tree
Hide file tree
Showing 11 changed files with 760 additions and 770 deletions.
4 changes: 3 additions & 1 deletion FlowCrypt/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ android {
kotlinOptions {
jvmTarget = "11"
//need for ACRA, maybe will be deleted in the upcoming updates
freeCompilerArgs = ['-Xjvm-default=enable']
freeCompilerArgs += ['-Xjvm-default=enable']
freeCompilerArgs += ["-Xopt-in=kotlin.RequiresOptIn"]
}

packagingOptions {
Expand Down Expand Up @@ -382,6 +383,7 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.0-rc01'
implementation 'androidx.room:room-runtime:2.4.2'
implementation 'androidx.room:room-ktx:2.4.2'
implementation 'androidx.room:room-paging:2.4.2'
implementation 'androidx.paging:paging-runtime-ktx:3.1.1'
implementation 'androidx.preference:preference-ktx:1.2.0'
implementation 'androidx.core:core-ktx:1.7.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class FoldersManager constructor(val account: String) {
sentFolder?.let { return it }

for (localFolder in allFolders) {
if (localFolder.fullName.toUpperCase(Locale.US) in arrayOf("INBOX/SENT", "SENT")) {
if (localFolder.fullName.uppercase(Locale.US) in arrayOf("INBOX/SENT", "SENT")) {
sentFolder = localFolder
}
}
Expand Down Expand Up @@ -404,8 +404,8 @@ class FoldersManager constructor(val account: String) {
* @return [FolderType].
*/
fun getFolderType(localFolder: LocalFolder?): FolderType? {
val folderTypes = FolderType.values()
val attributes = localFolder?.attributes ?: emptyList()
val folderTypes = FolderType.values()

for (attribute in attributes) {
for (folderType in folderTypes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class JavaEmailConstants {

const val DEFAULT_FETCH_BUFFER = 1024 * 1024
const val ATTACHMENTS_FETCH_BUFFER = 1024 * 256
const val COUNT_OF_LOADED_EMAILS_BY_STEP = 45

/*IMAP*/
const val PROPERTY_NAME_MAIL_IMAP_SSL_ENABLE = "mail.imap.ssl.enable"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ class GmailApiHelper {
"CATEGORY_PROMOTIONS",
"CATEGORY_SOCIAL"
)
private const val COUNT_OF_LOADED_EMAILS_BY_STEP =
JavaEmailConstants.COUNT_OF_LOADED_EMAILS_BY_STEP.toLong()

private val FULL_INFO_WITHOUT_DATA = listOf(
"id",
Expand Down Expand Up @@ -220,16 +218,19 @@ class GmailApiHelper {
}

suspend fun loadMsgsBaseInfo(
context: Context, accountEntity: AccountEntity, localFolder:
LocalFolder, nextPageToken: String? = null
context: Context,
accountEntity: AccountEntity,
localFolder: LocalFolder,
maxResults: Long,
nextPageToken: String? = null
): ListMessagesResponse = withContext(Dispatchers.IO) {
val gmailApiService = generateGmailApiService(context, accountEntity)
val request = gmailApiService
.users()
.messages()
.list(DEFAULT_USER_ID)
.setPageToken(nextPageToken)
.setMaxResults(COUNT_OF_LOADED_EMAILS_BY_STEP)
.setMaxResults(maxResults)

if (!localFolder.isAll()) {
request.labelIds = listOf(localFolder.fullName)
Expand Down Expand Up @@ -583,8 +584,11 @@ class GmailApiHelper {
}

suspend fun loadMsgsBaseInfoUsingSearch(
context: Context, accountEntity: AccountEntity,
localFolder: LocalFolder, nextPageToken: String? = null
context: Context,
accountEntity: AccountEntity,
localFolder: LocalFolder,
maxResults: Long,
nextPageToken: String? = null
):
ListMessagesResponse = withContext(Dispatchers.IO) {

Expand All @@ -601,7 +605,7 @@ class GmailApiHelper {
) as? GmailRawSearchTerm)?.pattern
)
.setPageToken(nextPageToken)
.setMaxResults(COUNT_OF_LOADED_EMAILS_BY_STEP)
.setMaxResults(maxResults)
return@withContext list.execute()
}

Expand Down
Loading

0 comments on commit 31b184f

Please sign in to comment.