Update dependencies:

- Android Studio Chipmunk | 2021.2.1 Patch 1
- kotlin_version = 1.6.21
- kotlinx_coroutines_version = 1.6.2
- com.google.android.material:material:1.6.0
- com.google.firebase:firebase-messaging:23.0.5
- comment out composeOptions that is not ye

following ExoPlayer's API changes:
- replace deprecated ExoPlayer's PlayerView to StyledPlayerView^M
- call ExoPlayer's StyledPlayerView's onResume(),onPause().
- remove some deprecated methods from ExoPlayer's event listener.
- hide some controller buttons from StyledPlayerView.
This commit is contained in:
tateisu 2022-05-29 14:00:51 +09:00
parent 5209d5d096
commit 228a8d3338
6 changed files with 112 additions and 65 deletions

View File

@ -19,7 +19,6 @@
<option value="$PROJECT_DIR$/sample_apng" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>

View File

@ -4,11 +4,28 @@
<modules>
<module fileurl="file://$PROJECT_DIR$/SubwayTooter.iml" filepath="$PROJECT_DIR$/SubwayTooter.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/apng/SubwayTooter.apng.iml" filepath="$PROJECT_DIR$/.idea/modules/apng/SubwayTooter.apng.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/apng/SubwayTooter.apng.main.iml" filepath="$PROJECT_DIR$/.idea/modules/apng/SubwayTooter.apng.main.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/apng/SubwayTooter.apng.test.iml" filepath="$PROJECT_DIR$/.idea/modules/apng/SubwayTooter.apng.test.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/apng_android/SubwayTooter.apng_android.iml" filepath="$PROJECT_DIR$/.idea/modules/apng_android/SubwayTooter.apng_android.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/apng_android/SubwayTooter.apng_android.androidTest.iml" filepath="$PROJECT_DIR$/.idea/modules/apng_android/SubwayTooter.apng_android.androidTest.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/apng_android/SubwayTooter.apng_android.main.iml" filepath="$PROJECT_DIR$/.idea/modules/apng_android/SubwayTooter.apng_android.main.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/apng_android/SubwayTooter.apng_android.unitTest.iml" filepath="$PROJECT_DIR$/.idea/modules/apng_android/SubwayTooter.apng_android.unitTest.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/app/SubwayTooter.app.iml" filepath="$PROJECT_DIR$/.idea/modules/app/SubwayTooter.app.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/app/SubwayTooter.app.androidTest.iml" filepath="$PROJECT_DIR$/.idea/modules/app/SubwayTooter.app.androidTest.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/app/SubwayTooter.app.main.iml" filepath="$PROJECT_DIR$/.idea/modules/app/SubwayTooter.app.main.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/app/SubwayTooter.app.unitTest.iml" filepath="$PROJECT_DIR$/.idea/modules/app/SubwayTooter.app.unitTest.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/colorpicker/SubwayTooter.colorpicker.iml" filepath="$PROJECT_DIR$/.idea/modules/colorpicker/SubwayTooter.colorpicker.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/colorpicker/SubwayTooter.colorpicker.androidTest.iml" filepath="$PROJECT_DIR$/.idea/modules/colorpicker/SubwayTooter.colorpicker.androidTest.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/colorpicker/SubwayTooter.colorpicker.main.iml" filepath="$PROJECT_DIR$/.idea/modules/colorpicker/SubwayTooter.colorpicker.main.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/colorpicker/SubwayTooter.colorpicker.unitTest.iml" filepath="$PROJECT_DIR$/.idea/modules/colorpicker/SubwayTooter.colorpicker.unitTest.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/emoji/SubwayTooter.emoji.iml" filepath="$PROJECT_DIR$/.idea/modules/emoji/SubwayTooter.emoji.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/emoji/SubwayTooter.emoji.androidTest.iml" filepath="$PROJECT_DIR$/.idea/modules/emoji/SubwayTooter.emoji.androidTest.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/emoji/SubwayTooter.emoji.main.iml" filepath="$PROJECT_DIR$/.idea/modules/emoji/SubwayTooter.emoji.main.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/emoji/SubwayTooter.emoji.unitTest.iml" filepath="$PROJECT_DIR$/.idea/modules/emoji/SubwayTooter.emoji.unitTest.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/sample_apng/SubwayTooter.sample_apng.iml" filepath="$PROJECT_DIR$/.idea/modules/sample_apng/SubwayTooter.sample_apng.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/sample_apng/SubwayTooter.sample_apng.androidTest.iml" filepath="$PROJECT_DIR$/.idea/modules/sample_apng/SubwayTooter.sample_apng.androidTest.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/sample_apng/SubwayTooter.sample_apng.main.iml" filepath="$PROJECT_DIR$/.idea/modules/sample_apng/SubwayTooter.sample_apng.main.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/sample_apng/SubwayTooter.sample_apng.unitTest.iml" filepath="$PROJECT_DIR$/.idea/modules/sample_apng/SubwayTooter.sample_apng.unitTest.iml" />
</modules>
</component>
</project>

