|
|
@ -90,45 +90,53 @@ class ChangeCoverViewModel(application: Application) : BaseViewModel(application |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Synchronized |
|
|
|
private fun search() { |
|
|
|
private fun search() { |
|
|
|
synchronized(this) { |
|
|
|
if (searchIndex >= bookSourceList.lastIndex) { |
|
|
|
if (searchIndex >= bookSourceList.lastIndex) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
searchIndex++ |
|
|
|
searchIndex++ |
|
|
|
val source = bookSourceList[searchIndex] |
|
|
|
val source = bookSourceList[searchIndex] |
|
|
|
if (source.getSearchRule().coverUrl.isNullOrBlank()) { |
|
|
|
val task = WebBook(source) |
|
|
|
searchNext() |
|
|
|
.searchBook(this, name, context = searchPool!!) |
|
|
|
return |
|
|
|
.timeout(60000L) |
|
|
|
} |
|
|
|
.onSuccess(Dispatchers.IO) { |
|
|
|
val task = WebBook(source) |
|
|
|
if (it.isNotEmpty()) { |
|
|
|
.searchBook(this, name, context = searchPool!!) |
|
|
|
val searchBook = it[0] |
|
|
|
.timeout(60000L) |
|
|
|
if (searchBook.name == name && searchBook.author == author |
|
|
|
.onSuccess(Dispatchers.IO) { |
|
|
|
&& !searchBook.coverUrl.isNullOrEmpty() |
|
|
|
if (it.isNotEmpty()) { |
|
|
|
) { |
|
|
|
val searchBook = it[0] |
|
|
|
appDb.searchBookDao.insert(searchBook) |
|
|
|
if (searchBook.name == name && searchBook.author == author |
|
|
|
if (!searchBooks.contains(searchBook)) { |
|
|
|
&& !searchBook.coverUrl.isNullOrEmpty() |
|
|
|
searchBooks.add(searchBook) |
|
|
|
) { |
|
|
|
upAdapter() |
|
|
|
appDb.searchBookDao.insert(searchBook) |
|
|
|
} |
|
|
|
if (!searchBooks.contains(searchBook)) { |
|
|
|
} |
|
|
|
searchBooks.add(searchBook) |
|
|
|
} |
|
|
|
upAdapter() |
|
|
|
} |
|
|
|
|
|
|
|
.onFinally { |
|
|
|
|
|
|
|
synchronized(this) { |
|
|
|
|
|
|
|
if (searchIndex < bookSourceList.lastIndex) { |
|
|
|
|
|
|
|
search() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
searchIndex++ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (searchIndex >= bookSourceList.lastIndex + min(bookSourceList.size, |
|
|
|
|
|
|
|
threadCount) |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
searchStateData.postValue(false) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
tasks.add(task) |
|
|
|
} |
|
|
|
|
|
|
|
.onFinally { |
|
|
|
|
|
|
|
searchNext() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
tasks.add(task) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Synchronized |
|
|
|
|
|
|
|
private fun searchNext() { |
|
|
|
|
|
|
|
if (searchIndex < bookSourceList.lastIndex) { |
|
|
|
|
|
|
|
search() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
searchIndex++ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (searchIndex >= bookSourceList.lastIndex + min( |
|
|
|
|
|
|
|
bookSourceList.size, |
|
|
|
|
|
|
|
threadCount |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
searchStateData.postValue(false) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|