Fix #636. Minor improvements. Dependency updates

This commit is contained in:
len 2017-02-23 22:30:43 +01:00
parent 6de260d73f
commit 4d7b188999
11 changed files with 61 additions and 130 deletions

View file

@ -102,7 +102,7 @@ dependencies {
compile 'com.github.inorichi:junrar-android:634c1f5'
// Android support library
final support_library_version = '25.1.1'
final support_library_version = '25.2.0'
compile "com.android.support:support-v4:$support_library_version"
compile "com.android.support:appcompat-v7:$support_library_version"
compile "com.android.support:cardview-v7:$support_library_version"
@ -111,7 +111,7 @@ dependencies {
compile "com.android.support:support-annotations:$support_library_version"
compile "com.android.support:customtabs:$support_library_version"
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
compile 'com.android.support.constraint:constraint-layout:1.0.0'
compile 'com.android.support:multidex:1.0.1'
@ -127,7 +127,7 @@ dependencies {
compile 'com.squareup.okio:okio:1.11.0'
// REST
final retrofit_version = '2.1.0'
final retrofit_version = '2.2.0'
compile "com.squareup.retrofit2:retrofit:$retrofit_version"
compile "com.squareup.retrofit2:converter-gson:$retrofit_version"
compile "com.squareup.retrofit2:adapter-rxjava:$retrofit_version"
@ -151,13 +151,13 @@ dependencies {
// Job scheduling
compile 'com.evernote:android-job:1.1.6'
compile 'com.google.android.gms:play-services-gcm:10.0.1'
compile 'com.google.android.gms:play-services-gcm:10.2.0'
// Changelog
compile 'com.github.gabrielemariotti.changeloglib:changelog:2.1.0'
// Database
compile "com.pushtorefresh.storio:sqlite:1.12.2"
compile "com.pushtorefresh.storio:sqlite:1.12.3"
// Model View Presenter
final nucleus_version = '3.0.0'

View file

@ -98,9 +98,6 @@
android:name=".data.download.DownloadService"
android:exported="false" />
<service
android:name=".data.track.TrackUpdateService"
android:exported="false" />
<service
android:name=".data.updater.UpdateDownloaderService"
android:exported="false" />

View file

@ -22,8 +22,6 @@ interface Track : Serializable {
var status: Int
var update: Boolean
fun copyPersonalFrom(other: Track) {
last_chapter_read = other.last_chapter_read
score = other.score

View file

@ -20,8 +20,6 @@ class TrackImpl : Track {
override var status: Int = 0
override var update: Boolean = false
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || javaClass != other.javaClass) return false

View file

@ -1,74 +0,0 @@
package eu.kanade.tachiyomi.data.track
import android.app.Service
import android.content.Context
import android.content.Intent
import android.os.IBinder
import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.database.models.Track
import rx.Observable
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import rx.subscriptions.CompositeSubscription
import uy.kohesive.injekt.injectLazy
class TrackUpdateService : Service() {
val trackManager: TrackManager by injectLazy()
val db: DatabaseHelper by injectLazy()
private lateinit var subscriptions: CompositeSubscription
override fun onCreate() {
super.onCreate()
subscriptions = CompositeSubscription()
}
override fun onDestroy() {
subscriptions.unsubscribe()
super.onDestroy()
}
override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
val track = intent.getSerializableExtra(EXTRA_TRACK)
if (track != null) {
updateLastChapterRead(track as Track, startId)
return Service.START_REDELIVER_INTENT
} else {
stopSelf(startId)
return Service.START_NOT_STICKY
}
}
override fun onBind(intent: Intent): IBinder? {
return null
}
private fun updateLastChapterRead(track: Track, startId: Int) {
val sync = trackManager.getService(track.sync_id)
if (sync == null) {
stopSelf(startId)
return
}
subscriptions.add(Observable.defer { sync.update(track) }
.flatMap { db.insertTrack(track).asRxObservable() }
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ stopSelf(startId) },
{ stopSelf(startId) }))
}
companion object {
private val EXTRA_TRACK = "extra_track"
@JvmStatic
fun start(context: Context, track: Track) {
val intent = Intent(context, TrackUpdateService::class.java)
intent.putExtra(EXTRA_TRACK, track)
context.startService(intent)
}
}
}

View file

@ -45,7 +45,7 @@ class TrackFragment : BaseRxFragment<TrackPresenter>() {
private fun findSearchFragmentIfNeeded() {
if (dialog == null) {
dialog = childFragmentManager.findFragmentByTag(searchFragmentTag) as TrackSearchDialog
dialog = childFragmentManager.findFragmentByTag(searchFragmentTag) as? TrackSearchDialog
}
}

View file

@ -171,11 +171,11 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
.content(getString(R.string.confirm_update_manga_sync, chapterToUpdate))
.positiveText(android.R.string.yes)
.negativeText(android.R.string.no)
.onPositive { dialog, which -> presenter.updateTrackLastChapterRead() }
.onPositive { dialog, which -> presenter.updateTrackLastChapterRead(chapterToUpdate) }
.onAny { dialog1, which1 -> super.onBackPressed() }
.show()
} else {
presenter.updateTrackLastChapterRead()
presenter.updateTrackLastChapterRead(chapterToUpdate)
super.onBackPressed()
}
} else {

View file

@ -14,7 +14,6 @@ import eu.kanade.tachiyomi.data.database.models.Track
import eu.kanade.tachiyomi.data.download.DownloadManager
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.data.track.TrackUpdateService
import eu.kanade.tachiyomi.source.LocalSource
import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.model.Page
@ -452,27 +451,31 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
Math.floor(chapter.chapter_number.toDouble()).toInt()
else if (prevChapter != null && prevChapter.read)
Math.floor(prevChapter.chapter_number.toDouble()).toInt()
else
return 0
return if (trackList.any { lastChapterRead > it.last_chapter_read })
lastChapterRead
else
0
trackList.forEach { sync ->
if (lastChapterRead > sync.last_chapter_read) {
sync.last_chapter_read = lastChapterRead
sync.update = true
}
}
return if (trackList.any { it.update }) lastChapterRead else 0
}
/**
* Starts the service that updates the last chapter read in sync services
*/
fun updateTrackLastChapterRead() {
trackList?.forEach { sync ->
val service = trackManager.getService(sync.sync_id)
if (service != null && service.isLogged && sync.update) {
TrackUpdateService.start(context, sync)
fun updateTrackLastChapterRead(lastChapterRead: Int) {
trackList?.forEach { track ->
val service = trackManager.getService(track.sync_id)
if (service != null && service.isLogged && lastChapterRead > track.last_chapter_read) {
track.last_chapter_read = lastChapterRead
// We wan't these to execute even if the presenter is destroyed and leaks for a
// while. The view can still be garbage collected.
Observable.defer { service.update(track) }
.map { db.insertTrack(track).executeAsBlocking() }
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({}, { Timber.e(it) })
}
}
}

View file

@ -1,9 +1,10 @@
package eu.kanade.tachiyomi.ui.recent_updates
import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.IFlexible
class RecentChaptersAdapter(val fragment: RecentChaptersFragment) :
FlexibleAdapter<RecentChapterItem>(null, fragment, true) {
FlexibleAdapter<IFlexible<*>>(null, fragment, true) {
init {
setDisplayHeadersAtStartUp(true)

View file

@ -9,6 +9,7 @@ import android.support.v7.widget.RecyclerView
import android.view.*
import com.afollestad.materialdialogs.MaterialDialog
import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.download.model.Download
import eu.kanade.tachiyomi.data.library.LibraryUpdateService
@ -116,7 +117,7 @@ class RecentChaptersFragment:
* @return list of selected chapters
*/
fun getSelectedChapters(): List<RecentChapterItem> {
return adapter.selectedPositions.mapNotNull { adapter.getItem(it) }
return adapter.selectedPositions.mapNotNull { adapter.getItem(it) as? RecentChapterItem }
}
/**
@ -125,7 +126,7 @@ class RecentChaptersFragment:
*/
override fun onItemClick(position: Int): Boolean {
// Get item from position
val item = adapter.getItem(position)
val item = adapter.getItem(position) as? RecentChapterItem ?: return false
if (actionMode != null && adapter.mode == FlexibleAdapter.MODE_MULTI) {
toggleSelection(position)
return true
@ -183,7 +184,7 @@ class RecentChaptersFragment:
* Populate adapter with chapters
* @param chapters list of [Any]
*/
fun onNextRecentChapters(chapters: List<RecentChapterItem>) {
fun onNextRecentChapters(chapters: List<IFlexible<*>>) {
(activity as MainActivity).updateEmptyView(chapters.isEmpty(),
R.string.information_no_recent, R.drawable.ic_update_black_128dp)
@ -291,6 +292,8 @@ class RecentChaptersFragment:
* @param item item from ActionMode.
*/
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
if (!isAdded) return true
when (item.itemId) {
R.id.action_mark_as_read -> markAsRead(getSelectedChapters())
R.id.action_mark_as_unread -> markAsUnread(getSelectedChapters())

View file

@ -28,7 +28,7 @@
</FrameLayout>
<RelativeLayout
<LinearLayout
android:id="@+id/title_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -48,14 +48,16 @@
<TextView
android:id="@+id/track_title"
style="@style/TextAppearance.Medium.Button"
android:textColor="?colorAccent"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:gravity="end"
android:maxLines="1"
android:ellipsize="middle"
android:text="@string/action_edit" />
</RelativeLayout>
</LinearLayout>
<View
android:id="@+id/divider1"
@ -70,7 +72,7 @@
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp" />
<RelativeLayout
<LinearLayout
android:id="@+id/status_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -90,13 +92,14 @@
<TextView
android:id="@+id/track_status"
style="@style/TextAppearance.Regular.Body1.Secondary"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:gravity="end"
tools:text="Reading" />
</RelativeLayout>
</LinearLayout>
<View
android:id="@+id/divider2"
@ -111,7 +114,7 @@
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp" />
<RelativeLayout
<LinearLayout
android:id="@+id/chapters_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -131,13 +134,14 @@
<TextView
android:id="@+id/track_chapters"
style="@style/TextAppearance.Regular.Body1.Secondary"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:gravity="end"
tools:text="12/24" />
</RelativeLayout>
</LinearLayout>
<View
android:id="@+id/divider3"
@ -152,7 +156,7 @@
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp" />
<RelativeLayout
<LinearLayout
android:id="@+id/score_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -172,13 +176,14 @@
<TextView
android:id="@+id/track_score"
style="@style/TextAppearance.Regular.Body1.Secondary"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:gravity="end"
tools:text="10" />
</RelativeLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>