View File

@ -42,8 +42,8 @@ android {
"-Xopt-in=kotlin.ExperimentalStdlibApi",
"-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
"-Xopt-in=kotlinx.serialization.ExperimentalSerializationApi",
// "-Xopt-in=androidx.compose.foundation.ExperimentalFoundationApi",
// "-Xopt-in=androidx.compose.animation.ExperimentalAnimationApi",
// "-Xopt-in=androidx.compose.foundation.ExperimentalFoundationApi",
// "-Xopt-in=androidx.compose.animation.ExperimentalAnimationApi",
]
}
@ -51,10 +51,9 @@ android {
// buildFeatures {
// compose true
// }
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
// composeOptions {
// kotlinCompilerExtensionVersion compose_version
// }
buildTypes {
release {
@ -157,7 +156,7 @@ dependencies {
implementation "androidx.drawerlayout:drawerlayout:1.1.1"
// NavigationView
implementation "com.google.android.material:material:1.5.0"
implementation "com.google.android.material:material:1.6.0"
implementation "androidx.exifinterface:exifinterface:1.3.3"
@ -170,7 +169,7 @@ dependencies {
kapt 'androidx.annotation:annotation:1.3.0'
// https://firebase.google.com/support/release-notes/android
implementation "com.google.firebase:firebase-messaging:23.0.3"
implementation "com.google.firebase:firebase-messaging:23.0.5"
implementation "org.jetbrains.kotlin:kotlin-reflect"
testImplementation "org.jetbrains.kotlin:kotlin-test"

View File

@ -20,9 +20,16 @@ import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import com.google.android.exoplayer2.*
import com.google.android.exoplayer2.Player.TimelineChangeReason
import com.google.android.exoplayer2.source.*
import jp.juggler.subwaytooter.api.*
import com.google.android.exoplayer2.source.LoadEventInfo
import com.google.android.exoplayer2.source.MediaLoadData
import com.google.android.exoplayer2.source.MediaSource
import com.google.android.exoplayer2.source.MediaSourceEventListener
import com.google.android.exoplayer2.util.RepeatModeUtil.REPEAT_TOGGLE_MODE_ONE
import jp.juggler.subwaytooter.api.ApiTask
import jp.juggler.subwaytooter.api.TootApiClient
import jp.juggler.subwaytooter.api.TootApiResult
import jp.juggler.subwaytooter.api.entity.*
import jp.juggler.subwaytooter.api.runApiTask
import jp.juggler.subwaytooter.databinding.ActMediaViewerBinding
import jp.juggler.subwaytooter.dialog.ActionsDialog
import jp.juggler.subwaytooter.drawable.MediaBackgroundDrawable
@ -95,7 +102,10 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
private lateinit var serviceType: ServiceType
private var showDescription = true
private lateinit var viewBinding: ActMediaViewerBinding
private val views by lazy {
ActMediaViewerBinding.inflate(layoutInflater)
}
private lateinit var exoPlayer: ExoPlayer
private var lastVolume = Float.NaN
@ -116,20 +126,12 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
log.d("exoPlayer onTimelineChanged reason=$reason")
}
override fun onSeekProcessed() {
}
override fun onShuffleModeEnabledChanged(shuffleModeEnabled: Boolean) {
}
override fun onLoadingChanged(isLoading: Boolean) {
// かなり頻繁に呼ばれる
// warning.d( "exoPlayer onLoadingChanged %s" ,isLoading );
}
override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) {
// かなり頻繁に呼ばれる
// warning.d( "exoPlayer onPlayerStateChanged %s %s", playWhenReady, playbackState );
private fun showBufferingToast() {
val playWhenReady = exoPlayer.playWhenReady
val playbackState = exoPlayer.playbackState
if (playWhenReady && playbackState == Player.STATE_BUFFERING) {
val now = SystemClock.elapsedRealtime()
if (now - bufferingLastShown >= short_limit && exoPlayer.duration >= short_limit) {
@ -142,6 +144,15 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
}
}
override fun onPlaybackStateChanged(playbackState: Int) {
showBufferingToast()
}
override fun onPlayWhenReadyChanged(playWhenReady: Boolean, reason: Int) {
log.d("onPlayWhenReadyChanged playWhenReady=$playWhenReady, reason=$reason")
showBufferingToast()
}
override fun onRepeatModeChanged(repeatMode: Int) {
log.d("exoPlayer onRepeatModeChanged $repeatMode")
}
@ -151,8 +162,12 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
showToast(error, "player error.")
}
override fun onPositionDiscontinuity(reason: Int) {
log.d("exoPlayer onPositionDiscontinuity reason=$reason")
override fun onPositionDiscontinuity(
oldPosition: Player.PositionInfo,
newPosition: Player.PositionInfo,
reason: Int,
) {
log.d("exoPlayer onPositionDiscontinuity reason=$reason, oldPosition=$oldPosition, newPosition=$newPosition")
}
}
@ -231,12 +246,8 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
requestWindowFeature(Window.FEATURE_NO_TITLE)
App1.setActivityTheme(this, noActionBar = true, forceDark = true)
val intent = intent
this.showDescription = intent.getBooleanExtra(EXTRA_SHOW_DESCRIPTION, showDescription)
this.idx = savedInstanceState?.getInt(EXTRA_IDX) ?: intent.getIntExtra(EXTRA_IDX, idx)
this.serviceType = ServiceType.values()[
savedInstanceState?.getInt(EXTRA_SERVICE_TYPE)
?: intent.getIntExtra(EXTRA_SERVICE_TYPE, 0)
@ -247,7 +258,10 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
?: intent.getStringExtra(EXTRA_DATA)
)
if (idx < 0 || idx >= mediaList.size) idx = 0
this.idx = (savedInstanceState?.getInt(EXTRA_IDX)
?: intent.getIntExtra(EXTRA_IDX, 0))
.takeIf { it in mediaList.indices }
?: 0
initUI()
@ -256,35 +270,44 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
override fun onDestroy() {
super.onDestroy()
viewBinding.pbvImage.setBitmap(null)
views.pbvImage.setBitmap(null)
exoPlayer.release()
}
override fun onStart() {
super.onStart()
views.exoView.onResume()
}
override fun onStop() {
super.onStop()
views.exoView.onPause()
}
override fun finish() {
super.finish()
overridePendingTransition(R.anim.fade_in, R.anim.slide_to_bottom)
}
internal fun initUI() {
viewBinding = ActMediaViewerBinding.inflate(layoutInflater)
setContentView(viewBinding.root)
setContentView(views.root)
App1.initEdgeToEdge(this)
viewBinding.pbvImage.background = MediaBackgroundDrawable(
views.pbvImage.background = MediaBackgroundDrawable(
tileStep = tileStep,
kind = MediaBackgroundDrawable.Kind.fromIndex(PrefI.ipMediaBackground(this))
)
val enablePaging = mediaList.size > 1
viewBinding.btnPrevious.isEnabledAlpha = enablePaging
viewBinding.btnNext.isEnabledAlpha = enablePaging
views.btnPrevious.isEnabledAlpha = enablePaging
views.btnNext.isEnabledAlpha = enablePaging
viewBinding.btnPrevious.setOnClickListener(this)
viewBinding.btnNext.setOnClickListener(this)
views.btnPrevious.setOnClickListener(this)
views.btnNext.setOnClickListener(this)
findViewById<View>(R.id.btnDownload).setOnClickListener(this)
findViewById<View>(R.id.btnMore).setOnClickListener(this)
viewBinding.cbMute.setOnCheckedChangeListener { _, isChecked ->
views.cbMute.setOnCheckedChangeListener { _, isChecked ->
if (isChecked) {
// mute
lastVolume = exoPlayer.volume
@ -300,7 +323,7 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
}
}
viewBinding.pbvImage.setCallback(object : PinchBitmapView.Callback {
views.pbvImage.setCallback(object : PinchBitmapView.Callback {
override fun onSwipe(deltaX: Int, deltaY: Int) {
if (isDestroyed) return
if (deltaX != 0) {
@ -320,8 +343,8 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
) {
App1.getAppState(this@ActMediaViewer).handler.post(Runnable {
if (isDestroyed) return@Runnable
if (viewBinding.tvStatus.visibility == View.VISIBLE) {
viewBinding.tvStatus.text = getString(
if (views.tvStatus.visibility == View.VISIBLE) {
views.tvStatus.text = getString(
R.string.zooming_of,
bitmapW.toInt(),
bitmapH.toInt(),
@ -334,7 +357,15 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
exoPlayer = ExoPlayer.Builder(this).build()
exoPlayer.addListener(playerListener)
viewBinding.exoView.player = exoPlayer
views.exoView.run {
player = exoPlayer
controllerAutoShow = false
setShowRewindButton(false)
setShowFastForwardButton(false)
setShowPreviousButton(false)
setShowNextButton(false)
setRepeatToggleModes(REPEAT_TOGGLE_MODE_ONE)
}
}
internal fun loadDelta(delta: Int) {
@ -349,7 +380,7 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
exoPlayer.stop()
// いったんすべて隠す
viewBinding.run {
views.run {
pbvImage.gone()
exoView.gone()
tvError.gone()
@ -364,8 +395,8 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
val ta = mediaList[idx]
val description = ta.description
if (showDescription && description?.isNotEmpty() == true) {
viewBinding.svDescription.visible()
viewBinding.tvDescription.text = description
views.svDescription.visible()
views.tvDescription.text = description
}
when (ta.type) {
@ -383,7 +414,7 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
}
private fun showError(message: String) {
viewBinding.run {
views.run {
exoView.gone()
pbvImage.gone()
tvError.visible().text = message
@ -393,7 +424,7 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
@SuppressLint("StaticFieldLeak")
private fun loadVideo(ta: TootAttachment, state: Bundle? = null) {
viewBinding.cbMute.visible().run {
views.cbMute.visible().run {
if (isChecked && lastVolume.isFinite()) {
exoPlayer.volume = 0f
}
@ -412,7 +443,7 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
// https://github.com/google/ExoPlayer/issues/1819
HttpsURLConnection.setDefaultSSLSocketFactory(MySslSocketFactory)
viewBinding.exoView.visibility = View.VISIBLE
views.exoView.visibility = View.VISIBLE
exoPlayer.setMediaItem(MediaItem.fromUri(uri))
exoPlayer.prepare()
exoPlayer.repeatMode = when (ta.type) {
@ -565,7 +596,7 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
@SuppressLint("StaticFieldLeak")
private fun loadBitmap(ta: TootAttachment) {
viewBinding.run {
views.run {
cbMute.gone()
tvStatus.visible().text = null
pbvImage.visible().setBitmap(null)
@ -603,7 +634,7 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
}.let { result -> // may null
when (val bitmap = resultBitmap) {
null -> if (result != null) showToast(true, result.error)
else -> viewBinding.pbvImage.setBitmap(bitmap)
else -> views.pbvImage.setBitmap(bitmap)
}
}
}
@ -612,10 +643,10 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
override fun onClick(v: View) {
try {
when (v) {
viewBinding.btnPrevious -> loadDelta(-1)
viewBinding.btnNext -> loadDelta(+1)
viewBinding.btnDownload -> download(mediaList[idx])
viewBinding.btnMore -> more(mediaList[idx])
views.btnPrevious -> loadDelta(-1)
views.btnNext -> loadDelta(+1)
views.btnDownload -> download(mediaList[idx])
views.btnMore -> more(mediaList[idx])
}
} catch (ex: Throwable) {
showToast(ex, "action failed.")
@ -825,7 +856,7 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
val idx = k.toIndex()
appPref.edit().put(PrefI.ipMediaBackground, idx).apply()
viewBinding.pbvImage.background = MediaBackgroundDrawable(
views.pbvImage.background = MediaBackgroundDrawable(
tileStep = tileStep,
kind = k
)

View File

@ -33,7 +33,7 @@
android:layout_height="match_parent"
/>
<com.google.android.exoplayer2.ui.PlayerView
<com.google.android.exoplayer2.ui.StyledPlayerView
android:id="@+id/exoView"
android:layout_width="match_parent"
android:layout_height="match_parent" />

View File

@ -10,14 +10,14 @@ buildscript {
ext.lifecycle_version = "2.4.1"
ext.arch_version = "2.1.0"
ext.kotlin_version = '1.6.10'
ext.kotlinx_coroutines_version = '1.6.0'
ext.kotlin_version = '1.6.21'
ext.kotlinx_coroutines_version = '1.6.2'
ext.anko_version = '0.10.8'
ext.junit_version = '4.13.2'
ext.detekt_version = '1.19.0'
ext.detekt_version = '1.20.0'
ext.compose_version = '1.0.5'
@ -34,11 +34,10 @@ buildscript {
//noinspection DifferentKotlinGradleVersion
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
classpath "com.github.bjoernq:unmockplugin:0.7.6"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:$detekt_version"
}
}
@ -53,12 +52,14 @@ allprojects {
maven { url 'https://dl.bintray.com/google/exoplayer/' }
maven { url 'https://dl.bintray.com/google/flexbox-layout/' }
// detekt
maven { url "https://plugins.gradle.org/m2/" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
tasks.withType(JavaCompile) {
options.compilerArgs << '-Xlint:unchecked'
options.compilerArgs << '-Xlint:deprecation'
options.compilerArgs << '-Xlint:divzero'
}