Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
Watcher TV v2.11 (#49)
Browse files Browse the repository at this point in the history
* Develop/remove background (#46)

* Remove blurred background, added new preview

* Disabled update; fixed clearing of token when refresh token request failed due to network error

* Updated version code and name; Updated release notes

* Updated disabled update manager message

* Fix/preview gradient (#47)

* Fix image preview gradient

* Increment version code

* Develop/update from browser (#48)

* Use external browser for updates

* Updated preview gradient borders
  • Loading branch information
janjanmedinaaa authored Mar 10, 2023
1 parent 9233ec9 commit b9fed6f
Show file tree
Hide file tree
Showing 15 changed files with 135 additions and 55 deletions.
13 changes: 12 additions & 1 deletion .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Watcher v2.10.2
# Watcher v2.11

## Bug Fix
- Updated API Header `versioncode` to 33
## What's new
- Removed blurred background
- Added new image preview
- Disabled in-app updater. Uses external browser from now on.

## Bug fix
- Fixed logging out when refresh token request fails due to network error
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ android {
applicationId "com.medina.juanantonio.watcher"
minSdk 21
targetSdk 33
versionCode 29
versionName "2.10.2"
versionCode 32
versionName "2.11"

javaCompileOptions {
annotationProcessorOptions {
Expand Down
36 changes: 15 additions & 21 deletions app/src/main/java/com/medina/juanantonio/watcher/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package com.medina.juanantonio.watcher

import android.Manifest.permission.WRITE_EXTERNAL_STORAGE
import android.content.ActivityNotFoundException
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.Bundle
import android.view.KeyEvent
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.core.content.res.ResourcesCompat
import androidx.core.view.isVisible
import androidx.fragment.app.FragmentActivity
import androidx.leanback.app.BackgroundManager
Expand All @@ -31,12 +30,12 @@ import com.fondesa.kpermissions.allGranted
import com.fondesa.kpermissions.extension.permissionsBuilder
import com.fondesa.kpermissions.extension.send
import com.medina.juanantonio.watcher.databinding.ActivityMainBinding
import com.medina.juanantonio.watcher.features.dialog.DialogActivity
import com.medina.juanantonio.watcher.features.dialog.DialogFragment
import com.medina.juanantonio.watcher.features.loader.LoaderUseCase
import com.medina.juanantonio.watcher.data.manager.downloader.IDownloadManager
import com.medina.juanantonio.watcher.data.manager.downloader.PollState
import com.medina.juanantonio.watcher.shared.extensions.initPoll
import com.medina.juanantonio.watcher.shared.extensions.toastIfNotBlank
import com.medina.juanantonio.watcher.shared.utils.observeEvent
import dagger.hilt.android.AndroidEntryPoint
import jp.wasabeef.glide.transformations.BlurTransformation
Expand Down Expand Up @@ -163,26 +162,20 @@ class MainActivity : FragmentActivity() {
private fun listenVM() {
viewModel.backgroundImageUrl.observe(this) {
when (it) {
null -> cancelBackgroundImageLoading()
null -> showDefaultBackground()
SHOW_MOVIE_BACKGROUND -> showMovieBackground()
else -> updateBackgroundDelayed(it)
}
}

viewModel.askToUpdate.observeEvent(this) {
val releaseName = viewModel.updateRelease?.name ?: return@observeEvent
startForResultUpdate.launch(
DialogActivity.getIntent(
context = this,
title = getString(R.string.update_available_title),
description = getString(
R.string.update_available_description,
releaseName
),
positiveButton = getString(R.string.update_button),
negativeButton = getString(R.string.no_thanks_button)
)
)
try {
val downloadUrl = viewModel.assetToDownload?.downloadUrl ?: return@observeEvent
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(downloadUrl))
startActivity(browserIntent)
} catch (e: ActivityNotFoundException) {
getString(R.string.install_browser_for_update).toastIfNotBlank(this)
}
}

viewModel.requestPermissions.observeEvent(this) {
Expand Down Expand Up @@ -232,13 +225,14 @@ class MainActivity : FragmentActivity() {
imageLoadingJob = null
}

private fun showDefaultBackground() {
cancelBackgroundImageLoading()
backgroundManager.setThemeDrawableResourceId(BACKGROUND_RESOURCE_ID)
}

private fun showMovieBackground() {
cancelBackgroundImageLoading()
backgroundManager.setThemeDrawableResourceId(MOVIE_BACKGROUND_RESOURCE_ID)

val drawable =
ResourcesCompat.getDrawable(resources, MOVIE_BACKGROUND_RESOURCE_ID, null)
backgroundManager.setBitmap((drawable as? BitmapDrawable)?.bitmap)
}

private fun setupLoading() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.medina.juanantonio.watcher.features.home
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.ImageView
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.widget.AppCompatImageView
Expand All @@ -24,6 +25,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.RequestManager
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.medina.juanantonio.watcher.MainViewModel
import com.medina.juanantonio.watcher.R
import com.medina.juanantonio.watcher.data.adapters.ContentAdapter
Expand Down Expand Up @@ -162,7 +164,6 @@ class HomeFragment : RowsSupportFragment() {

viewModel.setupVideoList(selectedVideoGroup, autoPlayFirstEpisode)
viewModel.getUserInfo()
activityViewModel.resetBackgroundImage()
}

private fun setupViews() {
Expand Down Expand Up @@ -372,6 +373,8 @@ class HomeFragment : RowsSupportFragment() {
view?.findViewById<AppCompatTextView>(R.id.text_view_preview_year)
val textViewPreviewTags =
view?.findViewById<AppCompatTextView>(R.id.text_view_preview_tags)
val imageViewPosterPreview =
view?.findViewById<ImageView>(R.id.image_view_poster_preview)

groupDetailsPreview?.isVisible = true

Expand All @@ -384,7 +387,13 @@ class HomeFragment : RowsSupportFragment() {
textViewPreviewDescription?.maxLines =
if ((textViewPreviewTitle?.lineCount ?: 1) > 1) 3 else 5

activityViewModel.setBackgroundImage(details.coverHorizontalUrl)
imageViewPosterPreview?.let {
glide.load(details.coverHorizontalUrl)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.transition(DrawableTransitionOptions.withCrossFade())
.error(R.drawable.drawable_image_error)
.into(it)
}
}

private fun setupUserDetailsPreview(details: GetUserInfoResponse.Data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.view.View
import androidx.annotation.Dimension
import androidx.core.view.isVisible
import androidx.core.view.updatePadding
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.leanback.app.VideoSupportFragment
import androidx.leanback.app.VideoSupportFragmentGlueHost
Expand Down Expand Up @@ -37,6 +38,7 @@ import com.google.android.exoplayer2.ui.CaptionStyleCompat.EDGE_TYPE_RAISED
import com.google.android.exoplayer2.ui.SubtitleView
import com.google.android.exoplayer2.upstream.DefaultDataSource
import com.google.android.exoplayer2.util.MimeTypes
import com.medina.juanantonio.watcher.MainViewModel
import com.medina.juanantonio.watcher.R
import com.medina.juanantonio.watcher.data.models.settings.SettingsSelectionItem
import com.medina.juanantonio.watcher.data.models.video.Video
Expand Down Expand Up @@ -77,6 +79,7 @@ class PlayerFragment : VideoSupportFragment() {

private var exoPlayer: ExoPlayer? = null
private val viewModel: PlayerViewModel by viewModels()
private val activityViewModel: MainViewModel by activityViewModels()
private lateinit var mediaSession: MediaSessionCompat
private lateinit var mediaSessionConnector: MediaSessionConnector
private lateinit var controlGlue: ProgressTransportControlGlue<LeanbackPlayerAdapter>
Expand Down Expand Up @@ -227,6 +230,7 @@ class PlayerFragment : VideoSupportFragment() {
override fun onDestroyView() {
super.onDestroyView()
viewModel.removePlaybackStateListener(uiPlaybackStateListener)
activityViewModel.cancelBackgroundImage()
}

override fun onStart() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ class VideoSearchFragment : SearchSupportFragment(), SearchSupportFragment.Searc
}
}

setOnItemViewSelectedListener { _, item, _, _ ->
if (item !is Video) return@setOnItemViewSelectedListener
activityViewModel.setBackgroundImage(item.imageUrl)
}

badgeDrawable = ResourcesCompat.getDrawable(resources, R.mipmap.ic_launcher, null)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ data class ReleaseBean(
) {

val downloadUrl: String
get() = url
get() = browser_download_url

fun isAPK(): Boolean =
content_type == "application/vnd.android.package-archive"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class MockUpdateRepository : IUpdateRepository {
if (alreadyDownloadedUpdate) return null
alreadyDownloadedUpdate = true

val sampleDownloadUrl =
"https://github.com/janjanmedinaaa/watcher-tv/releases/download/2.10.2/Watcher.TV.v2.10.2_29.Release.apk"
val version = DefaultArtifactVersion(BuildConfig.VERSION_NAME)
val newVersion = "${version.majorVersion}.${version.minorVersion + 1}"

Expand All @@ -30,8 +32,8 @@ class MockUpdateRepository : IUpdateRepository {
ReleaseBean.Asset(
id = 1,
content_type = "application/vnd.android.package-archive",
browser_download_url = "",
url = ""
browser_download_url = sampleDownloadUrl,
url = sampleDownloadUrl
)
),
draft = !showUpdate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.medina.juanantonio.watcher.network.ApiService
import com.medina.juanantonio.watcher.sources.BaseRemoteSource
import com.medina.juanantonio.watcher.network.Result
import com.medina.juanantonio.watcher.network.models.auth.*
import com.medina.juanantonio.watcher.network.wrapWithResult
import com.medina.juanantonio.watcher.network.wrapWithResultForLoklok
import com.medina.juanantonio.watcher.shared.utils.CoroutineDispatchers
import kotlinx.coroutines.CancellationException
Expand Down Expand Up @@ -88,7 +89,7 @@ class AuthRemoteSource(
val response = withContext(dispatchers.io) {
apiService.refreshToken()
}
response.wrapWithResultForLoklok()
response.wrapWithResult()
} catch (exception: CancellationException) {
Result.Cancelled()
} catch (exception: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,16 @@ class AuthRepository(
val result = remoteSource.refreshToken()
val data = result.data?.data

val isSuccessful =
if (result is Result.Success) data != null
else false

if (isSuccessful) {
saveToken(data ?: "")
} else {
clearToken()
result.message.toastIfNotBlank(context)
}

return isSuccessful
return if (result is Result.Success) {
if (data != null) {
saveToken(data)
true
} else {
clearToken()
result.message.toastIfNotBlank(context)
false
}
} else false
}

private suspend fun clearToken() {
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/preview_gradient_border_bottom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="270"
android:endColor="@color/screen_black"
android:startColor="#00000000"
android:type="linear" />
</shape>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/preview_gradient_borders.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:endColor="@color/screen_black"
android:gradientRadius="85%p"
android:startColor="#00000000"
android:type="radial" />
</shape>
Loading

0 comments on commit b9fed6f

Please sign in to comment.