Skip to content

Commit

Permalink
master - removed custom state mapping.
Browse files Browse the repository at this point in the history
  • Loading branch information
masterwok committed Aug 6, 2018
1 parent 583c06c commit 6ab95e3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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" +
Expand All @@ -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 }
}
}
}

0 comments on commit 6ab95e3

Please sign in to comment.