Skip to content

Commit

Permalink
Merge pull request #896 from StepicOrg/release/1.194
Browse files Browse the repository at this point in the history
Release/1.194
  • Loading branch information
rostikjoystick authored Oct 13, 2021
2 parents 9e9d766 + 0757ea9 commit a4c8d03
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 95 deletions.
10 changes: 10 additions & 0 deletions app/src/main/java/org/stepic/droid/analytic/AnalyticImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ constructor(
apply(Attribute.customBoolean(AmplitudeAnalytic.Properties.IS_NIGHT_MODE_ENABLED).withValue(context.isNightModeEnabled()))
apply(Attribute.customBoolean(AmplitudeAnalytic.Properties.IS_AR_SUPPORTED).withValue(context.isARSupported()))
}

firebaseAnalytics.setUserProperty(AmplitudeAnalytic.Properties.PUSH_PERMISSION, if (isNotificationsEnabled) "granted" else "not_granted")
firebaseAnalytics.setUserProperty(AmplitudeAnalytic.Properties.IS_NIGHT_MODE_ENABLED, context.isNightModeEnabled().toString())
firebaseAnalytics.setUserProperty(AmplitudeAnalytic.Properties.IS_AR_SUPPORTED, context.isARSupported().toString())
}

// Amplitude properties
Expand All @@ -85,32 +89,38 @@ constructor(
override fun setCoursesCount(coursesCount: Int) {
amplitude.identify(Identify().set(AmplitudeAnalytic.Properties.COURSES_COUNT, coursesCount))
updateYandexUserProfile { apply(Attribute.customNumber(AmplitudeAnalytic.Properties.COURSES_COUNT).withValue(coursesCount.toDouble())) }
firebaseAnalytics.setUserProperty(AmplitudeAnalytic.Properties.COURSES_COUNT, coursesCount.toString())
}

override fun setSubmissionsCount(submissionsCount: Long, delta: Long) {
amplitude.identify(Identify().set(AmplitudeAnalytic.Properties.SUBMISSIONS_COUNT, submissionsCount + delta))
updateYandexUserProfile { apply(Attribute.customCounter(AmplitudeAnalytic.Properties.SUBMISSIONS_COUNT).withDelta(delta.toDouble())) }
firebaseAnalytics.setUserProperty(AmplitudeAnalytic.Properties.SUBMISSIONS_COUNT, (submissionsCount + delta).toString())
}

override fun setScreenOrientation(orientation: Int) {
val orientationName = if (orientation == Configuration.ORIENTATION_PORTRAIT) "portrait" else "landscape"
amplitude.identify(Identify().set(AmplitudeAnalytic.Properties.SCREEN_ORIENTATION, orientationName))
updateYandexUserProfile { apply(Attribute.customString(AmplitudeAnalytic.Properties.SCREEN_ORIENTATION).withValue(orientationName)) }
firebaseAnalytics.setUserProperty(AmplitudeAnalytic.Properties.SCREEN_ORIENTATION, orientationName)
}

override fun setStreaksNotificationsEnabled(isEnabled: Boolean) {
amplitude.identify(Identify().set(AmplitudeAnalytic.Properties.STREAKS_NOTIFICATIONS_ENABLED, if (isEnabled) "enabled" else "disabled"))
updateYandexUserProfile { apply(Attribute.customBoolean(AmplitudeAnalytic.Properties.STREAKS_NOTIFICATIONS_ENABLED).withValue(isEnabled)) }
firebaseAnalytics.setUserProperty(AmplitudeAnalytic.Properties.STREAKS_NOTIFICATIONS_ENABLED.substring(0, 24), if (isEnabled) "enabled" else "disabled")
}

override fun setTeachingCoursesCount(coursesCount: Int) {
amplitude.identify(Identify().set(AmplitudeAnalytic.Properties.TEACHING_COURSES_COUNT, coursesCount))
updateYandexUserProfile { apply(Attribute.customNumber(AmplitudeAnalytic.Properties.TEACHING_COURSES_COUNT).withValue(coursesCount.toDouble())) }
firebaseAnalytics.setUserProperty(AmplitudeAnalytic.Properties.TEACHING_COURSES_COUNT, coursesCount.toString())
}

override fun setGoogleServicesAvailable(isAvailable: Boolean) {
amplitude.identify(Identify().set(AmplitudeAnalytic.Properties.IS_GOOGLE_SERVICES_AVAILABLE, isAvailable.toString()))
updateYandexUserProfile { apply(Attribute.customBoolean(AmplitudeAnalytic.Properties.IS_GOOGLE_SERVICES_AVAILABLE).withValue(isAvailable)) }
firebaseAnalytics.setUserProperty(AmplitudeAnalytic.Properties.IS_GOOGLE_SERVICES_AVAILABLE.substring(0, 24), isAvailable.toString())
}

override fun report(analyticEvent: AnalyticEvent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
setOnSeekBarChangeListener(this)
}

override fun addListener(listener: TimeBar.OnScrubListener?) {
listener?.let(listeners::add)
override fun addListener(listener: TimeBar.OnScrubListener) {
listeners += listener
}

override fun removeListener(listener: TimeBar.OnScrubListener?) {
listener?.let(listeners::remove)
override fun removeListener(listener: TimeBar.OnScrubListener) {
listeners -= listener
}

override fun setKeyTimeIncrement(time: Long) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ constructor(
courseBuyInWebActionDiscounted.setOnClickListener { buyInWebAction() }

courseBuyInAppAction.setOnClickListener {
courseHeaderData?.let { headerData ->
analytic.report(BuyCoursePressedEvent(headerData.course, BuyCoursePressedEvent.COURSE_SCREEN, headerData.stats.isWishlisted))
analytic.report(BuyCoursePressedAnalyticBatchEvent(headerData.courseId))
}
coursePresenter.purchaseCourse()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@ import androidx.appcompat.widget.PopupMenu
import androidx.core.view.GestureDetectorCompat
import androidx.core.view.isVisible
import androidx.lifecycle.ViewModelProvider
import com.google.android.exoplayer2.DefaultControlDispatcher
import com.google.android.exoplayer2.ExoPlaybackException
import com.google.android.exoplayer2.ExoPlayer
import com.google.android.exoplayer2.PlaybackException
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.upstream.HttpDataSource
import com.google.android.exoplayer2.util.Util
import kotlinx.android.synthetic.main.activity_video_player.*
import kotlinx.android.synthetic.main.exo_playback_control_view.*
import kotlinx.android.synthetic.main.exo_player_control_view.*
import org.stepic.droid.R
import org.stepic.droid.analytic.AmplitudeAnalytic
import org.stepic.droid.analytic.Analytic
Expand All @@ -65,7 +63,6 @@ import org.stepik.android.view.video_player.model.VideoPlayerData
import org.stepik.android.view.video_player.model.VideoPlayerMediaData
import org.stepik.android.view.video_player.ui.service.VideoPlayerForegroundService
import javax.inject.Inject
import kotlin.math.abs

class VideoPlayerActivity : AppCompatActivity(), VideoPlayerView, VideoQualityDialogInPlayer.Callback {
companion object {
Expand Down Expand Up @@ -152,11 +149,9 @@ class VideoPlayerActivity : AppCompatActivity(), VideoPlayerView, VideoQualityDi
}

private val exoPlayerListener =
object : Player.EventListener {
override fun onPlayerError(error: ExoPlaybackException?) {
error ?: return

if (error.type == ExoPlaybackException.TYPE_SOURCE && error.cause is HttpDataSource.HttpDataSourceException) {
object : Player.Listener {
override fun onPlayerError(error: PlaybackException) {
if (error.cause is HttpDataSource.HttpDataSourceException) {
Toast
.makeText(this@VideoPlayerActivity, R.string.no_connection, Toast.LENGTH_LONG)
.show()
Expand Down Expand Up @@ -204,35 +199,16 @@ class VideoPlayerActivity : AppCompatActivity(), VideoPlayerView, VideoQualityDi
}
CONTROL_TYPE_PAUSE -> exoPlayer?.playWhenReady = false
CONTROL_TYPE_REWIND -> exoPlayer?.let {
analytic.report(VideoPlayerControlClickedEvent(VideoPlayerControlClickedEvent.ACTION_REWIND))
it.seekTo(it.currentPosition - JUMP_TIME_MILLIS)
}
CONTROL_TYPE_FORWARD -> exoPlayer?.let {
analytic.report(VideoPlayerControlClickedEvent(VideoPlayerControlClickedEvent.ACTION_FORWARD))
it.seekTo(it.currentPosition + JUMP_TIME_MILLIS)
}
}
}
}
}

private val controlDispatcher = object : DefaultControlDispatcher() {
override fun dispatchSeekTo(player: Player?, windowIndex: Int, positionMs: Long): Boolean {
val current = player?.currentPosition ?: 0L
val difference = current - positionMs
val action =
if (difference > 0L) {
VideoPlayerControlClickedEvent.ACTION_SEEK_BACK
} else {
VideoPlayerControlClickedEvent.ACTION_SEEK_FORWARD
}
if (abs(difference) != JUMP_TIME_MILLIS.toLong()) {
analytic.report(VideoPlayerControlClickedEvent(action))
}
return super.dispatchSeekTo(player, windowIndex, positionMs)
}
}

private lateinit var gestureDetector: GestureDetectorCompat

private val onSimpleGestureListener = object : GestureDetector.SimpleOnGestureListener() {
Expand All @@ -247,7 +223,7 @@ class VideoPlayerActivity : AppCompatActivity(), VideoPlayerView, VideoQualityDi
}
}

private var exoPlayer: ExoPlayer? = null
private var exoPlayer: Player? = null
set(value) {
field?.removeListener(exoPlayerListener)
field = value
Expand Down Expand Up @@ -306,11 +282,7 @@ class VideoPlayerActivity : AppCompatActivity(), VideoPlayerView, VideoQualityDi
}

qualityView.isVisible = false

playerView.setControlDispatcher(controlDispatcher)
playerView.controllerShowTimeoutMs = TIMEOUT_BEFORE_HIDE
playerView.setFastForwardIncrementMs(JUMP_TIME_MILLIS)
playerView.setRewindIncrementMs(JUMP_TIME_MILLIS)

exo_pip_icon_container.isVisible = isSupportPIP()
exo_pip_icon_container.setOnClickListener {
Expand Down Expand Up @@ -343,12 +315,10 @@ class VideoPlayerActivity : AppCompatActivity(), VideoPlayerView, VideoQualityDi
}

rewind.setOnClickListener {
analytic.report(VideoPlayerControlClickedEvent(VideoPlayerControlClickedEvent.ACTION_REWIND))
exoPlayer?.let { player -> player.seekTo(player.currentPosition - JUMP_TIME_MILLIS) }
}

forward.setOnClickListener {
analytic.report(VideoPlayerControlClickedEvent(VideoPlayerControlClickedEvent.ACTION_FORWARD))
exoPlayer?.let { player -> player.seekTo(player.currentPosition + JUMP_TIME_MILLIS) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import androidx.appcompat.content.res.AppCompatResources
import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.CustomTarget
import com.bumptech.glide.request.transition.Transition
Expand All @@ -13,6 +14,7 @@ import com.google.android.exoplayer2.ui.PlayerNotificationManager
import org.stepic.droid.R
import org.stepik.android.view.video_player.model.VideoPlayerMediaData
import org.stepik.android.view.video_player.ui.activity.VideoPlayerActivity
import ru.nobird.android.view.base.ui.extension.toBitmap

class VideoPlayerMediaDescriptionAdapter(
private val context: Context
Expand All @@ -22,20 +24,20 @@ class VideoPlayerMediaDescriptionAdapter(
private fun createIntent(videoPlayerMediaData: VideoPlayerMediaData): Intent =
VideoPlayerActivity.createIntent(context, videoPlayerMediaData)

override fun createCurrentContentIntent(player: Player?): PendingIntent? =
override fun createCurrentContentIntent(player: Player): PendingIntent? =
videoPlayerMediaData
?.let(::createIntent)
?.let { intent ->
PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
}

override fun getCurrentContentText(player: Player?): String? =
override fun getCurrentContentText(player: Player): String? =
videoPlayerMediaData?.description

override fun getCurrentContentTitle(player: Player?): String =
override fun getCurrentContentTitle(player: Player): String =
videoPlayerMediaData?.title ?: ""

override fun getCurrentLargeIcon(player: Player?, callback: PlayerNotificationManager.BitmapCallback?): Bitmap? {
override fun getCurrentLargeIcon(player: Player, callback: PlayerNotificationManager.BitmapCallback): Bitmap? {
Glide.with(context)
.asBitmap()
.load(videoPlayerMediaData?.thumbnail)
Expand All @@ -44,9 +46,9 @@ class VideoPlayerMediaDescriptionAdapter(
override fun onLoadCleared(placeholder: Drawable?) {}

override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
callback?.onBitmap(resource)
callback.onBitmap(resource)
}
})
return null
return AppCompatResources.getDrawable(context, R.drawable.general_placeholder)?.toBitmap()
}
}
Loading

0 comments on commit a4c8d03

Please sign in to comment.