Skip to content

Commit

Permalink
[Bump + Fixed] Preparing for release & Fixed some crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
KaustubhPatange committed Jun 6, 2022
1 parent 81c2197 commit a6f3d14
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.kpstv.common_moviesy.extensions
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle

fun Fragment.colorFrom(@ColorRes color: Int) = requireContext().colorFrom(color)

Expand All @@ -13,4 +14,6 @@ fun Fragment.rootParentFragment(): Fragment {
return fragment?.rootParentFragment() ?: this
}

fun Fragment.toPx(dp: Float) : Int = requireContext().toPx(dp)
fun Fragment.toPx(dp: Float) : Int = requireContext().toPx(dp)

fun Fragment.isViewDestroying(): Boolean = viewLifecycleOwner.lifecycle.currentState == Lifecycle.State.DESTROYED
25 changes: 17 additions & 8 deletions app/src/main/java/com/kpstv/yts/services/DownloadService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import android.os.PowerManager.WakeLock
import android.text.Html
import android.util.Log
import androidx.core.app.NotificationCompat
import androidx.lifecycle.ViewModelProvider
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.github.se_bastiaan.torrentstream.StreamStatus
import com.github.se_bastiaan.torrentstream.TorrentOptions
import com.github.se_bastiaan.torrentstream.TorrentStream
import com.github.se_bastiaan.torrentstream.listeners.TorrentListener
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.google.gson.Gson
import com.kpstv.common_moviesy.extensions.utils.FileUtils
import com.kpstv.yts.AppInterface.Companion.ANONYMOUS_TORRENT_DOWNLOAD
Expand All @@ -33,7 +33,6 @@ import com.kpstv.yts.AppInterface.Companion.STORAGE_LOCATION
import com.kpstv.yts.AppInterface.Companion.TORRENT_NOT_SUPPORTED
import com.kpstv.yts.AppInterface.Companion.formatDownloadSpeed
import com.kpstv.yts.R
import com.kpstv.yts.adapters.HistoryModel
import com.kpstv.yts.data.db.repository.DownloadRepository
import com.kpstv.yts.data.db.repository.PauseRepository
import com.kpstv.yts.data.models.Torrent
Expand All @@ -44,7 +43,6 @@ import com.kpstv.yts.extensions.utils.AppUtils.Companion.getVideoDuration
import com.kpstv.yts.extensions.utils.AppUtils.Companion.saveImageFromUrl
import com.kpstv.yts.receivers.CommonBroadCast
import com.kpstv.yts.ui.activities.DownloadActivity
import com.kpstv.yts.ui.viewmodels.MainViewModel
import dagger.hilt.android.AndroidEntryPoint
import java.io.File
import java.text.SimpleDateFormat
Expand All @@ -71,6 +69,7 @@ class DownloadService : IntentService("blank") {
private var pendingJobs = ArrayList<Torrent>()
private var currentModel: com.github.se_bastiaan.torrentstream.Torrent? = null
private var currentTorrentModel: Torrent? = null
private var currentTorrentStreamData: TorrentStreamData? = null
private lateinit var context: Context
private var wakeLock: WakeLock? = null
private lateinit var notificationManager: NotificationManager
Expand All @@ -84,6 +83,8 @@ class DownloadService : IntentService("blank") {

private val SHOW_LOG_FROM_THIS_CLASS = true

data class TorrentStreamData(val saveLocation: File?, val videoFile: File?)

init {
setIntentRedelivery(true)
}
Expand Down Expand Up @@ -230,6 +231,7 @@ class DownloadService : IntentService("blank") {
override fun onStreamPrepared(torrent: com.github.se_bastiaan.torrentstream.Torrent?) {
updateNotification(model, torrent, true)
currentModel = torrent
currentTorrentStreamData = TorrentStreamData(torrent?.saveLocation, torrent?.videoFile)
DS_LOG("=> Preparing Job: ${torrent?.saveLocation}")
lastProgress = 0f
totalGap = getCurrentTimeSecond()
Expand All @@ -246,6 +248,7 @@ class DownloadService : IntentService("blank") {
}

override fun onStreamStarted(torrent: com.github.se_bastiaan.torrentstream.Torrent?) {
currentModel = torrent
DS_LOG("=> Stream Started")
}

Expand Down Expand Up @@ -310,6 +313,7 @@ class DownloadService : IntentService("blank") {
private fun onClear() {
currentModel = null
currentTorrentModel = null
currentTorrentStreamData = null
}

fun updateNotification(
Expand Down Expand Up @@ -420,33 +424,36 @@ class DownloadService : IntentService("blank") {
try {
if (!isError) {

val saveLocation = currentTorrentStreamData?.saveLocation ?: currentModel?.saveLocation
val videoFile = currentTorrentStreamData?.videoFile ?: currentModel?.videoFile

/** Save details of file in database. */
val imagePath = File(currentModel?.saveLocation, "banner.png")
val imagePath = File(saveLocation, "banner.png")
saveImageFromUrl(model.banner_url, imagePath)

val todayDate = SimpleDateFormat("yyyy-MM-dd")
.format(Calendar.getInstance().time)

val movieSize = getVideoDuration(this, currentModel?.videoFile!!)
val movieSize = getVideoDuration(this, videoFile!!)
.takeUnless { it == null } ?: 0L

val downloadResponse = Model.response_download(
title = model.title,
imagePath = imagePath.path,
downloadPath = currentModel?.saveLocation?.path,
downloadPath = saveLocation?.path,
size = model.size,
date_downloaded = todayDate,
hash = model.hash,
total_video_length = movieSize,
videoPath = currentModel?.videoFile?.path,
videoPath = videoFile.path,
movieId = currentTorrentModel?.movieId,
imdbCode = currentTorrentModel?.imdbCode
)

downloadRepository.saveDownload(downloadResponse)

/** Save a detail.json file. */
val detailPath = File(currentModel?.saveLocation, "details.json")
val detailPath = File(saveLocation, "details.json")
detailPath.writeText(Gson().toJson(downloadResponse))

/** Send download complete notification */
Expand All @@ -457,6 +464,8 @@ class DownloadService : IntentService("blank") {
}
} catch (e: Exception) {
/** Something unexpected occurred. */
e.printStackTrace()
FirebaseCrashlytics.getInstance().recordException(e)
Log.e(TAG, "Download failed for ${model.title} due to ${e.message}", e)
Notifications.sendDownloadFailedNotification(this, model.title)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ class LibraryFragment : ValueFragment(R.layout.fragment_library), FragmentNaviga
val f = File(model.downloadPath!!)
if (f.exists()) {
f.deleteRecursive()
viewModel.removeDownload(model.hash)
} else {
Toasty.error(requireContext(), getString(R.string.error_path_exist), Toasty.LENGTH_SHORT).show()
}
viewModel.removeDownload(model.hash)
}
}.show()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.widget.TextView
import androidx.core.view.isVisible
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.Observer
import androidx.paging.PagedList
import androidx.recyclerview.widget.GridLayoutManager
Expand Down Expand Up @@ -125,6 +126,7 @@ class SearchFragment : ValueFragment(R.layout.fragment_search) {
}

override fun onViewStateChanged(viewState: ViewState) {
if (isViewDestroying()) return
if (viewState == ViewState.FOREGROUND) {
binding.searchEditText.showKeyboard()
binding.itemClose.hide()
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/res/raw/changelog.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
{
"version": "2.0.5",
"version": "2.0.6",
"summary": [
"<br/><h4>Added:</h4><br/>",
"• Option to share link to subtitles.<br/>",
"• Way to restore purchase through PayPal transaction ID.<br/>",
"• Support for Large screen devices (enabled rotation).<br/>",
"<br/><h4>Fixed:</h4><br/>",
"• Crash when app is launched with no internet connection.<br/>"
"• Issue where subtitles are not downloading.<br/>",
"• Attempt to fix crash due to initialization of Google Play services.<br/>",
"• Crash when app is closed when Search screen is opened.<br/>",
"• Silent crash where torrent movie download was failing.<br/>",
"• Issues with activating purchase while restoring.<br/>"
]
}
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/AndroidConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ object AndroidConfig {

// TODO: Always change version code & name during release
const val VERSION_CODE = 17
const val VERSION_NAME = "2.0.5"
const val VERSION_NAME = "2.0.6"

const val ID = "com.kpstv.yts"
// const val TEST_INSTRUMENTATION_RUNNER = "android.support.test.runner.AndroidJUnitRunner"
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/GradleDependency.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
private object GradlePluginVersion {
const val KOTLIN = CoreVersion.KOTLIN
const val ANDROID_GRADLE = "4.1.1"
const val GOOGLE_SERVICE = "4.3.8"
const val GOOGLE_SERVICE = "4.3.10"
const val SAFE_ARGS = CoreVersion.JETPACK_NAVIGATION
const val HILT = "2.33-beta"
const val CRASHLYTICS = "2.4.1"
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/LibraryDependency.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private object LibraryVersion {
const val GUAVA_CONFLICT = "9999.0-empty-to-avoid-conflict-with-guava"
const val CAOC = "2.3.0"
const val FIREBASE_AUTH = "19.3.2"
const val FIREBASE_BOM = "26.1.0"
const val FIREBASE_BOM = "30.0.0"
const val AUTOBINDINGS = "1.1-alpha16"
const val APP_STARTUP = "1.0.0"
const val IMAGELOADERVIEW = "0.7-beta04"
Expand Down

0 comments on commit a6f3d14

Please sign in to comment.