From 6ab95e3e099783c8983f74cdcd9823735c3c95af Mon Sep 17 00:00:00 2001 From: Jonathan Trowbridge Date: Mon, 6 Aug 2018 16:07:27 -0400 Subject: [PATCH] master - removed custom state mapping. --- .../fragments/TorrentFragment.kt | 5 ++-- .../models/TorrentSessionStatus.kt | 30 ++----------------- 2 files changed, 5 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/com/masterwok/demosimpletorrentandroid/fragments/TorrentFragment.kt b/app/src/main/java/com/masterwok/demosimpletorrentandroid/fragments/TorrentFragment.kt index 5c649e7..892594c 100644 --- a/app/src/main/java/com/masterwok/demosimpletorrentandroid/fragments/TorrentFragment.kt +++ b/app/src/main/java/com/masterwok/demosimpletorrentandroid/fragments/TorrentFragment.kt @@ -11,6 +11,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import com.frostwire.jlibtorrent.TorrentHandle +import com.frostwire.jlibtorrent.TorrentStatus import com.masterwok.demosimpletorrentandroid.R import com.masterwok.demosimpletorrentandroid.adapters.TabFragmentPagerAdapter import com.masterwok.simpletorrentandroid.TorrentSession @@ -162,13 +163,13 @@ class TorrentFragment : Fragment() ) = configure("onMetadataReceived", torrentSessionStatus) private fun setPauseResumeButtonText() { - if (torrentSessionStatus?.state == TorrentSessionStatus.State.SEEDING) { + if (torrentSessionStatus?.state == TorrentStatus.State.SEEDING) { buttonPauseResume?.setText(R.string.button_seeding) buttonPauseResume?.isEnabled = false return } - if (torrentSessionStatus?.state == TorrentSessionStatus.State.FINISHED) { + if (torrentSessionStatus?.state == TorrentStatus.State.FINISHED) { buttonPauseResume?.setText(R.string.button_finished) buttonPauseResume?.isEnabled = false return diff --git a/simpletorrentandroid/src/main/java/com/masterwok/simpletorrentandroid/models/TorrentSessionStatus.kt b/simpletorrentandroid/src/main/java/com/masterwok/simpletorrentandroid/models/TorrentSessionStatus.kt index 3b677b3..5978749 100644 --- a/simpletorrentandroid/src/main/java/com/masterwok/simpletorrentandroid/models/TorrentSessionStatus.kt +++ b/simpletorrentandroid/src/main/java/com/masterwok/simpletorrentandroid/models/TorrentSessionStatus.kt @@ -13,7 +13,7 @@ import com.masterwok.simpletorrentandroid.extensions.* @Suppress("unused", "MemberVisibilityCanBePrivate") class TorrentSessionStatus private constructor( val torrentUri: Uri - , val state: State + , val state: TorrentStatus.State , val seederCount: Int , val downloadRate: Int , val uploadRate: Int @@ -33,7 +33,7 @@ class TorrentSessionStatus private constructor( , largestFileUri: Uri ): TorrentSessionStatus = TorrentSessionStatus( torrentUri - , torrentHandle.status().state().toTorrentStreamStatusSate() + , torrentHandle.status().state() , torrentHandle.getSeederCount() , torrentHandle.getDownloadRate() , torrentHandle.getUploadRate() @@ -44,17 +44,6 @@ class TorrentSessionStatus private constructor( , largestFileUri , torrentSessionBuffer ) - - private fun TorrentStatus.State.toTorrentStreamStatusSate(): State = when (this) { - TorrentStatus.State.CHECKING_FILES -> State.CHECKING_FILES - TorrentStatus.State.DOWNLOADING_METADATA -> State.DOWNLOADING_METADATA - TorrentStatus.State.DOWNLOADING -> State.DOWNLOADING - TorrentStatus.State.FINISHED -> State.FINISHED - TorrentStatus.State.SEEDING -> State.SEEDING - TorrentStatus.State.ALLOCATING -> State.ALLOCATING - TorrentStatus.State.CHECKING_RESUME_DATA -> State.CHECKING_RESUME_DATA - TorrentStatus.State.UNKNOWN -> State.UNKNOWN - } } override fun toString(): String = "State: $state" + @@ -66,20 +55,5 @@ class TorrentSessionStatus private constructor( ", Torrent Uri: $torrentUri" + ", Save Location: $saveLocationUri" + ", Video File: $videoFileUri" - - enum class State(val value: Int) { - UNKNOWN(-1), - CHECKING_FILES(0), - DOWNLOADING_METADATA(1), - DOWNLOADING(2), - FINISHED(3), - SEEDING(4), - ALLOCATING(5), - CHECKING_RESUME_DATA(6); - - companion object { - fun valueOf(value: Int): State = State.values().first { it.value == value } - } - } }