Fixing conlficts and build

Fixed searching in Anilist
This commit is contained in:
Jay 2020-03-15 15:04:20 -07:00
parent 6ab222bdc8
commit 2e4af629c6
7 changed files with 83 additions and 95 deletions

View File

@ -88,7 +88,7 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) {
val netResponse = authClient.newCall(request).execute()
val response = responseToJson(netResponse)
val media = response["data"]!!.obj["Page"].obj["mediaList"].array
val media = response["data"]!!.obj["Page"].obj["media"].array
val entries = media.map { jsonToALManga(it.obj) }
entries.map { it.toTrack() }
}

View File

@ -1,8 +1,6 @@
package eu.kanade.tachiyomi.data.updater
import eu.kanade.tachiyomi.BuildConfig
import eu.kanade.tachiyomi.data.updater.github.GithubUpdateChecker
import rx.Observable
abstract class UpdateChecker {
@ -11,8 +9,8 @@ abstract class UpdateChecker {
}
/**
* Returns observable containing release information
* Returns suspended result containing release information
*/
abstract fun checkForUpdate(): Observable<UpdateResult>
abstract suspend fun checkForUpdate(): UpdateResult
}

View File

@ -9,39 +9,46 @@ import com.evernote.android.job.JobManager
import com.evernote.android.job.JobRequest
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.notification.Notifications
import java.util.concurrent.TimeUnit
import eu.kanade.tachiyomi.util.system.notificationManager
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import java.util.concurrent.TimeUnit
class UpdaterJob : Job() {
override fun onRunJob(params: Params): Result {
return UpdateChecker.getUpdateChecker()
.checkForUpdate()
.map { result ->
if (result is UpdateResult.NewUpdate<*>) {
val url = result.release.downloadLink
GlobalScope.launch(Dispatchers.IO) {
val result = try { UpdateChecker.getUpdateChecker().checkForUpdate() }
catch (e: Exception) { return@launch }
if (result is UpdateResult.NewUpdate<*>) {
val url = result.release.downloadLink
val intent = Intent(context, UpdaterService::class.java).apply {
putExtra(UpdaterService.EXTRA_DOWNLOAD_URL, url)
}
NotificationCompat.Builder(context, Notifications.CHANNEL_COMMON).update {
setContentTitle(context.getString(R.string.app_name))
setContentText(context.getString(R.string.update_check_notification_update_available))
setSmallIcon(android.R.drawable.stat_sys_download_done)
color = ContextCompat.getColor(context, R.color.colorAccent)
// Download action
addAction(android.R.drawable.stat_sys_download_done,
context.getString(R.string.action_download),
PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT))
}
}
Result.SUCCESS
val intent = Intent(context, UpdaterService::class.java).apply {
putExtra(UpdaterService.EXTRA_DOWNLOAD_URL, url)
}
.onErrorReturn { Result.FAILURE }
// Sadly, the task needs to be synchronous.
.toBlocking()
.single()
NotificationCompat.Builder(context, Notifications.CHANNEL_COMMON).update {
setContentTitle(context.getString(R.string.app_name))
setContentText(context.getString(R.string.update_check_notification_update_available))
setSmallIcon(android.R.drawable.stat_sys_download_done)
color = ContextCompat.getColor(context, R.color.colorAccent)
// Download action
addAction(
android.R.drawable.stat_sys_download_done,
context.getString(R.string.action_download),
PendingIntent.getService(
context,
0,
intent,
PendingIntent.FLAG_UPDATE_CURRENT
)
)
}
}
Result.SUCCESS
}
return Result.SUCCESS
}
fun NotificationCompat.Builder.update(block: NotificationCompat.Builder.() -> Unit) {

View File

@ -3,22 +3,20 @@ package eu.kanade.tachiyomi.data.updater.github
import eu.kanade.tachiyomi.BuildConfig
import eu.kanade.tachiyomi.data.updater.UpdateChecker
import eu.kanade.tachiyomi.data.updater.UpdateResult
import rx.Observable
class GithubUpdateChecker : UpdateChecker() {
class GithubUpdateChecker : UpdateChecker() {
private val service: GithubService = GithubService.create()
override fun checkForUpdate(): Observable<UpdateResult> {
return service.getLatestVersion().map { release ->
val newVersion = release.version.replace("[^\\d.]".toRegex(), "")
override suspend fun checkForUpdate(): UpdateResult {
val release = service.getLatestVersion()
val newVersion = release.version.replace("[^\\d.]".toRegex(), "")
// Check if latest version is different from current version
if (newVersion != BuildConfig.VERSION_NAME) {
GithubUpdateResult.NewUpdate(release)
} else {
GithubUpdateResult.NoNewUpdate()
}
// Check if latest version is different from current version
return if (newVersion != BuildConfig.VERSION_NAME) {
GithubUpdateResult.NewUpdate(release)
} else {
GithubUpdateResult.NoNewUpdate()
}
}

View File

@ -54,11 +54,7 @@ class MangaDetailsPresenter(private val controller: MangaDetailsController,
DownloadQueue.DownloadListener,
LibraryServiceListener {
<<<<<<< Updated upstream
private var scope = CoroutineScope(Job() + Dispatchers.Default)
=======
var scope = CoroutineScope(Job() + Dispatchers.Default)
>>>>>>> Stashed changes
var isLockedFromSearch = false
var hasRequested = false
@ -715,17 +711,15 @@ class MangaDetailsPresenter(private val controller: MangaDetailsController,
fun trackSearch(query: String, service: TrackService) {
scope.launch(Dispatchers.IO) {
<<<<<<< Updated upstream
val results = try {service.search(query) }
=======
val results = try {service.search(query).toBlocking().single() }
>>>>>>> Stashed changes
catch (e: Exception) {
val results = try {
service.search(query)
} catch (e: Exception) {
withContext(Dispatchers.Main) { controller.trackSearchError(e) }
null }
if (!results.isNullOrEmpty()) {
withContext(Dispatchers.Main) { controller.onTrackSearchResults(results) }
}
null
}
if (!results.isNullOrEmpty()) {
withContext(Dispatchers.Main) { controller.onTrackSearchResults(results) }
}
}
}
@ -734,11 +728,7 @@ class MangaDetailsPresenter(private val controller: MangaDetailsController,
item.manga_id = manga.id!!
scope.launch {
<<<<<<< Updated upstream
val binding = try { service.bind(item) }
=======
val binding = try { service.bind(item).toBlocking().single() }
>>>>>>> Stashed changes
catch (e: Exception) {
trackError(e)
null
@ -758,11 +748,7 @@ class MangaDetailsPresenter(private val controller: MangaDetailsController,
private fun updateRemote(track: Track, service: TrackService) {
scope.launch {
<<<<<<< Updated upstream
val binding = try { service.update(track) }
=======
val binding = try { service.update(track).toBlocking().single() }
>>>>>>> Stashed changes
catch (e: Exception) {
trackError(e)
null

View File

@ -95,6 +95,7 @@ class TrackingBottomSheet(private val controller: MangaDetailsController) : Bott
fun onSearchResultsError(error: Throwable) {
Timber.e(error)
activity.toast(error.message)
getSearchDialog()?.onSearchResultsError()
}

View File

@ -4,7 +4,6 @@ import android.app.Dialog
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.View
import androidx.preference.PreferenceScreen
import com.afollestad.materialdialogs.MaterialDialog
import eu.kanade.tachiyomi.BuildConfig
@ -16,11 +15,13 @@ import eu.kanade.tachiyomi.data.updater.UpdateResult
import eu.kanade.tachiyomi.data.updater.UpdaterService
import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.ui.main.ChangelogDialogController
import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.util.lang.toTimestampString
import rx.Subscription
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import eu.kanade.tachiyomi.util.system.toast
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import timber.log.Timber
import uy.kohesive.injekt.injectLazy
import java.text.DateFormat
@ -43,7 +44,7 @@ class SettingsAboutController : SettingsController() {
/**
* The subscribtion service of the obtained release object
*/
private var releaseSubscription: Subscription? = null
private val scope = CoroutineScope(Job() + Dispatchers.IO)
private val isUpdaterEnabled = BuildConfig.INCLUDE_UPDATER
@ -95,12 +96,6 @@ class SettingsAboutController : SettingsController() {
}
}
override fun onDestroyView(view: View) {
super.onDestroyView(view)
releaseSubscription?.unsubscribe()
releaseSubscription = null
}
/**
* Checks version and shows a user prompt if an update is available.
*/
@ -108,27 +103,30 @@ class SettingsAboutController : SettingsController() {
if (activity == null) return
activity?.toast(R.string.update_check_look_for_updates)
releaseSubscription?.unsubscribe()
releaseSubscription = updateChecker.checkForUpdate()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ result ->
when (result) {
is UpdateResult.NewUpdate<*> -> {
val body = result.release.info
val url = result.release.downloadLink
scope.launch {
val result = try {
updateChecker.checkForUpdate()
} catch (error: Exception) {
activity?.toast(error.message)
Timber.e(error)
}
when (result) {
is UpdateResult.NewUpdate<*> -> {
val body = result.release.info
val url = result.release.downloadLink
// Create confirmation window
NewUpdateDialogController(body, url).showDialog(router)
}
is UpdateResult.NoNewUpdate -> {
activity?.toast(R.string.update_check_no_new_updates)
}
// Create confirmation window
withContext(Dispatchers.Main) {
NewUpdateDialogController(body, url).showDialog(router)
}
}, { error ->
activity?.toast(error.message)
Timber.e(error)
})
}
is UpdateResult.NoNewUpdate -> {
withContext(Dispatchers.Main) {
activity?.toast(R.string.update_check_no_new_updates)
}
}
}
}
}
class NewUpdateDialogController(bundle: Bundle? = null) : DialogController(bundle) {