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 netResponse = authClient.newCall(request).execute()
val response = responseToJson(netResponse) 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) } val entries = media.map { jsonToALManga(it.obj) }
entries.map { it.toTrack() } entries.map { it.toTrack() }
} }

View File

@ -1,8 +1,6 @@
package eu.kanade.tachiyomi.data.updater package eu.kanade.tachiyomi.data.updater
import eu.kanade.tachiyomi.BuildConfig
import eu.kanade.tachiyomi.data.updater.github.GithubUpdateChecker import eu.kanade.tachiyomi.data.updater.github.GithubUpdateChecker
import rx.Observable
abstract class UpdateChecker { 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 com.evernote.android.job.JobRequest
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.data.notification.Notifications
import java.util.concurrent.TimeUnit
import eu.kanade.tachiyomi.util.system.notificationManager 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() { class UpdaterJob : Job() {
override fun onRunJob(params: Params): Result { override fun onRunJob(params: Params): Result {
return UpdateChecker.getUpdateChecker() GlobalScope.launch(Dispatchers.IO) {
.checkForUpdate() val result = try { UpdateChecker.getUpdateChecker().checkForUpdate() }
.map { result -> catch (e: Exception) { return@launch }
if (result is UpdateResult.NewUpdate<*>) { if (result is UpdateResult.NewUpdate<*>) {
val url = result.release.downloadLink val url = result.release.downloadLink
val intent = Intent(context, UpdaterService::class.java).apply { val intent = Intent(context, UpdaterService::class.java).apply {
putExtra(UpdaterService.EXTRA_DOWNLOAD_URL, url) 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
} }
.onErrorReturn { Result.FAILURE }
// Sadly, the task needs to be synchronous. NotificationCompat.Builder(context, Notifications.CHANNEL_COMMON).update {
.toBlocking() setContentTitle(context.getString(R.string.app_name))
.single() 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) { 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.BuildConfig
import eu.kanade.tachiyomi.data.updater.UpdateChecker import eu.kanade.tachiyomi.data.updater.UpdateChecker
import eu.kanade.tachiyomi.data.updater.UpdateResult import eu.kanade.tachiyomi.data.updater.UpdateResult
import rx.Observable
class GithubUpdateChecker : UpdateChecker() { class GithubUpdateChecker : UpdateChecker() {
private val service: GithubService = GithubService.create() private val service: GithubService = GithubService.create()
override fun checkForUpdate(): Observable<UpdateResult> { override suspend fun checkForUpdate(): UpdateResult {
return service.getLatestVersion().map { release -> val release = service.getLatestVersion()
val newVersion = release.version.replace("[^\\d.]".toRegex(), "") val newVersion = release.version.replace("[^\\d.]".toRegex(), "")
// Check if latest version is different from current version // Check if latest version is different from current version
if (newVersion != BuildConfig.VERSION_NAME) { return if (newVersion != BuildConfig.VERSION_NAME) {
GithubUpdateResult.NewUpdate(release) GithubUpdateResult.NewUpdate(release)
} else { } else {
GithubUpdateResult.NoNewUpdate() GithubUpdateResult.NoNewUpdate()
}
} }
} }

View File

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

View File

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

View File

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