From 74e55e81ae72b928ceb8e3fa449e2ae56bd74e21 Mon Sep 17 00:00:00 2001 From: MichaelStH Date: Thu, 23 Sep 2021 11:08:23 +0200 Subject: [PATCH 01/11] [feat/041-spring-choice] : Spring layout modification 2 buttons added --- app/src/main/res/drawable/round_corners.xml | 2 +- app/src/main/res/layout/activity_spring.xml | 317 ++++++++++++++---- .../main/res/xml/activity_spring_scene.xml | 33 ++ build.gradle | 16 +- 4 files changed, 301 insertions(+), 67 deletions(-) create mode 100644 app/src/main/res/xml/activity_spring_scene.xml diff --git a/app/src/main/res/drawable/round_corners.xml b/app/src/main/res/drawable/round_corners.xml index 9d401458..9afa9518 100644 --- a/app/src/main/res/drawable/round_corners.xml +++ b/app/src/main/res/drawable/round_corners.xml @@ -3,6 +3,6 @@ xmlns:tools="http://schemas.android.com/tools" android:shape="rectangle"> - + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_spring.xml b/app/src/main/res/layout/activity_spring.xml index 6d5c494d..05d49adc 100644 --- a/app/src/main/res/layout/activity_spring.xml +++ b/app/src/main/res/layout/activity_spring.xml @@ -1,62 +1,263 @@ - - - - - - - - - - - - - \ No newline at end of file + android:background="@color/default_dark" + app:layoutDescription="@xml/activity_spring_scene" + tools:context=".ui.spring.SpringActivity" + tools:motionDebug="SHOW_ALL"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/xml/activity_spring_scene.xml b/app/src/main/res/xml/activity_spring_scene.xml new file mode 100644 index 00000000..40cf0d4f --- /dev/null +++ b/app/src/main/res/xml/activity_spring_scene.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 18bf817a..9e276ca1 100644 --- a/build.gradle +++ b/build.gradle @@ -1,18 +1,18 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. ext { minSdkVersion = 23 - targetSdkVersion = 30 - compileSdkVersion = 30 - buildToolsVersion = "30.0.2" + targetSdkVersion = 31 + compileSdkVersion = 31 + buildToolsVersion = "30.0.3" // version information versionMajor = 10 - versionMinor = 7 - versionPatch = 1 + versionMinor = 8 + versionPatch = 0 versionName = "${versionMajor}.${versionMinor}.${versionPatch}" // Kotlin - kotlinVersion = '1.5.30' + kotlinVersion = '1.5.31' coroutinesVersion = '1.5.2' activityKtxVersion = '1.3.1' fragmentKtxVersion = '1.3.6' @@ -33,7 +33,7 @@ ext { viewPager2Version = '1.0.0' dynamicanimationVersion = '1.0.0' - mediaVersion = '1.4.1' + mediaVersion = '1.4.2' mediaRouterVersion = '1.2.5' autoFillVersion = '1.1.0' @@ -44,7 +44,7 @@ ext { roomVersion = '2.3.0' - lifecycleVersion = '2.4.0-alpha03' + lifecycleVersion = '2.4.0-beta01' hiltVersion = '2.38.1' hiltAndroidXVersion = '1.0.0' From 8679ddf00f02292e357c4c850bc9c3198f67730f Mon Sep 17 00:00:00 2001 From: MichaelStH Date: Thu, 23 Sep 2021 11:09:45 +0200 Subject: [PATCH 02/11] [feat/041-spring-choice] : Manifest Adaptation for android api 31 --- app/src/main/AndroidManifest.xml | 21 ++++++++++++------- .../locationonmaps/LocationOnMapsActivity.kt | 1 + build.gradle | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7bbfc395..bb8f360e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -146,7 +146,8 @@ + android:theme="@style/Theme.TheLab.NoActionBar" + android:exported="true"> @@ -196,7 +197,8 @@ android:name=".ui.contacts.ContactsActivity" android:label="@string/activity_title_database_contacts" android:parentActivityName=".ui.mainactivity.MainActivity" - android:theme="@style/Theme.TheLab.NoActionBar"> + android:theme="@style/Theme.TheLab.NoActionBar" + android:exported="true"> + android:theme="@style/Theme.TheLab" + android:exported="true"> + android:label="@string/app_name" + android:exported="true"> @@ -405,7 +409,8 @@ + android:enabled="true" + android:exported="true"> - + @@ -449,7 +455,8 @@ android:enabled="true" android:exported="false" /> - + diff --git a/app/src/main/java/com/riders/thelab/ui/locationonmaps/LocationOnMapsActivity.kt b/app/src/main/java/com/riders/thelab/ui/locationonmaps/LocationOnMapsActivity.kt index fc3ac5aa..d12ddfd7 100644 --- a/app/src/main/java/com/riders/thelab/ui/locationonmaps/LocationOnMapsActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/locationonmaps/LocationOnMapsActivity.kt @@ -21,6 +21,7 @@ import com.google.android.gms.common.api.ApiException import com.google.android.gms.common.api.CommonStatusCodes import com.google.android.gms.common.api.ResolvableApiException import com.google.android.gms.location.* +import com.google.android.gms.location.LocationRequest import com.google.android.gms.maps.* import com.google.android.gms.maps.model.LatLng import com.google.android.gms.maps.model.MarkerOptions diff --git a/build.gradle b/build.gradle index 9e276ca1..a2cf768a 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ ext { // version information versionMajor = 10 versionMinor = 8 - versionPatch = 0 + versionPatch = 1 versionName = "${versionMajor}.${versionMinor}.${versionPatch}" // Kotlin From ef5894bb790d3fb6c5a0a8bfe79f2daaf43af1af Mon Sep 17 00:00:00 2001 From: MichaelStH Date: Thu, 23 Sep 2021 18:56:46 +0200 Subject: [PATCH 03/11] [feat/041-spring-choice] : Spring animation move to middle done --- .../thelab/ui/mainactivity/MainActivity.kt | 8 +- .../ui/songplayer/SongPlayerActivity.kt | 2 +- .../riders/thelab/ui/spring/SpringActivity.kt | 108 +++++++++++------ .../main/res/layout/activity_song_player.xml | 2 +- app/src/main/res/layout/activity_spring.xml | 4 +- .../main/res/xml/activity_spring_scene.xml | 113 +++++++++++++++++- build.gradle | 2 +- 7 files changed, 190 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/com/riders/thelab/ui/mainactivity/MainActivity.kt b/app/src/main/java/com/riders/thelab/ui/mainactivity/MainActivity.kt index cf2afe2a..9e4250eb 100644 --- a/app/src/main/java/com/riders/thelab/ui/mainactivity/MainActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/mainactivity/MainActivity.kt @@ -389,7 +389,7 @@ class MainActivity : AppCompatActivity(), GlobalScope.launch(Dispatchers.Main) { Timber.d("resetProgressBars()") - binding.includeToolbarLayout?.llProgressBarContainer?.children?.let { + binding.includeToolbarLayout?.llProgressBarContainer?.children?.let { it -> val size = it.count() - 1 for (i in size downTo 0) { @@ -401,9 +401,9 @@ class MainActivity : AppCompatActivity(), progressBar.progress = 100 - for (j in 100 downTo 0) { - progressBar.progress = j - delay(20) + (100 downTo 0).forEach { percent -> + progressBar.progress = percent + delay(15) } } } diff --git a/app/src/main/java/com/riders/thelab/ui/songplayer/SongPlayerActivity.kt b/app/src/main/java/com/riders/thelab/ui/songplayer/SongPlayerActivity.kt index 6b04ca7d..05082a3e 100644 --- a/app/src/main/java/com/riders/thelab/ui/songplayer/SongPlayerActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/songplayer/SongPlayerActivity.kt @@ -573,7 +573,7 @@ class SongPlayerActivity : AppCompatActivity(), toggleAnimation(view) } - R.id.cv_song_player -> { + R.id.tv_song_path -> { if (!isToggle) toggleAnimation(view) } diff --git a/app/src/main/java/com/riders/thelab/ui/spring/SpringActivity.kt b/app/src/main/java/com/riders/thelab/ui/spring/SpringActivity.kt index f427fe7a..87bd22f8 100644 --- a/app/src/main/java/com/riders/thelab/ui/spring/SpringActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/spring/SpringActivity.kt @@ -13,11 +13,20 @@ import androidx.dynamicanimation.animation.DynamicAnimation import androidx.dynamicanimation.animation.DynamicAnimation.ViewProperty import androidx.dynamicanimation.animation.SpringAnimation import androidx.dynamicanimation.animation.SpringForce +import com.riders.thelab.R import com.riders.thelab.databinding.ActivitySpringBinding +import timber.log.Timber -class SpringActivity : AppCompatActivity() { +class SpringActivity : AppCompatActivity(), View.OnClickListener { - lateinit var viewBinding: ActivitySpringBinding + private var _viewBinding: ActivitySpringBinding? = null + + // This property is only valid between onCreateView and + // onDestroyView. + private val binding get() = _viewBinding!! + + private var isTopAnimationToggle: Boolean = false + private var isBottomAnimationToggle: Boolean = false private var xAnimation: SpringAnimation? = null private var yAnimation: SpringAnimation? = null @@ -25,14 +34,13 @@ class SpringActivity : AppCompatActivity() { private var dX = 0f private var dY = 0f - private val globalLayoutListener = OnGlobalLayoutListener { xAnimation = createSpringAnimation( - viewBinding.imageView, DynamicAnimation.X, viewBinding.imageView.getX(), + binding.imageView, DynamicAnimation.X, binding.imageView.getX(), SpringForce.STIFFNESS_MEDIUM, SpringForce.DAMPING_RATIO_HIGH_BOUNCY ) yAnimation = createSpringAnimation( - viewBinding.imageView, DynamicAnimation.Y, viewBinding.imageView.getY(), + binding.imageView, DynamicAnimation.Y, binding.imageView.getY(), SpringForce.STIFFNESS_MEDIUM, SpringForce.DAMPING_RATIO_HIGH_BOUNCY ) } @@ -51,7 +59,7 @@ class SpringActivity : AppCompatActivity() { } MotionEvent.ACTION_MOVE -> { // a different approach would be to change the view's LayoutParams. - viewBinding.imageView.animate() + binding.imageView.animate() .x(event.rawX + dX) .y(event.rawY + dY) .setDuration(0) @@ -76,11 +84,12 @@ class SpringActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + _viewBinding = ActivitySpringBinding.inflate(layoutInflater) + setContentView(binding.root) - viewBinding = ActivitySpringBinding.inflate(layoutInflater) - setContentView(viewBinding.root) + setListeners() - viewBinding.imageView.viewTreeObserver.addOnGlobalLayoutListener(globalLayoutListener) + binding.imageView.viewTreeObserver.addOnGlobalLayoutListener(globalLayoutListener) chainedSpringAnimation() } @@ -93,6 +102,16 @@ class SpringActivity : AppCompatActivity() { return true } + override fun onDestroy() { + super.onDestroy() + Timber.e("onDestroy()") + _viewBinding = null + } + + private fun setListeners() { + binding.clTop.setOnClickListener(this) + binding.clBottom.setOnClickListener(this) + } fun createSpringAnimation( view: View?, @@ -113,74 +132,74 @@ class SpringActivity : AppCompatActivity() { @SuppressLint("ClickableViewAccessibility") private fun chainedSpringAnimation() { val xAnimation2 = createSpringAnimation( - viewBinding.imageView2, DynamicAnimation.X, viewBinding.imageView2.getX(), + binding.imageView2, DynamicAnimation.X, binding.imageView2.x, SpringForce.STIFFNESS_MEDIUM, SpringForce.DAMPING_RATIO_HIGH_BOUNCY ) val yAnimation2 = createSpringAnimation( - viewBinding.imageView2, DynamicAnimation.Y, viewBinding.imageView2.getY(), + binding.imageView2, DynamicAnimation.Y, binding.imageView2.y, SpringForce.STIFFNESS_MEDIUM, SpringForce.DAMPING_RATIO_HIGH_BOUNCY ) val xAnimation3 = createSpringAnimation( - viewBinding.imageView3, DynamicAnimation.X, viewBinding.imageView3.getX(), + binding.imageView3, DynamicAnimation.X, binding.imageView3.x, SpringForce.STIFFNESS_MEDIUM, SpringForce.DAMPING_RATIO_HIGH_BOUNCY ) val yAnimation3 = createSpringAnimation( - viewBinding.imageView3, DynamicAnimation.Y, viewBinding.imageView3.getY(), + binding.imageView3, DynamicAnimation.Y, binding.imageView3.y, SpringForce.STIFFNESS_MEDIUM, SpringForce.DAMPING_RATIO_HIGH_BOUNCY ) val xAnimation4 = createSpringAnimation( - viewBinding.imageView4, DynamicAnimation.X, viewBinding.imageView4.getX(), + binding.imageView4, DynamicAnimation.X, binding.imageView4.x, SpringForce.STIFFNESS_MEDIUM, SpringForce.DAMPING_RATIO_HIGH_BOUNCY ) val yAnimation4 = createSpringAnimation( - viewBinding.imageView4, DynamicAnimation.Y, viewBinding.imageView4.getY(), + binding.imageView4, DynamicAnimation.Y, binding.imageView4.y, SpringForce.STIFFNESS_MEDIUM, SpringForce.DAMPING_RATIO_HIGH_BOUNCY ) val xAnimation5 = createSpringAnimation( - viewBinding.imageView5, DynamicAnimation.X, viewBinding.imageView5.getX(), + binding.imageView5, DynamicAnimation.X, binding.imageView5.x, SpringForce.STIFFNESS_MEDIUM, SpringForce.DAMPING_RATIO_HIGH_BOUNCY ) val yAnimation5 = createSpringAnimation( - viewBinding.imageView5, DynamicAnimation.Y, viewBinding.imageView5.getY(), + binding.imageView5, DynamicAnimation.Y, binding.imageView5.y, SpringForce.STIFFNESS_MEDIUM, SpringForce.DAMPING_RATIO_HIGH_BOUNCY ) - val imageView2Params = viewBinding.imageView2.getLayoutParams() as MarginLayoutParams - val imageView3Params = viewBinding.imageView3.getLayoutParams() as MarginLayoutParams - val imageView4Params = viewBinding.imageView4.getLayoutParams() as MarginLayoutParams - val imageView5Params = viewBinding.imageView5.getLayoutParams() as MarginLayoutParams - xAnimation2.addUpdateListener { dynamicAnimation: DynamicAnimation<*>?, v: Float, v1: Float -> + val imageView2Params = binding.imageView2.layoutParams as MarginLayoutParams + val imageView3Params = binding.imageView3.layoutParams as MarginLayoutParams + val imageView4Params = binding.imageView4.layoutParams as MarginLayoutParams + val imageView5Params = binding.imageView5.layoutParams as MarginLayoutParams + xAnimation2.addUpdateListener { _: DynamicAnimation<*>?, v: Float, _: Float -> xAnimation3.animateToFinalPosition( - v + (viewBinding.imageView2.width - viewBinding.imageView3.width) / 2 + v + (binding.imageView2.width - binding.imageView3.width) / 2 ) } - yAnimation2.addUpdateListener { dynamicAnimation: DynamicAnimation<*>?, v: Float, v1: Float -> + yAnimation2.addUpdateListener { _: DynamicAnimation<*>?, v: Float, _: Float -> yAnimation3.animateToFinalPosition( - v + viewBinding.imageView2.height + imageView3Params.topMargin + v + binding.imageView2.height + imageView3Params.topMargin ) } - xAnimation3.addUpdateListener { dynamicAnimation: DynamicAnimation<*>?, v: Float, v1: Float -> + xAnimation3.addUpdateListener { _: DynamicAnimation<*>?, v: Float, _: Float -> xAnimation4.animateToFinalPosition( - v + (viewBinding.imageView3.width - viewBinding.imageView4.width) / 2 + v + (binding.imageView3.width - binding.imageView4.width) / 2 ) } - yAnimation3.addUpdateListener { dynamicAnimation: DynamicAnimation<*>?, v: Float, v1: Float -> + yAnimation3.addUpdateListener { _: DynamicAnimation<*>?, v: Float, _: Float -> yAnimation4.animateToFinalPosition( - v + viewBinding.imageView3.height + imageView4Params.topMargin + v + binding.imageView3.height + imageView4Params.topMargin ) } - xAnimation4.addUpdateListener { dynamicAnimation: DynamicAnimation<*>?, v: Float, v1: Float -> + xAnimation4.addUpdateListener { _: DynamicAnimation<*>?, v: Float, _: Float -> xAnimation5.animateToFinalPosition( - v + (viewBinding.imageView4.width - viewBinding.imageView5.width) / 2 + v + (binding.imageView4.width - binding.imageView5.width) / 2 ) } - yAnimation4.addUpdateListener { dynamicAnimation: DynamicAnimation<*>?, v: Float, v1: Float -> + yAnimation4.addUpdateListener { _: DynamicAnimation<*>?, v: Float, _: Float -> yAnimation5.animateToFinalPosition( - v + viewBinding.imageView4.height + imageView5Params.topMargin + v + binding.imageView4.height + imageView5Params.topMargin ) } - viewBinding.imageView.setOnTouchListener { view: View, motionEvent: MotionEvent -> + binding.imageView.setOnTouchListener { view: View, motionEvent: MotionEvent -> when (motionEvent.actionMasked) { MotionEvent.ACTION_DOWN -> { dX = view.x - motionEvent.rawX @@ -196,14 +215,31 @@ class SpringActivity : AppCompatActivity() { .setDuration(0) .start() xAnimation2.animateToFinalPosition( - newX + (viewBinding.imageView.width - viewBinding.imageView2.width) / 2 + newX + (binding.imageView.width - binding.imageView2.width) / 2 ) yAnimation2.animateToFinalPosition( - newY + viewBinding.imageView2.height + imageView2Params.topMargin + newY + binding.imageView2.height + imageView2Params.topMargin ) } } true } } + + override fun onClick(view: View?) { + when (view?.id) { + R.id.cl_top -> { + Timber.d("Dismiss bottom") + binding.springMotionLayout.setTransition(R.id.start, R.id.bottom_dismiss_end) +// binding.springMotionLayout.startLayoutAnimation() + binding.springMotionLayout.transitionToEnd() + } + + R.id.cl_bottom -> { + Timber.d("Dismiss top") + binding.springMotionLayout.setTransition(R.id.start, R.id.top_dismiss_end) + binding.springMotionLayout.transitionToEnd() + } + } + } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_song_player.xml b/app/src/main/res/layout/activity_song_player.xml index 7453d3b2..8617c15d 100644 --- a/app/src/main/res/layout/activity_song_player.xml +++ b/app/src/main/res/layout/activity_song_player.xml @@ -32,7 +32,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" app:layoutDescription="@xml/song_player_scene" - tools:context=".MainActivity" + tools:context=".ui.songplayer.SongPlayerActivity" tools:motionDebug="SHOW_ALL"> diff --git a/app/src/main/res/layout/activity_spring.xml b/app/src/main/res/layout/activity_spring.xml index 05d49adc..8f30b7e6 100644 --- a/app/src/main/res/layout/activity_spring.xml +++ b/app/src/main/res/layout/activity_spring.xml @@ -13,7 +13,7 @@ @@ -12,22 +10,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index a2cf768a..7610a602 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ ext { // version information versionMajor = 10 versionMinor = 8 - versionPatch = 1 + versionPatch = 2 versionName = "${versionMajor}.${versionMinor}.${versionPatch}" // Kotlin From 4bad0f0922f6069d2855e6e9560258f71f4b8a5a Mon Sep 17 00:00:00 2001 From: MichaelStH Date: Wed, 29 Sep 2021 20:39:16 +0200 Subject: [PATCH 04/11] [feat/041-spring-choice] : Spring animations done --- .../riders/thelab/ui/spring/SpringActivity.kt | 177 +++++++++++++++++- .../main/res/xml/activity_spring_scene.xml | 93 ++++++--- build.gradle | 12 +- 3 files changed, 239 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/com/riders/thelab/ui/spring/SpringActivity.kt b/app/src/main/java/com/riders/thelab/ui/spring/SpringActivity.kt index 87bd22f8..10273565 100644 --- a/app/src/main/java/com/riders/thelab/ui/spring/SpringActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/spring/SpringActivity.kt @@ -1,5 +1,6 @@ package com.riders.thelab.ui.spring +import android.animation.ObjectAnimator import android.annotation.SuppressLint import android.os.Bundle import android.view.MenuItem @@ -8,13 +9,19 @@ import android.view.View import android.view.View.OnTouchListener import android.view.ViewGroup.MarginLayoutParams import android.view.ViewTreeObserver.OnGlobalLayoutListener +import android.view.animation.BounceInterpolator import androidx.appcompat.app.AppCompatActivity import androidx.dynamicanimation.animation.DynamicAnimation import androidx.dynamicanimation.animation.DynamicAnimation.ViewProperty +import androidx.dynamicanimation.animation.FloatPropertyCompat import androidx.dynamicanimation.animation.SpringAnimation import androidx.dynamicanimation.animation.SpringForce import com.riders.thelab.R import com.riders.thelab.databinding.ActivitySpringBinding +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch import timber.log.Timber class SpringActivity : AppCompatActivity(), View.OnClickListener { @@ -84,6 +91,7 @@ class SpringActivity : AppCompatActivity(), View.OnClickListener { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + Timber.d("onCreate()") _viewBinding = ActivitySpringBinding.inflate(layoutInflater) setContentView(binding.root) @@ -102,6 +110,26 @@ class SpringActivity : AppCompatActivity(), View.OnClickListener { return true } + + override fun onBackPressed() { + Timber.d("onBackPressed()") + + if (isTopAnimationToggle) { + revertTopAnimation() + setListeners() + return + } + + if (isBottomAnimationToggle) { + revertBottomAnimation() + setListeners() + return + } + + + super.onBackPressed() + } + override fun onDestroy() { super.onDestroy() Timber.e("onDestroy()") @@ -109,11 +137,12 @@ class SpringActivity : AppCompatActivity(), View.OnClickListener { } private fun setListeners() { + Timber.d("setListeners()") binding.clTop.setOnClickListener(this) binding.clBottom.setOnClickListener(this) } - fun createSpringAnimation( + private fun createSpringAnimation( view: View?, property: ViewProperty?, finalPosition: Float, @@ -131,6 +160,7 @@ class SpringActivity : AppCompatActivity(), View.OnClickListener { @SuppressLint("ClickableViewAccessibility") private fun chainedSpringAnimation() { + Timber.d("chainedSpringAnimation()") val xAnimation2 = createSpringAnimation( binding.imageView2, DynamicAnimation.X, binding.imageView2.x, SpringForce.STIFFNESS_MEDIUM, SpringForce.DAMPING_RATIO_HIGH_BOUNCY @@ -226,20 +256,153 @@ class SpringActivity : AppCompatActivity(), View.OnClickListener { } } + override fun onClick(view: View?) { when (view?.id) { R.id.cl_top -> { - Timber.d("Dismiss bottom") - binding.springMotionLayout.setTransition(R.id.start, R.id.bottom_dismiss_end) -// binding.springMotionLayout.startLayoutAnimation() - binding.springMotionLayout.transitionToEnd() + Timber.d("Click on top then Dismiss bottom") + toggleTopAnimation() } R.id.cl_bottom -> { - Timber.d("Dismiss top") - binding.springMotionLayout.setTransition(R.id.start, R.id.top_dismiss_end) + Timber.d("Click on bottom then Dismiss top") + toggleBottomAnimation() + } + } + } + + private fun removeListeners() { + binding.clTop.setOnClickListener(null) + binding.clBottom.setOnClickListener(null) + } + + + /** + * This function moves the top card view to the center of the screen while fading out the bottom card view + * and display the multiple views in full screen + */ + private fun toggleTopAnimation() { + Timber.d("toggleTopAnimation()") + removeListeners() + isTopAnimationToggle = !isTopAnimationToggle + startChainedAnimations(R.id.start, R.id.bottom_dismiss_end, R.id.cl_views_container_end) + launchAnimations() + } + + + /** + * This function moves the bottom card view to the center of the screen while fading out the top card view + * and display the dot container in full screen + */ + private fun toggleBottomAnimation() { + Timber.d("toggleBottomAnimation()") + removeListeners() + isBottomAnimationToggle = !isBottomAnimationToggle + startChainedAnimations(R.id.start, R.id.top_dismiss_end, R.id.cl_dot_container_end) + } + + + /** + * This function should collapse the multiple spring views into the card view + * and then display the two buttons + */ + private fun revertTopAnimation() { + Timber.d("revertTopAnimation()") + startChainedAnimations(R.id.cl_views_container_end, R.id.bottom_dismiss_end, R.id.start) + isTopAnimationToggle = !isTopAnimationToggle + } + + /** + * This function should collapse the dot container view into the card view + * and then display the two buttons + */ + private fun revertBottomAnimation() { + Timber.d("revertBottomAnimation()") + startChainedAnimations(R.id.cl_dot_container_end, R.id.top_dismiss_end, R.id.start) + isBottomAnimationToggle = !isBottomAnimationToggle + } + + + /** + * Used to run animations avoid code redundancy + */ + private fun startChainedAnimations( + idTransitionStart: Int, + idTransitionEnd: Int, + idOnEndListenerTransitionEnd: Int + ) { + // Use idTransitionEnd as idOnEndListenerTransitionStart because the end point of the first animation + // will be the start point of the end listener animation + val idOnEndListenerTransitionStart: Int = idTransitionEnd + + binding.springMotionLayout.setTransition(idTransitionStart, idTransitionEnd) + binding.springMotionLayout.transitionToEnd { + Runnable { + Timber.d("Expand bottom") + binding.springMotionLayout.setTransition( + idOnEndListenerTransitionStart, + idOnEndListenerTransitionEnd + ) binding.springMotionLayout.transitionToEnd() + }.run() + } + } + + + private fun launchAnimations() { + CoroutineScope(Dispatchers.Main).launch { + launch { + delay(450) + setBounceAnimation(binding.tvTopLeft, "translationY") + } + launch { + delay(750) + getSpringAnimation( + binding.tvTopRight, + SpringAnimation.TRANSLATION_Y, + 100f + ).start() + } + + launch { + delay(500) + // Translation on bottom left + setBounceAnimation(binding.tvBottomLeft, "translationX") + } + launch { + delay(750) + // Scale on bottom right + getSpringAnimation(binding.tvBottomRight, SpringAnimation.SCALE_X, 0.8f).start() + getSpringAnimation(binding.tvBottomRight, SpringAnimation.SCALE_Y, 0.8f).start() } } } + + private fun setBounceAnimation(targetView: View, propertyName: String) { + val bounceInterpolator = BounceInterpolator() + val anim: ObjectAnimator = + ObjectAnimator.ofFloat(targetView, propertyName, 0f, -50f, 50f, 0f) + anim.interpolator = bounceInterpolator + anim + .setDuration(450) + .start() + } + + + private fun getSpringAnimation( + view: View, + springAnimationType: FloatPropertyCompat, + finalPosition: Float + ): SpringAnimation { + val animation = SpringAnimation(view, springAnimationType) + // create a spring with desired parameters + val spring = SpringForce() + spring.finalPosition = finalPosition + spring.stiffness = SpringForce.STIFFNESS_MEDIUM // optional + spring.dampingRatio = SpringForce.DAMPING_RATIO_HIGH_BOUNCY // optional + // set your animation's spring + animation.spring = spring + return animation + } + } \ No newline at end of file diff --git a/app/src/main/res/xml/activity_spring_scene.xml b/app/src/main/res/xml/activity_spring_scene.xml index 418bf78d..cc674a98 100644 --- a/app/src/main/res/xml/activity_spring_scene.xml +++ b/app/src/main/res/xml/activity_spring_scene.xml @@ -10,7 +10,9 @@ - + + + @@ -46,17 +48,9 @@ motion:layout_constraintTop_toTopOf="parent" /> + - - - - - - + @@ -92,47 +86,86 @@ motion:layout_constraintTop_toTopOf="parent" /> + + + + + + + + + + + + + - - - + + + + + + - + + + - - + + - --> + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 7610a602..6f6b8284 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ ext { // version information versionMajor = 10 versionMinor = 8 - versionPatch = 2 + versionPatch = 3 versionName = "${versionMajor}.${versionMinor}.${versionPatch}" // Kotlin @@ -24,7 +24,7 @@ ext { appCompatVersion = '1.3.1' materialVersion = '1.4.0' paletteVersion = '1.0.0' - constraintLayoutVersion = '2.1.0' + constraintLayoutVersion = '2.1.1' navigationFragmentVersion = '2.3.5' navigationUiVersion = '2.3.5' recyclerViewVersion = '1.2.1' @@ -44,7 +44,7 @@ ext { roomVersion = '2.3.0' - lifecycleVersion = '2.4.0-beta01' + lifecycleVersion = '2.4.0-rc01' hiltVersion = '2.38.1' hiltAndroidXVersion = '1.0.0' @@ -65,13 +65,13 @@ ext { // googleApiDriveV3Version = 'v3-rev110-1.23.0' playServicesAuthVersion = '19.2.0' mapsVersion = '17.0.1' - mapsUtilsVersion = '2.2.5' + mapsUtilsVersion = '2.2.6' locationVersion = '18.0.0' placesVersion = "2.4.0" firebaseBomVersion = '26.0.0' firebaseKtxVersion = '23.0.3' - adsVersion = '20.3.0' + adsVersion = '20.4.0' retrofit2Version = '2.9.0' okhttpBomVersion = '5.0.0-alpha.2' @@ -253,7 +253,7 @@ ext { buildscript { - ext.kotlin_version = "1.5.30" + ext.kotlin_version = "1.5.31" ext.hiltVersion = "2.38" ext.navigationVersion = "2.3.4" From 4890da72c6864fee5c8586706919a309cb763d9a Mon Sep 17 00:00:00 2001 From: MichaelStH Date: Wed, 29 Sep 2021 20:40:13 +0200 Subject: [PATCH 05/11] [feat/041-spring-choice] : Upgarde to version 10.8.4 --- app/build.gradle | 10 +++++++++- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index e4b289bb..fca43e09 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -109,7 +109,7 @@ android { } kotlinOptions { - jvmTarget = "1.8" + jvmTarget = '1.8' } compileOptions { @@ -118,6 +118,14 @@ android { } } +allprojects { + repositories { + flatDir { + dirs 'libs' + } + } +} + dependencies { ///////////////////////////// diff --git a/build.gradle b/build.gradle index 6f6b8284..1a0a9bc0 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ ext { // version information versionMajor = 10 versionMinor = 8 - versionPatch = 3 + versionPatch = 4 versionName = "${versionMajor}.${versionMinor}.${versionPatch}" // Kotlin diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5957359a..04785905 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Jul 20 12:09:29 CEST 2021 +#Wed Sep 29 20:33:16 CEST 2021 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME From 9bec0a1c01775b9af374bff4215813f4c7d2035f Mon Sep 17 00:00:00 2001 From: MichaelStH Date: Wed, 29 Sep 2021 21:48:11 +0200 Subject: [PATCH 06/11] [feat/041-spring-choice] : Fix build warnings + Upgrade to 10.8.5 --- app/src/main/AndroidManifest.xml | 3 +- .../riders/thelab/core/location/GpsUtils.kt | 2 +- .../thelab/core/okhttp/LabInterceptors.kt | 2 +- .../core/service/FloatingViewService.kt | 8 ++-- .../riders/thelab/core/utils/BrowserUtils.kt | 2 +- .../thelab/core/utils/LabAddressesUtils.kt | 5 +-- .../thelab/core/utils/LabDeviceManager.kt | 4 +- .../thelab/core/utils/LabLocationManager.kt | 4 +- .../com/riders/thelab/core/utils/UIManager.kt | 4 +- .../riders/thelab/data/local/model/app/App.kt | 4 +- .../data/remote/rest/WeatherRestClient.kt | 2 +- .../ui/builtin/BuiltInWebViewActivity.kt | 5 +-- .../ui/contacts/ContactDetailActivity.kt | 37 ++++++++++------ .../thelab/ui/contacts/ContactViewModel.kt | 1 - .../thelab/ui/contacts/ContactsActivity.kt | 43 +++++++++++-------- .../thelab/ui/contacts/ContactsAdapter.kt | 6 +-- .../filterlistview/FilterListViewActivity.kt | 29 ++++++++----- .../filterlistview/FilterListViewAdapter.kt | 36 ++++++++-------- .../ui/googledrive/GoogleDriveActivity.kt | 2 +- .../locationonmaps/LocationOnMapsActivity.kt | 6 +-- .../ui/mainactivity/RowAppViewHolder.kt | 2 +- .../thelab/ui/multipane/MoviesAdapter.kt | 2 +- .../ui/multipane/MultipaneDetailActivity.kt | 12 +++--- .../fragments/MultiPaneDetailFragment.kt | 2 +- .../thelab/ui/recycler/RecyclerViewAdapter.kt | 2 +- .../thelab/ui/recycler/RecyclerViewModel.kt | 6 +-- .../ui/speechtotext/SpeechToTextActivity.kt | 4 +- .../ui/weather/WeatherDownloadWorker.kt | 3 +- .../ui/weather/WeatherSearchViewAdapter.kt | 6 +-- .../youtubelike/YoutubeLikeDetailActivity.kt | 5 +-- build.gradle | 2 +- 31 files changed, 136 insertions(+), 115 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index bb8f360e..984b627a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -39,7 +39,8 @@ - + + diff --git a/app/src/main/java/com/riders/thelab/core/location/GpsUtils.kt b/app/src/main/java/com/riders/thelab/core/location/GpsUtils.kt index 1cd282f0..1f8740a1 100644 --- a/app/src/main/java/com/riders/thelab/core/location/GpsUtils.kt +++ b/app/src/main/java/com/riders/thelab/core/location/GpsUtils.kt @@ -58,7 +58,7 @@ class GpsUtils(private val context: Context) { // GPS is already enable, callback GPS status through listener onGpsListener.gpsStatus(true) } - ?.addOnFailureListener((context as Activity)) { exception -> + ?.addOnFailureListener(context) { exception -> when ((exception as ApiException).statusCode) { LocationSettingsStatusCodes.RESOLUTION_REQUIRED -> { diff --git a/app/src/main/java/com/riders/thelab/core/okhttp/LabInterceptors.kt b/app/src/main/java/com/riders/thelab/core/okhttp/LabInterceptors.kt index d46c6c99..b8396dea 100644 --- a/app/src/main/java/com/riders/thelab/core/okhttp/LabInterceptors.kt +++ b/app/src/main/java/com/riders/thelab/core/okhttp/LabInterceptors.kt @@ -45,7 +45,7 @@ class LabInterceptors { .newBuilder() .body( ResponseBody.create( - Objects.requireNonNull(response.body)!!.contentType(), + response.body?.contentType(), jsonResponse ) ) diff --git a/app/src/main/java/com/riders/thelab/core/service/FloatingViewService.kt b/app/src/main/java/com/riders/thelab/core/service/FloatingViewService.kt index 30e8e0c5..fcae1193 100644 --- a/app/src/main/java/com/riders/thelab/core/service/FloatingViewService.kt +++ b/app/src/main/java/com/riders/thelab/core/service/FloatingViewService.kt @@ -95,7 +95,7 @@ class FloatingViewService : Service() { //Set the next button. val nextButton = mFloatingView!!.findViewById(R.id.next_btn) as ImageView - nextButton.setOnClickListener { v: View? -> + nextButton.setOnClickListener { Toast.makeText( this@FloatingViewService, "Playing next song.", @@ -107,7 +107,7 @@ class FloatingViewService : Service() { //Set the pause button. val prevButton = mFloatingView!!.findViewById(R.id.prev_btn) as ImageView - prevButton.setOnClickListener { v: View? -> + prevButton.setOnClickListener { Toast.makeText( this@FloatingViewService, "Playing previous song.", @@ -119,7 +119,7 @@ class FloatingViewService : Service() { //Set the close button val closeButton = mFloatingView!!.findViewById(R.id.close_button) as ImageView - closeButton.setOnClickListener { view: View? -> + closeButton.setOnClickListener { collapsedView.visibility = View.VISIBLE expandedView.visibility = View.GONE } @@ -127,7 +127,7 @@ class FloatingViewService : Service() { //Open the application on thi button click val openButton = mFloatingView!!.findViewById(R.id.open_button) as ImageView - openButton.setOnClickListener { view: View? -> + openButton.setOnClickListener { //Open the application click. val intent = Intent(this@FloatingViewService, FloatingViewActivity::class.java) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) diff --git a/app/src/main/java/com/riders/thelab/core/utils/BrowserUtils.kt b/app/src/main/java/com/riders/thelab/core/utils/BrowserUtils.kt index a1f4c44d..23184967 100644 --- a/app/src/main/java/com/riders/thelab/core/utils/BrowserUtils.kt +++ b/app/src/main/java/com/riders/thelab/core/utils/BrowserUtils.kt @@ -9,7 +9,7 @@ class BrowserUtils private constructor() { companion object { fun isSameDomain(url: String, url1: String): Boolean { - return getRootDomainUrl(url.toLowerCase()) == getRootDomainUrl(url1.toLowerCase()) + return getRootDomainUrl(url.lowercase()) == getRootDomainUrl(url1.lowercase()) } private fun getRootDomainUrl(url: String): String { diff --git a/app/src/main/java/com/riders/thelab/core/utils/LabAddressesUtils.kt b/app/src/main/java/com/riders/thelab/core/utils/LabAddressesUtils.kt index 014da97f..ab82f93e 100644 --- a/app/src/main/java/com/riders/thelab/core/utils/LabAddressesUtils.kt +++ b/app/src/main/java/com/riders/thelab/core/utils/LabAddressesUtils.kt @@ -49,9 +49,7 @@ class LabAddressesUtils private constructor() { } } - fun buildAddress(address: Address): String? { - val finalCity = "" val addressStringBuilder = StringBuilder() val street = address.featureName + ", " + address.thoroughfare val locality = address.locality @@ -66,7 +64,8 @@ class LabAddressesUtils private constructor() { .append(departmentName).append(" - ") .append(regionName).append(" - ") .append(countryName) - Timber.d(addressStringBuilder.toString()) + val finalAddress = addressStringBuilder.toString() + Timber.d(finalAddress) return locality } } diff --git a/app/src/main/java/com/riders/thelab/core/utils/LabDeviceManager.kt b/app/src/main/java/com/riders/thelab/core/utils/LabDeviceManager.kt index 056704b6..86a054c7 100644 --- a/app/src/main/java/com/riders/thelab/core/utils/LabDeviceManager.kt +++ b/app/src/main/java/com/riders/thelab/core/utils/LabDeviceManager.kt @@ -151,7 +151,7 @@ class LabDeviceManager private constructor() { fun getScreenHeight(activity: Activity): Int { var screenHeight = 0 screenHeight = if (LabCompatibilityManager.isAndroid10() - && getModel().trim { it <= ' ' }.toLowerCase() + && getModel().trim { it <= ' ' }.lowercase() .contains(Constants.EMULATOR_DEVICE_TAG) ) { val metrics = getDisplayMetricsAndroid10(activity) @@ -167,7 +167,7 @@ class LabDeviceManager private constructor() { fun getScreenWidth(activity: Activity): Int { var screenWidth = 0 screenWidth = if (LabCompatibilityManager.isAndroid10() - && getModel().trim { it <= ' ' }.toLowerCase() + && getModel().trim { it <= ' ' }.lowercase() .contains(Constants.EMULATOR_DEVICE_TAG) ) { val metrics = getDisplayMetricsAndroid10(activity) diff --git a/app/src/main/java/com/riders/thelab/core/utils/LabLocationManager.kt b/app/src/main/java/com/riders/thelab/core/utils/LabLocationManager.kt index c3114ac9..ab6acfef 100644 --- a/app/src/main/java/com/riders/thelab/core/utils/LabLocationManager.kt +++ b/app/src/main/java/com/riders/thelab/core/utils/LabLocationManager.kt @@ -267,7 +267,7 @@ class LabLocationManager constructor( // On pressing Settings button alertDialog.setPositiveButton( "Settings" - ) { dialog: DialogInterface?, which: Int -> + ) { _: DialogInterface?, _: Int -> val intent = Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS ) @@ -277,7 +277,7 @@ class LabLocationManager constructor( // on pressing cancel button alertDialog.setNegativeButton( "Cancel" - ) { dialog: DialogInterface, which: Int -> dialog.cancel() } + ) { dialog: DialogInterface, _: Int -> dialog.cancel() } // Showing Alert Message alertDialog.show() diff --git a/app/src/main/java/com/riders/thelab/core/utils/UIManager.kt b/app/src/main/java/com/riders/thelab/core/utils/UIManager.kt index 1953e9cf..70a6dba6 100644 --- a/app/src/main/java/com/riders/thelab/core/utils/UIManager.kt +++ b/app/src/main/java/com/riders/thelab/core/utils/UIManager.kt @@ -78,7 +78,7 @@ class UIManager private constructor() { // Setting Dialog Message alertDialog.setMessage(message) - alertDialog.setNegativeButton(negativeMessage) { dialog: DialogInterface, which: Int -> + alertDialog.setNegativeButton(negativeMessage) { dialog: DialogInterface, _: Int -> showActionInToast(context, negativeMessage) if (negativeMessage.equals("Réessayer", ignoreCase = true)) { //launchActivity(context, MainActivity.class, Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED|Intent.FLAG_ACTIVITY_NEW_TASK, null, null); @@ -89,7 +89,7 @@ class UIManager private constructor() { dialog.dismiss() } } - alertDialog.setPositiveButton(positiveMessage) { dialog: DialogInterface?, which: Int -> + alertDialog.setPositiveButton(positiveMessage) { _: DialogInterface?, _: Int -> showActionInToast(context, positiveMessage) activity?.onBackPressed() if (negativeMessage.equals("Quitter", ignoreCase = true)) { diff --git a/app/src/main/java/com/riders/thelab/data/local/model/app/App.kt b/app/src/main/java/com/riders/thelab/data/local/model/app/App.kt index 42f42932..96a21ec7 100644 --- a/app/src/main/java/com/riders/thelab/data/local/model/app/App.kt +++ b/app/src/main/java/com/riders/thelab/data/local/model/app/App.kt @@ -59,7 +59,7 @@ data class App( } parcel.writeParcelable(bitmap, flags) - appName?.let { parcel.writeString(appName) } + appName.let { parcel.writeString(appName) } parcel.writeString(appVersion) parcel.writeString(appPackageName) parcel.writeString(appTitle) @@ -73,7 +73,7 @@ data class App( @IgnoredOnParcel private var name: String? = null - //@IgnoredOnParcel + @IgnoredOnParcel private var drawableIcon: Drawable? = null @IgnoredOnParcel diff --git a/app/src/main/java/com/riders/thelab/data/remote/rest/WeatherRestClient.kt b/app/src/main/java/com/riders/thelab/data/remote/rest/WeatherRestClient.kt index 1288d819..f68a19cd 100644 --- a/app/src/main/java/com/riders/thelab/data/remote/rest/WeatherRestClient.kt +++ b/app/src/main/java/com/riders/thelab/data/remote/rest/WeatherRestClient.kt @@ -27,7 +27,7 @@ class WeatherRestClient { .addInterceptor(Interceptor { chain: Interceptor.Chain -> val original = chain.request() val originalHttpUrl = original.url - var url: HttpUrl? = null + var url: HttpUrl? // Request customization: add request headers url = originalHttpUrl.newBuilder() diff --git a/app/src/main/java/com/riders/thelab/ui/builtin/BuiltInWebViewActivity.kt b/app/src/main/java/com/riders/thelab/ui/builtin/BuiltInWebViewActivity.kt index 640f5f24..c7b6b78e 100644 --- a/app/src/main/java/com/riders/thelab/ui/builtin/BuiltInWebViewActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/builtin/BuiltInWebViewActivity.kt @@ -6,7 +6,6 @@ import android.os.Bundle import android.text.TextUtils import android.view.MotionEvent import android.view.View -import android.view.View.OnTouchListener import android.webkit.WebView import android.webkit.WebViewClient import androidx.appcompat.app.AppCompatActivity @@ -81,7 +80,7 @@ class BuiltInWebViewActivity : AppCompatActivity() { viewBinding.contentBuiltInWebview.builtInWebView.clearHistory() viewBinding.contentBuiltInWebview.builtInWebView.settings.javaScriptEnabled = true viewBinding.contentBuiltInWebview.builtInWebView.isHorizontalScrollBarEnabled = false - viewBinding.contentBuiltInWebview.builtInWebView.setOnTouchListener(OnTouchListener { v: View?, event: MotionEvent -> + viewBinding.contentBuiltInWebview.builtInWebView.setOnTouchListener { _: View?, event: MotionEvent -> if (event.pointerCount > 1) { //Multi touch detected true @@ -92,7 +91,7 @@ class BuiltInWebViewActivity : AppCompatActivity() { event.setLocation(m_downX, event.y) } false - }) + } } private fun renderPost() { diff --git a/app/src/main/java/com/riders/thelab/ui/contacts/ContactDetailActivity.kt b/app/src/main/java/com/riders/thelab/ui/contacts/ContactDetailActivity.kt index eac9474a..e97a3d2c 100644 --- a/app/src/main/java/com/riders/thelab/ui/contacts/ContactDetailActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/contacts/ContactDetailActivity.kt @@ -24,33 +24,38 @@ class ContactDetailActivity : AppCompatActivity() { private var mContext: Context? = null + private var _viewBinding: ActivityContactsDetailBinding? = null + + // This property is only valid between onCreateView and + // onDestroyView. + private val binding get() = _viewBinding!! + var itemNameDetail: String? = null var itemSurnameDetail: String? = null var itemEmailDetail: String? = null var itemImage: String? = null - lateinit var viewBinding: ActivityContactsDetailBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - viewBinding = ActivityContactsDetailBinding.inflate(layoutInflater) - setContentView(viewBinding.root) + _viewBinding = ActivityContactsDetailBinding.inflate(layoutInflater) + setContentView(binding.root) mContext = this getBundle() - ViewCompat.setTransitionName(viewBinding.appBarLayout, "icon") + ViewCompat.setTransitionName(binding.appBarLayout, "icon") supportPostponeEnterTransition() /*setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true);*/ - setSupportActionBar(viewBinding.contactDetailToolbar) + setSupportActionBar(binding.contactDetailToolbar) supportActionBar!!.setDisplayHomeAsUpEnabled(true) - viewBinding.contactDetailCollapsingToolbar.title = itemNameDetail - viewBinding.contactDetailCollapsingToolbar.setExpandedTitleColor( + binding.contactDetailCollapsingToolbar.title = itemNameDetail + binding.contactDetailCollapsingToolbar.setExpandedTitleColor( ContextCompat.getColor( this, R.color.transparent @@ -58,8 +63,8 @@ class ContactDetailActivity : AppCompatActivity() { ) // getSupportActionBar().setTitle(itemNameDetail); - viewBinding.appBarLayout.setExpanded(true) - viewBinding.appBarLayout.addOnOffsetChangedListener(object : OnOffsetChangedListener { + binding.appBarLayout.setExpanded(true) + binding.appBarLayout.addOnOffsetChangedListener(object : OnOffsetChangedListener { var isShow = false var scrollRange = -1 override fun onOffsetChanged(appBarLayout: AppBarLayout, verticalOffset: Int) { @@ -67,16 +72,22 @@ class ContactDetailActivity : AppCompatActivity() { scrollRange = appBarLayout.totalScrollRange } if (scrollRange + verticalOffset == 0) { - viewBinding.contactDetailCollapsingToolbar.title = itemNameDetail + binding.contactDetailCollapsingToolbar.title = itemNameDetail isShow = true } else if (isShow) { - viewBinding.contactDetailCollapsingToolbar.title = " " + binding.contactDetailCollapsingToolbar.title = " " isShow = false } } }) } + override fun onDestroy() { + super.onDestroy() + Timber.e("onDestroy()") + _viewBinding = null + } + private fun getBundle() { val bundle = intent.extras if (null == bundle) { @@ -90,7 +101,7 @@ class ContactDetailActivity : AppCompatActivity() { } private fun setViews() { - viewBinding.tvNameDetail.text = itemNameDetail - viewBinding.tvEmailDetail.text = itemEmailDetail + binding.tvNameDetail.text = itemNameDetail + binding.tvEmailDetail.text = itemEmailDetail } } \ No newline at end of file diff --git a/app/src/main/java/com/riders/thelab/ui/contacts/ContactViewModel.kt b/app/src/main/java/com/riders/thelab/ui/contacts/ContactViewModel.kt index 0b6a4dd2..f39956a8 100644 --- a/app/src/main/java/com/riders/thelab/ui/contacts/ContactViewModel.kt +++ b/app/src/main/java/com/riders/thelab/ui/contacts/ContactViewModel.kt @@ -1,6 +1,5 @@ package com.riders.thelab.ui.contacts - import android.content.Intent import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData diff --git a/app/src/main/java/com/riders/thelab/ui/contacts/ContactsActivity.kt b/app/src/main/java/com/riders/thelab/ui/contacts/ContactsActivity.kt index 559927b4..d080ec63 100644 --- a/app/src/main/java/com/riders/thelab/ui/contacts/ContactsActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/contacts/ContactsActivity.kt @@ -24,26 +24,29 @@ import timber.log.Timber import java.util.* @AndroidEntryPoint -class ContactsActivity : AppCompatActivity(), ContactsClickListener, - RecyclerItemTouchHelperListener { +class ContactsActivity + : AppCompatActivity(), ContactsClickListener, RecyclerItemTouchHelperListener { - lateinit var viewBinding: ActivityContactsBinding - private var searchView: SearchView? = null + private var _viewBinding: ActivityContactsBinding? = null - private var mAdapter: ContactsAdapter? = null + // This property is only valid between onCreateView and + // onDestroyView. + private val binding get() = _viewBinding!! - private val mContactViewModel: ContactViewModel by viewModels() + private var searchView: SearchView? = null + private val mContactViewModel: ContactViewModel by viewModels() private var contactList: List? = null + private var mAdapter: ContactsAdapter? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - viewBinding = ActivityContactsBinding.inflate(layoutInflater) - setContentView(viewBinding.root) + _viewBinding = ActivityContactsBinding.inflate(layoutInflater) + setContentView(binding.root) - setSupportActionBar(viewBinding.toolbar) + setSupportActionBar(binding.toolbar) supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) @@ -57,7 +60,7 @@ class ContactsActivity : AppCompatActivity(), ContactsClickListener, mContactViewModel .getNoContactFound() .observe(this, { - viewBinding.noContactFoundLayoutContainer.layoutNoContactsFound.visibility = + binding.noContactFoundLayoutContainer.layoutNoContactsFound.visibility = View.VISIBLE }) @@ -80,9 +83,9 @@ class ContactsActivity : AppCompatActivity(), ContactsClickListener, ) val linearLayoutManager = LinearLayoutManager(this@ContactsActivity) - viewBinding.contactsLayoutContainer.rvContacts.layoutManager = linearLayoutManager - viewBinding.contactsLayoutContainer.rvContacts.itemAnimator = DefaultItemAnimator() - viewBinding.contactsLayoutContainer.rvContacts.adapter = mAdapter + binding.contactsLayoutContainer.rvContacts.layoutManager = linearLayoutManager + binding.contactsLayoutContainer.rvContacts.itemAnimator = DefaultItemAnimator() + binding.contactsLayoutContainer.rvContacts.adapter = mAdapter // adding item touch helper // only ItemTouchHelper.LEFT added to detect Right to Left swipe @@ -91,10 +94,10 @@ class ContactsActivity : AppCompatActivity(), ContactsClickListener, val itemTouchHelperCallback: ItemTouchHelper.SimpleCallback = RecyclerItemTouchHelper(0, ItemTouchHelper.LEFT, this) ItemTouchHelper(itemTouchHelperCallback) - .attachToRecyclerView(viewBinding.contactsLayoutContainer.rvContacts) + .attachToRecyclerView(binding.contactsLayoutContainer.rvContacts) }) - viewBinding.noContactFoundLayoutContainer.btnAddNewContact.setOnClickListener { + binding.noContactFoundLayoutContainer.btnAddNewContact.setOnClickListener { Navigator(this).callAddContactActivity() } } @@ -163,6 +166,12 @@ class ContactsActivity : AppCompatActivity(), ContactsClickListener, } } + override fun onDestroy() { + super.onDestroy() + Timber.e("onDestroy()") + _viewBinding = null + } + override fun onContactItemCLickListener(item: Contact, position: Int) { Timber.d("contact %s clicked", item.toString()) @@ -185,7 +194,7 @@ class ContactsActivity : AppCompatActivity(), ContactsClickListener, // showing snack bar with Undo option UIManager.showActionInSnackBar( this, - viewBinding.coordinator, + binding.coordinator, "$name removed from cart!", SnackBarType.WARNING, "UNDO" @@ -197,6 +206,4 @@ class ContactsActivity : AppCompatActivity(), ContactsClickListener, } } } - - } \ No newline at end of file diff --git a/app/src/main/java/com/riders/thelab/ui/contacts/ContactsAdapter.kt b/app/src/main/java/com/riders/thelab/ui/contacts/ContactsAdapter.kt index 7321d96c..c4e2ec60 100644 --- a/app/src/main/java/com/riders/thelab/ui/contacts/ContactsAdapter.kt +++ b/app/src/main/java/com/riders/thelab/ui/contacts/ContactsAdapter.kt @@ -32,7 +32,7 @@ class ContactsAdapter( val item = contactListFiltered!![position] holder.bindData(item) - holder.viewBinding.cvContactItem.setOnClickListener { view: View? -> + holder.viewBinding.cvContactItem.setOnClickListener { listener.onContactItemCLickListener( item, holder.adapterPosition @@ -61,8 +61,8 @@ class ContactsAdapter( // name match condition. this might differ depending on your requirement // here we are looking for name or phone number match - if (row.name.toLowerCase(Locale.ROOT) - .contains(charString.toLowerCase(Locale.ROOT)) + if (row.name.lowercase() + .contains(charString.lowercase()) || row.email.contains(charSequence) ) { filteredList.add(row) diff --git a/app/src/main/java/com/riders/thelab/ui/filterlistview/FilterListViewActivity.kt b/app/src/main/java/com/riders/thelab/ui/filterlistview/FilterListViewActivity.kt index 3dc8a42c..ee3cbcfd 100644 --- a/app/src/main/java/com/riders/thelab/ui/filterlistview/FilterListViewActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/filterlistview/FilterListViewActivity.kt @@ -16,19 +16,22 @@ import java.util.* @AndroidEntryPoint class FilterListViewActivity : AppCompatActivity(), TextWatcher { - var mWorldPopulationList: ArrayList? = null - lateinit var adapter: FilterListViewAdapter - - lateinit var viewBinding: ActivityFilterListviewBinding + private var _viewBinding: ActivityFilterListviewBinding? = null + // This property is only valid between onCreateView and + // onDestroyView. + private val binding get() = _viewBinding!! private val mFilterViewModel: FilterListViewModel by viewModels() + var mWorldPopulationList: ArrayList? = null + lateinit var adapter: FilterListViewAdapter + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - viewBinding = ActivityFilterListviewBinding.inflate(layoutInflater) - setContentView(viewBinding.root) + _viewBinding = ActivityFilterListviewBinding.inflate(layoutInflater) + setContentView(binding.root) setAdapter() @@ -40,10 +43,10 @@ class FilterListViewActivity : AppCompatActivity(), TextWatcher { adapter = FilterListViewAdapter(this, list as MutableList) // Binds the Adapter to the ListView - viewBinding.lvFilterListview.adapter = adapter + binding.lvFilterListview.adapter = adapter // Capture Text in EditText - viewBinding.etFilterListviewSearch.addTextChangedListener(this) + binding.etFilterListviewSearch.addTextChangedListener(this) }) } @@ -56,6 +59,13 @@ class FilterListViewActivity : AppCompatActivity(), TextWatcher { return true } + override fun onDestroy() { + super.onDestroy() + Timber.e("onDestroy()") + _viewBinding = null + } + + private fun setAdapter() { mFilterViewModel.generatePopulationList() } @@ -67,8 +77,7 @@ class FilterListViewActivity : AppCompatActivity(), TextWatcher { } override fun afterTextChanged(s: Editable?) { - val text: String = - viewBinding.etFilterListviewSearch.text.toString().toLowerCase(Locale.getDefault()) + val text: String = binding.etFilterListviewSearch.text.toString().lowercase() adapter.filter(text) } } \ No newline at end of file diff --git a/app/src/main/java/com/riders/thelab/ui/filterlistview/FilterListViewAdapter.kt b/app/src/main/java/com/riders/thelab/ui/filterlistview/FilterListViewAdapter.kt index 73e54e20..f6652164 100644 --- a/app/src/main/java/com/riders/thelab/ui/filterlistview/FilterListViewAdapter.kt +++ b/app/src/main/java/com/riders/thelab/ui/filterlistview/FilterListViewAdapter.kt @@ -9,8 +9,6 @@ import android.widget.BaseAdapter import com.google.android.material.textview.MaterialTextView import com.riders.thelab.R import com.riders.thelab.data.local.model.WorldPopulation -import java.util.* -import kotlin.collections.ArrayList class FilterListViewAdapter(context: Context, worldPopulationList: MutableList) : @@ -42,31 +40,33 @@ class FilterListViewAdapter(context: Context, worldPopulationList: MutableList listener.onMovieClicked(movie) } + holder.viewBinding.cvMultiPaneItem.setOnClickListener { listener.onMovieClicked(movie) } } } \ No newline at end of file diff --git a/app/src/main/java/com/riders/thelab/ui/multipane/MultipaneDetailActivity.kt b/app/src/main/java/com/riders/thelab/ui/multipane/MultipaneDetailActivity.kt index 07ac4298..6997661e 100644 --- a/app/src/main/java/com/riders/thelab/ui/multipane/MultipaneDetailActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/multipane/MultipaneDetailActivity.kt @@ -6,7 +6,6 @@ import com.bumptech.glide.Glide import com.riders.thelab.data.local.model.Movie import com.riders.thelab.databinding.ActivityMultiPaneDetailBinding import timber.log.Timber -import java.util.* class MultipaneDetailActivity : AppCompatActivity() { companion object { @@ -28,10 +27,13 @@ class MultipaneDetailActivity : AppCompatActivity() { Timber.e("Bundle is null exit activity.") finish() } - val movie: Movie? = Objects.requireNonNull(bundle)!!.getParcelable(EXTRA_MOVIE) - if (movie != null) { - supportActionBar?.title = movie.title - setViews(movie) + + bundle?.let { + val movie: Movie? = it.getParcelable(EXTRA_MOVIE) + if (movie != null) { + supportActionBar?.title = movie.title + setViews(movie) + } } } diff --git a/app/src/main/java/com/riders/thelab/ui/multipane/fragments/MultiPaneDetailFragment.kt b/app/src/main/java/com/riders/thelab/ui/multipane/fragments/MultiPaneDetailFragment.kt index c28198f4..d915e239 100644 --- a/app/src/main/java/com/riders/thelab/ui/multipane/fragments/MultiPaneDetailFragment.kt +++ b/app/src/main/java/com/riders/thelab/ui/multipane/fragments/MultiPaneDetailFragment.kt @@ -84,7 +84,7 @@ class MultiPaneDetailFragment : Fragment() { Timber.e("URL RECEIVE : %s", movie.urlThumbnail) - Glide.with(Objects.requireNonNull(activity)!!) + Glide.with(requireActivity()) .load(movie.urlThumbnail) .listener(object : RequestListener { override fun onLoadFailed( diff --git a/app/src/main/java/com/riders/thelab/ui/recycler/RecyclerViewAdapter.kt b/app/src/main/java/com/riders/thelab/ui/recycler/RecyclerViewAdapter.kt index 0a5baf63..294a5933 100644 --- a/app/src/main/java/com/riders/thelab/ui/recycler/RecyclerViewAdapter.kt +++ b/app/src/main/java/com/riders/thelab/ui/recycler/RecyclerViewAdapter.kt @@ -102,7 +102,7 @@ class RecyclerViewAdapter( position ) } - holder.viewBinding.rowDeleteBtn.setOnClickListener { deleteView: View? -> + holder.viewBinding.rowDeleteBtn.setOnClickListener { Timber.e("setOnClickListener deleteView ") listener.onDeleteClick(artist, position) } diff --git a/app/src/main/java/com/riders/thelab/ui/recycler/RecyclerViewModel.kt b/app/src/main/java/com/riders/thelab/ui/recycler/RecyclerViewModel.kt index ec5ad9a6..f436cebf 100644 --- a/app/src/main/java/com/riders/thelab/ui/recycler/RecyclerViewModel.kt +++ b/app/src/main/java/com/riders/thelab/ui/recycler/RecyclerViewModel.kt @@ -177,7 +177,7 @@ class RecyclerViewModel @Inject constructor( Timber.e(throwable) return@addOnFailureListener } - .addOnCompleteListener { taskResult: Task? -> + .addOnCompleteListener { return@addOnCompleteListener } @@ -197,7 +197,7 @@ class RecyclerViewModel @Inject constructor( Timber.e(throwable) return@addOnFailureListener } - .addOnCompleteListener { task1: Task? -> + .addOnCompleteListener { return@addOnCompleteListener } } @@ -274,7 +274,7 @@ class RecyclerViewModel @Inject constructor( activity, activity.findViewById(android.R.id.content), "$name removed from cart!", SnackBarType.WARNING, "UNDO" - ) { view: View? -> + ) { // undo is selected, restore the deleted item adapter.restoreItem(item, position) } diff --git a/app/src/main/java/com/riders/thelab/ui/speechtotext/SpeechToTextActivity.kt b/app/src/main/java/com/riders/thelab/ui/speechtotext/SpeechToTextActivity.kt index 943fca0c..17343155 100644 --- a/app/src/main/java/com/riders/thelab/ui/speechtotext/SpeechToTextActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/speechtotext/SpeechToTextActivity.kt @@ -241,8 +241,6 @@ class SpeechToTextActivity : AppCompatActivity(), RecognitionListener { override fun onResults(results: Bundle?) { Timber.e("onResults()") - var result = "" - val matches = results!!.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION) for (element in matches!!) Timber.d(element) @@ -260,7 +258,7 @@ class SpeechToTextActivity : AppCompatActivity(), RecognitionListener { hideEq() } - result = matches[0] + val result: String = matches[0] viewBinding.speechInputTextView.text = result } diff --git a/app/src/main/java/com/riders/thelab/ui/weather/WeatherDownloadWorker.kt b/app/src/main/java/com/riders/thelab/ui/weather/WeatherDownloadWorker.kt index fe730f3a..267de160 100644 --- a/app/src/main/java/com/riders/thelab/ui/weather/WeatherDownloadWorker.kt +++ b/app/src/main/java/com/riders/thelab/ui/weather/WeatherDownloadWorker.kt @@ -130,8 +130,7 @@ class WeatherDownloadWorker @AssistedInject constructor( CoroutineScope(Dispatchers.IO).launch { try { - val job = mRepository.saveCities(dtoCities) - + mRepository.saveCities(dtoCities) mRepository.insertWeatherData(WeatherData(0, true)) outputData = createOutputData(WORK_RESULT, WORK_SUCCESS) future!!.set(Result.success(outputData!!)) diff --git a/app/src/main/java/com/riders/thelab/ui/weather/WeatherSearchViewAdapter.kt b/app/src/main/java/com/riders/thelab/ui/weather/WeatherSearchViewAdapter.kt index 07d22f4d..34f25b7a 100644 --- a/app/src/main/java/com/riders/thelab/ui/weather/WeatherSearchViewAdapter.kt +++ b/app/src/main/java/com/riders/thelab/ui/weather/WeatherSearchViewAdapter.kt @@ -15,7 +15,6 @@ import com.riders.thelab.R import com.riders.thelab.core.utils.LabCompatibilityManager import com.riders.thelab.data.local.model.weather.CityModel import com.riders.thelab.utils.Constants -import java.util.* @SuppressLint("RestrictedApi") class WeatherSearchViewAdapter( @@ -52,15 +51,14 @@ class WeatherSearchViewAdapter( .load(countryURL) .into(ivCityFlag) - view.setOnClickListener { view1: View? -> + view.setOnClickListener { //take next action based user selected item if (!LabCompatibilityManager.isOreo()) { if (!mSearchView.isIconified) { mSearchView.isIconified = true } } else { - Objects.requireNonNull((context as WeatherActivity).supportActionBar) - ?.collapseActionView() + (context as WeatherActivity).supportActionBar?.collapseActionView() } mListener.onWeatherItemClicked(CityModel(cursor)) } diff --git a/app/src/main/java/com/riders/thelab/ui/youtubelike/YoutubeLikeDetailActivity.kt b/app/src/main/java/com/riders/thelab/ui/youtubelike/YoutubeLikeDetailActivity.kt index 05350cb2..c2d37dcc 100644 --- a/app/src/main/java/com/riders/thelab/ui/youtubelike/YoutubeLikeDetailActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/youtubelike/YoutubeLikeDetailActivity.kt @@ -65,7 +65,7 @@ class YoutubeLikeDetailActivity : AppCompatActivity() { } private fun loadContent() { - Objects.requireNonNull(supportActionBar)?.title = item.name + supportActionBar?.title = item.name //Load the background thumb image Glide.with(this) @@ -123,8 +123,7 @@ class YoutubeLikeDetailActivity : AppCompatActivity() { //il se peut que la palette ne génère pas tous les swatch if (muted != null) { //j'utilise getRgb() en tant que couleur de fond de ma toolbar - Objects.requireNonNull(supportActionBar) - ?.setBackgroundDrawable(ColorDrawable(muted.rgb)) + supportActionBar?.setBackgroundDrawable(ColorDrawable(muted.rgb)) } } run { diff --git a/build.gradle b/build.gradle index 1a0a9bc0..4ca4939b 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ ext { // version information versionMajor = 10 versionMinor = 8 - versionPatch = 4 + versionPatch = 5 versionName = "${versionMajor}.${versionMinor}.${versionPatch}" // Kotlin From 89bd059258fc9d084da6d9af5c7695468515511e Mon Sep 17 00:00:00 2001 From: MichaelStH Date: Wed, 29 Sep 2021 23:00:13 +0200 Subject: [PATCH 07/11] [feat/041-spring-choice] : Working tabs updated to viewpager2 --- .../riders/thelab/ui/tabs/WorkingFragment.kt | 61 ++++++++++++++++++ .../thelab/ui/tabs/WorkingTabsActivity.kt | 63 +++++++------------ .../thelab/ui/tabs/WorkingTabsAdapter.kt | 40 ++++++++++++ app/src/main/res/layout/activity_tabs.xml | 8 +-- build.gradle | 4 +- 5 files changed, 129 insertions(+), 47 deletions(-) create mode 100644 app/src/main/java/com/riders/thelab/ui/tabs/WorkingFragment.kt create mode 100644 app/src/main/java/com/riders/thelab/ui/tabs/WorkingTabsAdapter.kt diff --git a/app/src/main/java/com/riders/thelab/ui/tabs/WorkingFragment.kt b/app/src/main/java/com/riders/thelab/ui/tabs/WorkingFragment.kt new file mode 100644 index 00000000..e4916874 --- /dev/null +++ b/app/src/main/java/com/riders/thelab/ui/tabs/WorkingFragment.kt @@ -0,0 +1,61 @@ +package com.riders.thelab.ui.tabs + +import android.annotation.SuppressLint +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import com.riders.thelab.databinding.FragmentOneBinding + +// Instances of this class are fragments representing a single +// object in our collection. +class WorkingFragment : Fragment() { + + companion object { + + private const val ARG_OBJ = "arg_obj" + + fun newInstance(position: Int): WorkingFragment { + val fragment = WorkingFragment() + val args = Bundle() + args.putInt(ARG_OBJ, position) + fragment.arguments = args + return fragment + } + } + + private var _viewBinding: FragmentOneBinding? = null + + // This property is only valid between onCreateView and + // onDestroyView. + private val binding get() = _viewBinding!! + + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + _viewBinding = FragmentOneBinding.inflate(inflater, container, false) + return binding.root + } + + @SuppressLint("SetTextI18n") + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + arguments?.let { bundle -> + bundle.getInt(ARG_OBJ).let { position -> + binding.tv.text = "Position : $position" + } + } + + } + + override fun onDestroyView() { + super.onDestroyView() + + _viewBinding = null + } +} \ No newline at end of file diff --git a/app/src/main/java/com/riders/thelab/ui/tabs/WorkingTabsActivity.kt b/app/src/main/java/com/riders/thelab/ui/tabs/WorkingTabsActivity.kt index 55ad8f79..40c1ae99 100644 --- a/app/src/main/java/com/riders/thelab/ui/tabs/WorkingTabsActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/tabs/WorkingTabsActivity.kt @@ -3,31 +3,35 @@ package com.riders.thelab.ui.tabs import android.os.Bundle import android.view.MenuItem import androidx.appcompat.app.AppCompatActivity -import androidx.fragment.app.Fragment -import androidx.fragment.app.FragmentManager -import androidx.fragment.app.FragmentPagerAdapter -import androidx.viewpager.widget.ViewPager +import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayoutMediator import com.riders.thelab.databinding.ActivityTabsBinding import com.riders.thelab.ui.tabs.fragment.OneFragment import com.riders.thelab.ui.tabs.fragment.ThreeFragment import com.riders.thelab.ui.tabs.fragment.TwoFragment -import java.util.* +import timber.log.Timber class WorkingTabsActivity : AppCompatActivity() { - lateinit var viewBinding: ActivityTabsBinding + private var _viewBinding: ActivityTabsBinding? = null + + // This property is only valid between onCreateView and + // onDestroyView. + private val binding get() = _viewBinding!! override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - viewBinding = ActivityTabsBinding.inflate(layoutInflater) - setContentView(viewBinding.root) + _viewBinding = ActivityTabsBinding.inflate(layoutInflater) + setContentView(binding.root) - setSupportActionBar(viewBinding.tabToolbar) + setSupportActionBar(binding.tabToolbar) - setupViewPager(viewBinding.tabViewPager) + setupViewPager(binding.tabViewPager2) - viewBinding.tabs.setupWithViewPager(viewBinding.tabViewPager) + TabLayoutMediator(binding.tabs, binding.tabViewPager2) { tab, position -> + tab.text = "OBJECT ${(position + 1)}" + }.attach() } override fun onOptionsItemSelected(item: MenuItem): Boolean { @@ -39,39 +43,18 @@ class WorkingTabsActivity : AppCompatActivity() { return true } + override fun onDestroy() { + super.onDestroy() + Timber.e("onDestroy()") + _viewBinding = null + } + - private fun setupViewPager(viewPager: ViewPager) { - val adapter = ViewPagerAdapter(supportFragmentManager) + private fun setupViewPager(viewPager: ViewPager2) { + val adapter = WorkingTabsAdapter(supportFragmentManager, lifecycle) adapter.addFragment(OneFragment.newInstance(), "ONE") adapter.addFragment(TwoFragment.newInstance(), "TWO") adapter.addFragment(ThreeFragment.newInstance(), "THREE") viewPager.adapter = adapter } - - - private class ViewPagerAdapter(manager: FragmentManager?) : - FragmentPagerAdapter(manager!!) { - - private val mFragmentList: MutableList = ArrayList() - private val mFragmentTitleList: MutableList = ArrayList() - - override fun getItem(position: Int): Fragment { - return mFragmentList[position] - } - - override fun getCount(): Int { - return mFragmentList.size - } - - fun addFragment(fragment: Fragment, title: String) { - mFragmentList.add(fragment) - mFragmentTitleList.add(title) - } - - override fun getPageTitle(position: Int): CharSequence? { - - // return null to display only the icon (if there's icons) - return mFragmentTitleList[position] - } - } } \ No newline at end of file diff --git a/app/src/main/java/com/riders/thelab/ui/tabs/WorkingTabsAdapter.kt b/app/src/main/java/com/riders/thelab/ui/tabs/WorkingTabsAdapter.kt new file mode 100644 index 00000000..2ac6d7b4 --- /dev/null +++ b/app/src/main/java/com/riders/thelab/ui/tabs/WorkingTabsAdapter.kt @@ -0,0 +1,40 @@ +package com.riders.thelab.ui.tabs + +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentManager +import androidx.lifecycle.Lifecycle +import androidx.viewpager2.adapter.FragmentStateAdapter +import java.util.* + +class WorkingTabsAdapter(manager: FragmentManager, lifecycle: Lifecycle) : + FragmentStateAdapter(manager, lifecycle) { + + private val mFragmentList: MutableList = ArrayList() + private val mFragmentTitleList: MutableList = ArrayList() + + override fun createFragment(position: Int): Fragment { + // Return a NEW fragment instance in createFragment(int) + return WorkingFragment.newInstance(position + 1) + } + + override fun getItemId(position: Int): Long { + return position.toLong() + } + + override fun getItemCount(): Int = 3 + + fun getItem(position: Int): Fragment { + return mFragmentList[position] + } + + fun addFragment(fragment: Fragment, title: String) { + mFragmentList.add(fragment) + mFragmentTitleList.add(title) + } + + fun getPageTitle(position: Int): CharSequence { + + // return null to display only the icon (if there's icons) + return mFragmentTitleList[position] + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_tabs.xml b/app/src/main/res/layout/activity_tabs.xml index 2a3811b2..11c437a7 100644 --- a/app/src/main/res/layout/activity_tabs.xml +++ b/app/src/main/res/layout/activity_tabs.xml @@ -5,7 +5,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" - tools:context=".activities.WorkingTabsActivity"> + tools:context=".ui.tabs.WorkingTabsActivity"> - - - \ No newline at end of file diff --git a/build.gradle b/build.gradle index 4ca4939b..932842ba 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ ext { // version information versionMajor = 10 versionMinor = 8 - versionPatch = 5 + versionPatch = 6 versionName = "${versionMajor}.${versionMinor}.${versionPatch}" // Kotlin @@ -71,7 +71,7 @@ ext { firebaseBomVersion = '26.0.0' firebaseKtxVersion = '23.0.3' - adsVersion = '20.4.0' + adsVersion = '20.3.0' retrofit2Version = '2.9.0' okhttpBomVersion = '5.0.0-alpha.2' From 1f0c732fb8debcaeaea993d1b9301d6acfb01edd Mon Sep 17 00:00:00 2001 From: MichaelStH Date: Wed, 29 Sep 2021 23:02:40 +0200 Subject: [PATCH 08/11] [feat/041-spring-choice] : Remove unused imports --- app/src/main/AndroidManifest.xml | 22 +-- .../riders/thelab/core/location/GpsUtils.kt | 4 +- .../thelab/core/okhttp/LabInterceptors.kt | 1 - .../core/utils/LabCompatibilityManager.kt | 3 +- .../thelab/core/utils/LabDeviceManager.kt | 6 +- .../core/utils/LabNetworkManagerNewAPI.kt | 11 +- .../core/utils/RecyclerItemClickListener.kt | 4 +- .../com/riders/thelab/core/utils/UIManager.kt | 3 +- .../riders/thelab/data/local/model/Movie.kt | 2 +- .../thelab/data/local/model/RecyclerItem.kt | 2 +- .../riders/thelab/data/local/model/Video.kt | 2 +- .../riders/thelab/data/local/model/app/App.kt | 2 +- .../com/riders/thelab/data/remote/ApiImpl.kt | 4 + .../thelab/data/remote/dto/artist/Artist.kt | 2 +- .../thelab/ui/bluetooth/BluetoothActivity.kt | 2 - .../thelab/ui/bluetooth/BluetoothViewModel.kt | 40 +++-- .../ui/builtin/BuiltInBrowserActivity.kt | 2 +- .../thelab/ui/contacts/ContactsActivity.kt | 8 +- .../thelab/ui/contacts/ContactsAdapter.kt | 3 +- .../ui/googlesignin/GoogleSignInActivity.kt | 1 + .../ui/mainactivity/MainActivityAdapter.kt | 1 - .../fragment/home/HomeFragment.kt | 1 + .../fragment/home/HomeViewModel.kt | 2 +- .../fragment/time/TimeFragment.kt | 1 - .../fragment/weather/WeatherFragment.kt | 3 +- .../fragments/MultiPaneDetailFragment.kt | 1 - .../thelab/ui/recycler/RecyclerViewModel.kt | 7 +- .../ui/songplayer/SongPlayerActivity.kt | 169 +++--------------- .../thelab/ui/weather/WeatherActivity.kt | 2 +- .../youtubelike/YoutubeLikeDetailActivity.kt | 1 - .../ui/youtubelike/YoutubeLikeListAdapter.kt | 2 +- .../com/riders/thelab/utils/DateTimeUtils.kt | 29 --- .../main/res/drawable/ic_staggered_layout.xml | 13 +- app/src/main/res/layout/activity_main.xml | 2 +- app/src/main/res/layout/fragment_news.xml | 2 +- app/src/main/res/layout/fragment_one.xml | 2 + build.gradle | 2 +- 37 files changed, 115 insertions(+), 249 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 984b627a..931e46a3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -147,8 +147,8 @@ + android:exported="true" + android:theme="@style/Theme.TheLab.NoActionBar"> @@ -196,10 +196,10 @@ + android:theme="@style/Theme.TheLab.NoActionBar"> + android:theme="@style/Theme.TheLab"> + android:exported="true" + android:label="@string/app_name"> @@ -426,7 +426,8 @@ - @@ -456,7 +457,8 @@ android:enabled="true" android:exported="false" /> - diff --git a/app/src/main/java/com/riders/thelab/core/location/GpsUtils.kt b/app/src/main/java/com/riders/thelab/core/location/GpsUtils.kt index 1f8740a1..dace6e95 100644 --- a/app/src/main/java/com/riders/thelab/core/location/GpsUtils.kt +++ b/app/src/main/java/com/riders/thelab/core/location/GpsUtils.kt @@ -32,8 +32,8 @@ class GpsUtils(private val context: Context) { this.mSettingsClient = LocationServices.getSettingsClient(mContext!!) this.locationRequest = LocationRequest.create() locationRequest?.priority = LocationRequest.PRIORITY_HIGH_ACCURACY - locationRequest?.interval = 10 * 1000 - locationRequest?.fastestInterval = 2 * 1000 + locationRequest?.interval = (10 * 1000).toLong() + locationRequest?.fastestInterval = (2 * 1000).toLong() val builder: LocationSettingsRequest.Builder = LocationSettingsRequest.Builder() .addLocationRequest(locationRequest!!) diff --git a/app/src/main/java/com/riders/thelab/core/okhttp/LabInterceptors.kt b/app/src/main/java/com/riders/thelab/core/okhttp/LabInterceptors.kt index b8396dea..4f5edbe4 100644 --- a/app/src/main/java/com/riders/thelab/core/okhttp/LabInterceptors.kt +++ b/app/src/main/java/com/riders/thelab/core/okhttp/LabInterceptors.kt @@ -7,7 +7,6 @@ import okio.GzipSink import okio.buffer import timber.log.Timber import java.io.IOException -import java.util.* class LabInterceptors { diff --git a/app/src/main/java/com/riders/thelab/core/utils/LabCompatibilityManager.kt b/app/src/main/java/com/riders/thelab/core/utils/LabCompatibilityManager.kt index 597f332b..7993e06b 100644 --- a/app/src/main/java/com/riders/thelab/core/utils/LabCompatibilityManager.kt +++ b/app/src/main/java/com/riders/thelab/core/utils/LabCompatibilityManager.kt @@ -137,10 +137,9 @@ class LabCompatibilityManager private constructor() { } // TEST - fields = null + fields = VERSION_CODES::class.java.fields val builder = StringBuilder() builder.append("android : ").append(Build.VERSION.RELEASE) - fields = VERSION_CODES::class.java.fields for (field in fields) { val fieldName = field.name var fieldValue = -1 diff --git a/app/src/main/java/com/riders/thelab/core/utils/LabDeviceManager.kt b/app/src/main/java/com/riders/thelab/core/utils/LabDeviceManager.kt index 86a054c7..1f4e5f99 100644 --- a/app/src/main/java/com/riders/thelab/core/utils/LabDeviceManager.kt +++ b/app/src/main/java/com/riders/thelab/core/utils/LabDeviceManager.kt @@ -149,8 +149,7 @@ class LabDeviceManager private constructor() { @SuppressLint("NewApi") fun getScreenHeight(activity: Activity): Int { - var screenHeight = 0 - screenHeight = if (LabCompatibilityManager.isAndroid10() + val screenHeight: Int = if (LabCompatibilityManager.isAndroid10() && getModel().trim { it <= ' ' }.lowercase() .contains(Constants.EMULATOR_DEVICE_TAG) ) { @@ -165,8 +164,7 @@ class LabDeviceManager private constructor() { @SuppressLint("NewApi") fun getScreenWidth(activity: Activity): Int { - var screenWidth = 0 - screenWidth = if (LabCompatibilityManager.isAndroid10() + val screenWidth: Int = if (LabCompatibilityManager.isAndroid10() && getModel().trim { it <= ' ' }.lowercase() .contains(Constants.EMULATOR_DEVICE_TAG) ) { diff --git a/app/src/main/java/com/riders/thelab/core/utils/LabNetworkManagerNewAPI.kt b/app/src/main/java/com/riders/thelab/core/utils/LabNetworkManagerNewAPI.kt index 98c9742f..dd4b899e 100644 --- a/app/src/main/java/com/riders/thelab/core/utils/LabNetworkManagerNewAPI.kt +++ b/app/src/main/java/com/riders/thelab/core/utils/LabNetworkManagerNewAPI.kt @@ -20,9 +20,8 @@ class LabNetworkManagerNewAPI constructor( var isConnected = false } - init { - val mListener: ConnectivityListener = listener - } + val mListener: ConnectivityListener get() = listener + /** * Check the Internet connection @@ -38,7 +37,7 @@ class LabNetworkManagerNewAPI constructor( super.onAvailable(network) Timber.d("onAvailable()") isConnected = true - listener.onConnected() + mListener.onConnected() } override fun onBlockedStatusChanged(network: Network, blocked: Boolean) { @@ -55,7 +54,7 @@ class LabNetworkManagerNewAPI constructor( super.onLost(network) Timber.e("onLost()") isConnected = false - listener.onLostConnection() + mListener.onLostConnection() } override fun onUnavailable() { @@ -65,7 +64,7 @@ class LabNetworkManagerNewAPI constructor( } - @SuppressLint("WifiManagerPotentialLeak") + @SuppressLint("WifiManagerPotentialLeak", "InlinedApi") fun changeWifiState(applicationContext: Context, activity: Activity) { Timber.d("changeWifiState()") diff --git a/app/src/main/java/com/riders/thelab/core/utils/RecyclerItemClickListener.kt b/app/src/main/java/com/riders/thelab/core/utils/RecyclerItemClickListener.kt index 1e254663..e861809a 100644 --- a/app/src/main/java/com/riders/thelab/core/utils/RecyclerItemClickListener.kt +++ b/app/src/main/java/com/riders/thelab/core/utils/RecyclerItemClickListener.kt @@ -31,7 +31,7 @@ class RecyclerItemClickListener( override fun onLongPress(e: MotionEvent) { val child = recyclerView.findChildViewUnder(e.x, e.y) if (child != null && mListener != null) { - mListener!!.onLongClick(child, recyclerView.getChildPosition(child)) + mListener!!.onLongClick(child, recyclerView.getChildAdapterPosition(child)) } } }) @@ -40,7 +40,7 @@ class RecyclerItemClickListener( override fun onInterceptTouchEvent(view: RecyclerView, e: MotionEvent): Boolean { val childView = view.findChildViewUnder(e.x, e.y) if (childView != null && mListener != null && mGestureDetector!!.onTouchEvent(e)) { - mListener!!.onItemClick(childView, view.getChildPosition(childView)) + mListener!!.onItemClick(childView, view.getChildAdapterPosition(childView)) return true } return false diff --git a/app/src/main/java/com/riders/thelab/core/utils/UIManager.kt b/app/src/main/java/com/riders/thelab/core/utils/UIManager.kt index 70a6dba6..8c794a21 100644 --- a/app/src/main/java/com/riders/thelab/core/utils/UIManager.kt +++ b/app/src/main/java/com/riders/thelab/core/utils/UIManager.kt @@ -290,7 +290,8 @@ class UIManager private constructor() { targetImageView: ShapeableImageView, listener: RequestListener ) { - LabGlideUtils.getInstance().loadImage(context, iconResDrawable, targetImageView, listener) + LabGlideUtils.getInstance() + .loadImage(context, iconResDrawable, targetImageView, listener) } /** diff --git a/app/src/main/java/com/riders/thelab/data/local/model/Movie.kt b/app/src/main/java/com/riders/thelab/data/local/model/Movie.kt index cd7e096f..f3ce6737 100644 --- a/app/src/main/java/com/riders/thelab/data/local/model/Movie.kt +++ b/app/src/main/java/com/riders/thelab/data/local/model/Movie.kt @@ -3,7 +3,7 @@ package com.riders.thelab.data.local.model import android.os.Parcelable import com.riders.thelab.data.local.bean.MovieEnum import com.squareup.moshi.JsonClass -import kotlinx.android.parcel.Parcelize +import kotlinx.parcelize.Parcelize @Parcelize @JsonClass(generateAdapter = true) diff --git a/app/src/main/java/com/riders/thelab/data/local/model/RecyclerItem.kt b/app/src/main/java/com/riders/thelab/data/local/model/RecyclerItem.kt index 3edb6509..2854f134 100644 --- a/app/src/main/java/com/riders/thelab/data/local/model/RecyclerItem.kt +++ b/app/src/main/java/com/riders/thelab/data/local/model/RecyclerItem.kt @@ -2,7 +2,7 @@ package com.riders.thelab.data.local.model import android.os.Parcelable import com.riders.thelab.data.local.bean.RecyclerEnum -import kotlinx.android.parcel.Parcelize +import kotlinx.parcelize.Parcelize @Parcelize data class RecyclerItem constructor(var name: String? = null) : Parcelable { diff --git a/app/src/main/java/com/riders/thelab/data/local/model/Video.kt b/app/src/main/java/com/riders/thelab/data/local/model/Video.kt index 0cbef2c9..d35f301c 100644 --- a/app/src/main/java/com/riders/thelab/data/local/model/Video.kt +++ b/app/src/main/java/com/riders/thelab/data/local/model/Video.kt @@ -3,7 +3,7 @@ package com.riders.thelab.data.local.model import android.os.Parcelable import com.squareup.moshi.Json import com.squareup.moshi.JsonClass -import kotlinx.android.parcel.Parcelize +import kotlinx.parcelize.Parcelize @Parcelize @JsonClass(generateAdapter = true) diff --git a/app/src/main/java/com/riders/thelab/data/local/model/app/App.kt b/app/src/main/java/com/riders/thelab/data/local/model/app/App.kt index 96a21ec7..ec8dd1b0 100644 --- a/app/src/main/java/com/riders/thelab/data/local/model/app/App.kt +++ b/app/src/main/java/com/riders/thelab/data/local/model/app/App.kt @@ -51,7 +51,7 @@ data class App( // Custom write implementation parcel.writeLong(id) var bitmap: Bitmap? = null - + if (appDrawableIcon is BitmapDrawable) { bitmap = (appDrawableIcon as BitmapDrawable).bitmap as Bitmap } else if (appDrawableIcon is VectorDrawable) { diff --git a/app/src/main/java/com/riders/thelab/data/remote/ApiImpl.kt b/app/src/main/java/com/riders/thelab/data/remote/ApiImpl.kt index 27c6e4a1..fe0f495e 100644 --- a/app/src/main/java/com/riders/thelab/data/remote/ApiImpl.kt +++ b/app/src/main/java/com/riders/thelab/data/remote/ApiImpl.kt @@ -50,6 +50,10 @@ class ApiImpl @Inject constructor( val task = mAuth.signInAnonymously().await() + task.user?.let { + Timber.d("signInAnonymously:success : $it") + } + if (null != mAuth.currentUser) { // Sign in success, update UI with the signed-in user's information Timber.d("signInAnonymously:success") diff --git a/app/src/main/java/com/riders/thelab/data/remote/dto/artist/Artist.kt b/app/src/main/java/com/riders/thelab/data/remote/dto/artist/Artist.kt index 289efa02..1ef3f827 100644 --- a/app/src/main/java/com/riders/thelab/data/remote/dto/artist/Artist.kt +++ b/app/src/main/java/com/riders/thelab/data/remote/dto/artist/Artist.kt @@ -3,7 +3,7 @@ package com.riders.thelab.data.remote.dto.artist import android.os.Parcelable import com.squareup.moshi.Json import com.squareup.moshi.JsonClass -import kotlinx.android.parcel.Parcelize +import kotlinx.parcelize.Parcelize @Parcelize @JsonClass(generateAdapter = true) diff --git a/app/src/main/java/com/riders/thelab/ui/bluetooth/BluetoothActivity.kt b/app/src/main/java/com/riders/thelab/ui/bluetooth/BluetoothActivity.kt index 6271592c..7786c3b5 100644 --- a/app/src/main/java/com/riders/thelab/ui/bluetooth/BluetoothActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/bluetooth/BluetoothActivity.kt @@ -17,8 +17,6 @@ import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat import com.riders.thelab.R -import com.riders.thelab.core.utils.UIManager -import com.riders.thelab.data.local.bean.SnackBarType import com.riders.thelab.databinding.ActivityBluetoothBinding import timber.log.Timber diff --git a/app/src/main/java/com/riders/thelab/ui/bluetooth/BluetoothViewModel.kt b/app/src/main/java/com/riders/thelab/ui/bluetooth/BluetoothViewModel.kt index e8c1aa0c..b0490c6c 100644 --- a/app/src/main/java/com/riders/thelab/ui/bluetooth/BluetoothViewModel.kt +++ b/app/src/main/java/com/riders/thelab/ui/bluetooth/BluetoothViewModel.kt @@ -1,6 +1,7 @@ package com.riders.thelab.ui.bluetooth -import android.bluetooth.BluetoothAdapter +import android.bluetooth.BluetoothManager +import android.content.Context import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel @@ -15,33 +16,40 @@ class BluetoothViewModel : ViewModel() { return isBluetoothEnabled } - fun setBluetooth(enable: Boolean) { - val bluetoothAdapter = BluetoothAdapter.getDefaultAdapter() - val isEnabled = bluetoothAdapter.isEnabled + fun setBluetooth(context: Context, enable: Boolean) { + + /* Source : https://stackoverflow.com/questions/69122978/what-do-i-use-now-that-bluetoothadapter-getdefaultadapter-is-deprecated*/ + val bluetoothManager = + context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager + + val isEnabled = bluetoothManager.adapter.isEnabled if (enable && !isEnabled) { - isBluetoothEnabled.value = bluetoothAdapter.enable() + isBluetoothEnabled.value = bluetoothManager.adapter.enable() } else if (!enable && isEnabled) { - isBluetoothEnabled.value = bluetoothAdapter.disable() + isBluetoothEnabled.value = bluetoothManager.adapter.disable() } // No need to change bluetooth state // isBluetoothEnabled.value = true } - fun getBluetoothState(): Boolean { - val bluetoothAdapter: BluetoothAdapter = BluetoothAdapter.getDefaultAdapter() - return bluetoothAdapter.isEnabled + fun getBluetoothState(context: Context): Boolean { + val bluetoothManager = + context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager + return bluetoothManager.adapter.isEnabled } - fun startDiscovery() { - val bluetoothAdapter: BluetoothAdapter = BluetoothAdapter.getDefaultAdapter() + fun startDiscovery(context: Context) { + val bluetoothManager = + context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager - if (!bluetoothAdapter.isDiscovering) { - bluetoothAdapter.startDiscovery() + if (!bluetoothManager.adapter.isDiscovering) { + bluetoothManager.adapter.startDiscovery() } } - fun stopDiscovery() { - val bluetoothAdapter: BluetoothAdapter = BluetoothAdapter.getDefaultAdapter() - bluetoothAdapter.cancelDiscovery() + fun stopDiscovery(context: Context) { + val bluetoothManager = + context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager + bluetoothManager.adapter.cancelDiscovery() } } \ No newline at end of file diff --git a/app/src/main/java/com/riders/thelab/ui/builtin/BuiltInBrowserActivity.kt b/app/src/main/java/com/riders/thelab/ui/builtin/BuiltInBrowserActivity.kt index a93354b6..3e430164 100644 --- a/app/src/main/java/com/riders/thelab/ui/builtin/BuiltInBrowserActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/builtin/BuiltInBrowserActivity.kt @@ -81,7 +81,7 @@ class BuiltInBrowserActivity : AppCompatActivity() { viewBinding.contentBuiltInBrowser.browserWebView.clearHistory() viewBinding.contentBuiltInBrowser.browserWebView.settings.javaScriptEnabled = true viewBinding.contentBuiltInBrowser.browserWebView.isHorizontalScrollBarEnabled = false - viewBinding.contentBuiltInBrowser.browserWebView.setOnTouchListener { view: View?, event: MotionEvent -> + viewBinding.contentBuiltInBrowser.browserWebView.setOnTouchListener { _: View?, event: MotionEvent -> if (event.pointerCount > 1) { //Multi touch detected return@setOnTouchListener true diff --git a/app/src/main/java/com/riders/thelab/ui/contacts/ContactsActivity.kt b/app/src/main/java/com/riders/thelab/ui/contacts/ContactsActivity.kt index d080ec63..339a8bf3 100644 --- a/app/src/main/java/com/riders/thelab/ui/contacts/ContactsActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/contacts/ContactsActivity.kt @@ -182,14 +182,14 @@ class ContactsActivity if (viewHolder is ContactsViewHolder) { // get the removed item name to display it in snack bar - val name: String? = contactList?.get(viewHolder.getAdapterPosition())?.name + val name: String? = contactList?.get(viewHolder.absoluteAdapterPosition)?.name // backup of removed item for undo purpose - val deletedItem: Contact? = contactList?.get(viewHolder.getAdapterPosition()) - val deletedIndex = viewHolder.getAdapterPosition() + val deletedItem: Contact? = contactList?.get(viewHolder.absoluteAdapterPosition) + val deletedIndex = viewHolder.absoluteAdapterPosition // remove the item from recycler view - mAdapter!!.removeItem(viewHolder.getAdapterPosition()) + mAdapter!!.removeItem(viewHolder.absoluteAdapterPosition) // showing snack bar with Undo option UIManager.showActionInSnackBar( diff --git a/app/src/main/java/com/riders/thelab/ui/contacts/ContactsAdapter.kt b/app/src/main/java/com/riders/thelab/ui/contacts/ContactsAdapter.kt index c4e2ec60..b2a6c204 100644 --- a/app/src/main/java/com/riders/thelab/ui/contacts/ContactsAdapter.kt +++ b/app/src/main/java/com/riders/thelab/ui/contacts/ContactsAdapter.kt @@ -2,7 +2,6 @@ package com.riders.thelab.ui.contacts import android.content.Context import android.view.LayoutInflater -import android.view.View import android.view.ViewGroup import android.widget.Filter import android.widget.Filterable @@ -35,7 +34,7 @@ class ContactsAdapter( holder.viewBinding.cvContactItem.setOnClickListener { listener.onContactItemCLickListener( item, - holder.adapterPosition + holder.absoluteAdapterPosition ) } } diff --git a/app/src/main/java/com/riders/thelab/ui/googlesignin/GoogleSignInActivity.kt b/app/src/main/java/com/riders/thelab/ui/googlesignin/GoogleSignInActivity.kt index e41a0d8b..edad3791 100644 --- a/app/src/main/java/com/riders/thelab/ui/googlesignin/GoogleSignInActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/googlesignin/GoogleSignInActivity.kt @@ -85,6 +85,7 @@ class GoogleSignInActivity : AppCompatActivity(), View.OnClickListener { try { val account = completedTask.getResult(ApiException::class.java) val idToken = account.idToken + Timber.d("Token fetched : $idToken") // TODO(developer): send ID Token to server and validate updateUI(account) diff --git a/app/src/main/java/com/riders/thelab/ui/mainactivity/MainActivityAdapter.kt b/app/src/main/java/com/riders/thelab/ui/mainactivity/MainActivityAdapter.kt index d6fa7ba7..85f6d412 100644 --- a/app/src/main/java/com/riders/thelab/ui/mainactivity/MainActivityAdapter.kt +++ b/app/src/main/java/com/riders/thelab/ui/mainactivity/MainActivityAdapter.kt @@ -5,7 +5,6 @@ import android.content.Context import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.view.animation.AnimationUtils import android.widget.Filter import android.widget.Filterable import androidx.recyclerview.widget.RecyclerView diff --git a/app/src/main/java/com/riders/thelab/ui/mainactivity/fragment/home/HomeFragment.kt b/app/src/main/java/com/riders/thelab/ui/mainactivity/fragment/home/HomeFragment.kt index dbca9d79..0ce28475 100644 --- a/app/src/main/java/com/riders/thelab/ui/mainactivity/fragment/home/HomeFragment.kt +++ b/app/src/main/java/com/riders/thelab/ui/mainactivity/fragment/home/HomeFragment.kt @@ -21,6 +21,7 @@ import timber.log.Timber class HomeFragment : BaseFragment() { private var _viewBinding: FragmentHomeBinding? = null + // This property is only valid between onCreateView and // onDestroyView. private val binding get() = _viewBinding!! diff --git a/app/src/main/java/com/riders/thelab/ui/mainactivity/fragment/home/HomeViewModel.kt b/app/src/main/java/com/riders/thelab/ui/mainactivity/fragment/home/HomeViewModel.kt index 33212635..beb3368b 100644 --- a/app/src/main/java/com/riders/thelab/ui/mainactivity/fragment/home/HomeViewModel.kt +++ b/app/src/main/java/com/riders/thelab/ui/mainactivity/fragment/home/HomeViewModel.kt @@ -18,7 +18,7 @@ import java.util.* import javax.inject.Inject @HiltViewModel -class HomeViewModel @Inject constructor( +class HomeViewModel @Inject constructor( private val repository: IRepository ) : ViewModel() { diff --git a/app/src/main/java/com/riders/thelab/ui/mainactivity/fragment/time/TimeFragment.kt b/app/src/main/java/com/riders/thelab/ui/mainactivity/fragment/time/TimeFragment.kt index 07d2e9a3..7466fc4a 100644 --- a/app/src/main/java/com/riders/thelab/ui/mainactivity/fragment/time/TimeFragment.kt +++ b/app/src/main/java/com/riders/thelab/ui/mainactivity/fragment/time/TimeFragment.kt @@ -4,7 +4,6 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels import com.bumptech.glide.Glide import com.riders.thelab.core.utils.LabCompatibilityManager diff --git a/app/src/main/java/com/riders/thelab/ui/mainactivity/fragment/weather/WeatherFragment.kt b/app/src/main/java/com/riders/thelab/ui/mainactivity/fragment/weather/WeatherFragment.kt index d6f1fa61..71d2e5d4 100644 --- a/app/src/main/java/com/riders/thelab/ui/mainactivity/fragment/weather/WeatherFragment.kt +++ b/app/src/main/java/com/riders/thelab/ui/mainactivity/fragment/weather/WeatherFragment.kt @@ -6,7 +6,6 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels import com.riders.thelab.core.bus.LocationFetchedEvent import com.riders.thelab.core.utils.LabLocationManager @@ -36,7 +35,7 @@ class WeatherFragment : BaseFragment(), LocationListener { } } - private var _viewBinding: FragmentWeatherBinding? = null + private var _viewBinding: FragmentWeatherBinding? = null private val binding get() = _viewBinding!! diff --git a/app/src/main/java/com/riders/thelab/ui/multipane/fragments/MultiPaneDetailFragment.kt b/app/src/main/java/com/riders/thelab/ui/multipane/fragments/MultiPaneDetailFragment.kt index d915e239..433374ec 100644 --- a/app/src/main/java/com/riders/thelab/ui/multipane/fragments/MultiPaneDetailFragment.kt +++ b/app/src/main/java/com/riders/thelab/ui/multipane/fragments/MultiPaneDetailFragment.kt @@ -17,7 +17,6 @@ import com.riders.thelab.data.local.model.Movie import com.riders.thelab.databinding.FragmentMultiPaneDetailBinding import dagger.hilt.android.AndroidEntryPoint import timber.log.Timber -import java.util.* @AndroidEntryPoint class MultiPaneDetailFragment : Fragment() { diff --git a/app/src/main/java/com/riders/thelab/ui/recycler/RecyclerViewModel.kt b/app/src/main/java/com/riders/thelab/ui/recycler/RecyclerViewModel.kt index f436cebf..e35f752a 100644 --- a/app/src/main/java/com/riders/thelab/ui/recycler/RecyclerViewModel.kt +++ b/app/src/main/java/com/riders/thelab/ui/recycler/RecyclerViewModel.kt @@ -4,7 +4,6 @@ import android.annotation.SuppressLint import android.app.Activity import android.content.Intent import android.net.Uri -import android.view.View import androidx.core.app.ActivityOptionsCompat import androidx.core.view.ViewCompat import androidx.lifecycle.LiveData @@ -116,10 +115,10 @@ class RecyclerViewModel @Inject constructor( Timber.d("signInAnonymously:success") - storageReference?.let { + storageReference?.let { ref -> // Create a child reference // imagesRef now points to "images" - val imagesRef: StorageReference = it.child("images/artists") + val imagesRef: StorageReference = ref.child("images/artists") imagesRef .listAll() @@ -146,7 +145,7 @@ class RecyclerViewModel @Inject constructor( Timber.d("Links : %s", job.toString()) if (taskResult.result.items.size == job.size) { withContext(Dispatchers.Main) { - artistsThumbnails.value = job!! + job.also { artistsThumbnails.value = it } } } } diff --git a/app/src/main/java/com/riders/thelab/ui/songplayer/SongPlayerActivity.kt b/app/src/main/java/com/riders/thelab/ui/songplayer/SongPlayerActivity.kt index 05082a3e..8f9d80dc 100644 --- a/app/src/main/java/com/riders/thelab/ui/songplayer/SongPlayerActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/songplayer/SongPlayerActivity.kt @@ -11,8 +11,6 @@ import android.os.Bundle import android.os.Handler import android.os.IBinder import android.support.v4.media.session.MediaControllerCompat -import android.support.v4.media.session.MediaSessionCompat -import android.support.v4.media.session.PlaybackStateCompat import android.view.MenuItem import android.view.View import android.widget.SeekBar @@ -20,8 +18,6 @@ import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity import androidx.constraintlayout.motion.widget.MotionLayout import androidx.core.animation.addListener -import androidx.core.app.NotificationCompat -import androidx.core.app.NotificationManagerCompat import androidx.core.view.marginTop import androidx.interpolator.view.animation.LinearOutSlowInInterpolator import androidx.media.session.MediaButtonReceiver @@ -36,7 +32,6 @@ import com.riders.thelab.R import com.riders.thelab.core.service.MusicMediaPlaybackService import com.riders.thelab.core.utils.LabNotificationManager import com.riders.thelab.core.utils.SongsManager -import com.riders.thelab.core.utils.UIManager import com.riders.thelab.data.local.model.music.SongModel import com.riders.thelab.databinding.ActivitySongPlayerBinding import com.riders.thelab.utils.Constants @@ -57,6 +52,7 @@ class SongPlayerActivity : AppCompatActivity(), get() = Dispatchers.Main + Job() private var _viewBinding: ActivitySongPlayerBinding? = null + // This property is only valid between onCreateView and // onDestroyView. private val binding get() = _viewBinding!! @@ -67,11 +63,11 @@ class SongPlayerActivity : AppCompatActivity(), private lateinit var mp: MediaPlayer // Handler to update UI timer, progress bar etc,. - private var mHandler: Handler? = Handler() + private var mHandler: Handler? = null private var songManager: SongsManager? = null - private val seekForwardTime = 5000 // 5000 milliseconds + // private val seekForwardTime = 5000 // 5000 milliseconds - private val seekBackwardTime = 5000 // 5000 milliseconds + // private val seekBackwardTime = 5000 // 5000 milliseconds private var currentSongIndex = 0 private val isShuffle = false @@ -86,6 +82,29 @@ class SongPlayerActivity : AppCompatActivity(), private lateinit var mAdapter: SongPlayerAdapter + /** + * Background Runnable thread + */ + private val mUpdateTimeTask: Runnable = object : Runnable { + override fun run() { + val totalDuration = mp.duration.toLong() + val currentDuration = mp.currentPosition.toLong() + + // Displaying Total Duration time + //songTotalDurationLabel.setText("" + utils.milliSecondsToTimer(totalDuration)) + // Displaying time completed playing + //songCurrentDurationLabel.setText("" + utils.milliSecondsToTimer(currentDuration)) + + // Updating progress bar + val progress = SongPlayerUtils.getProgressPercentage(currentDuration, totalDuration) + //Log.d("Progress", ""+progress); + if (_viewBinding != null) binding.songProgressBar.progress = progress + + mHandler = Handler() + // Running this thread after 100 milliseconds + mHandler?.postDelayed(this, 100) + } + } private lateinit var controller: MediaControllerCompat private lateinit var mServiceMusic: MusicMediaPlaybackService @@ -418,117 +437,6 @@ class SongPlayerActivity : AppCompatActivity(), } - @SuppressLint("NewApi") - private fun displaySessionNotification(songModel: SongModel) { - Timber.d("displaySessionNotification()") - - // Given a media session and its context (usually the component containing the session) - val mediaSession: MediaSessionCompat = SongPlayerUtils.createMediaSession(this, mp) - - // Create a NotificationCompat.Builder - - // Get the session's metadata - // var mediaSession: MediaSessionCompat = MediaSessionCompat(this, TAG) - controller = SongPlayerUtils.createMediaController(mediaSession) - /*val controlsCallback: MediaControllerCompat.Callback = - object : MediaControllerCompat.Callback() { - override fun onPlaybackStateChanged(state: PlaybackStateCompat?) { - super.onPlaybackStateChanged(state) - - when (state?.state?.toLong()) { - PlaybackState.ACTION_PLAY -> { - Timber.d("controlsCallback - PlaybackState.ACTION_PLAY") - } - PlaybackState.ACTION_PAUSE -> { - Timber.e("controlsCallback - PlaybackState.ACTION_PAUSE") - } - } - } - }*/ - //controller.registerCallback(controlsCallback) - - val mediaMetadata = controller.metadata - val description = mediaMetadata?.description - - - val notification = - NotificationCompat.Builder(this, Constants.NOTIFICATION_MUSIC_CHANNEL_ID).apply { - - // Add the metadata for the currently playing track - setContentTitle(description?.title) - setContentText(description?.subtitle) - setSubText(description?.description) - setLargeIcon(description?.iconBitmap) - - // Enable launching the player by clicking the notification - setContentIntent(controller.sessionActivity) - - // Stop the service when the notification is swiped away - setDeleteIntent( - MediaButtonReceiver.buildMediaButtonPendingIntent( - this@SongPlayerActivity, - PlaybackStateCompat.ACTION_STOP - ) - ) - - // Show controls on lock screen even when user hides sensitive content. - setVisibility(NotificationCompat.VISIBILITY_PUBLIC) - - // Add an app icon and set its accent color - // Be careful about the color - setSmallIcon(R.drawable.ic_music) - - // Add a pause button - addAction( - NotificationCompat.Action( - R.drawable.ic_pause, - getString(R.string.action_pause), - MediaButtonReceiver.buildMediaButtonPendingIntent( - this@SongPlayerActivity, - PlaybackStateCompat.ACTION_PLAY_PAUSE - ) - ) - ) - - - // Add media control buttons that invoke intents in your media service - //.addAction(R.drawable.ic_previous, "Previous", prevPendingIntent) // #0 - //.addAction(R.drawable.ic_pause, "Pause", pausePendingIntent) // #1 - //.addAction(R.drawable.ic_next, "Next", nextPendingIntent) // #2 - // Apply the media style template - setStyle( - // Take advantage of MediaStyle features - androidx.media.app.NotificationCompat.MediaStyle() - .setShowActionsInCompactView(0 /* #1: pause button */) - .setMediaSession(mediaSession.sessionToken) - - // Add a cancel button - .setShowCancelButton(true) - .setCancelButtonIntent( - MediaButtonReceiver.buildMediaButtonPendingIntent( - this@SongPlayerActivity, - PlaybackStateCompat.ACTION_STOP - ) - ) - ) - setContentTitle(songModel.name) - setContentText(songModel.path) - setLargeIcon( - UIManager.getDrawable( - this@SongPlayerActivity, - R.drawable.logo_colors - )!! - ) - } - - with(NotificationManagerCompat.from(this)) { - // notificationId is a unique int for each notification that you must define - notify(Constants.NOTIFICATION_MUSIC_ID, notification.build()) - // Provide a unique integer for the "notificationId" of each notification. - mServiceMusic.startForeground(Constants.NOTIFICATION_MUSIC_ID, notification.build()) - } - } - /** * Update timer on seekbar */ @@ -536,28 +444,6 @@ class SongPlayerActivity : AppCompatActivity(), mHandler?.postDelayed(mUpdateTimeTask, 100) } - /** - * Background Runnable thread - */ - private val mUpdateTimeTask: Runnable = object : Runnable { - override fun run() { - val totalDuration = mp.duration.toLong() - val currentDuration = mp.currentPosition.toLong() - - // Displaying Total Duration time - //songTotalDurationLabel.setText("" + utils.milliSecondsToTimer(totalDuration)) - // Displaying time completed playing - //songCurrentDurationLabel.setText("" + utils.milliSecondsToTimer(currentDuration)) - - // Updating progress bar - val progress = SongPlayerUtils.getProgressPercentage(currentDuration, totalDuration) - //Log.d("Progress", ""+progress); - if (_viewBinding != null) binding.songProgressBar.progress = progress - - // Running this thread after 100 milliseconds - mHandler?.postDelayed(this, 100) - } - } override fun onSongClick(view: View, item: SongModel) { Timber.d("onFileClick() - $item") @@ -650,7 +536,6 @@ class SongPlayerActivity : AppCompatActivity(), } override fun onStopTrackingTouch(seekBar: SeekBar?) { - mHandler?.removeCallbacks(mUpdateTimeTask) val totalDuration = mp.duration val currentPosition: Int = diff --git a/app/src/main/java/com/riders/thelab/ui/weather/WeatherActivity.kt b/app/src/main/java/com/riders/thelab/ui/weather/WeatherActivity.kt index d497fe62..d4f94e4d 100644 --- a/app/src/main/java/com/riders/thelab/ui/weather/WeatherActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/weather/WeatherActivity.kt @@ -58,7 +58,7 @@ import kotlin.math.roundToInt class WeatherActivity : AppCompatActivity(), WeatherClickListener { private var _viewBinding: ActivityWeatherBinding? = null - + private val binding get() = _viewBinding!! private val mWeatherViewModel: WeatherViewModel by viewModels() diff --git a/app/src/main/java/com/riders/thelab/ui/youtubelike/YoutubeLikeDetailActivity.kt b/app/src/main/java/com/riders/thelab/ui/youtubelike/YoutubeLikeDetailActivity.kt index c2d37dcc..732c1253 100644 --- a/app/src/main/java/com/riders/thelab/ui/youtubelike/YoutubeLikeDetailActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/youtubelike/YoutubeLikeDetailActivity.kt @@ -19,7 +19,6 @@ import com.riders.thelab.data.local.model.Video import com.riders.thelab.databinding.ActivityYoutubeDetailBinding import jp.wasabeef.glide.transformations.BlurTransformation import timber.log.Timber -import java.util.* class YoutubeLikeDetailActivity : AppCompatActivity() { diff --git a/app/src/main/java/com/riders/thelab/ui/youtubelike/YoutubeLikeListAdapter.kt b/app/src/main/java/com/riders/thelab/ui/youtubelike/YoutubeLikeListAdapter.kt index 6c09816e..7cca6f84 100644 --- a/app/src/main/java/com/riders/thelab/ui/youtubelike/YoutubeLikeListAdapter.kt +++ b/app/src/main/java/com/riders/thelab/ui/youtubelike/YoutubeLikeListAdapter.kt @@ -48,7 +48,7 @@ class YoutubeLikeListAdapter( holder.getNameTextView(), holder.getDescriptionView(), itemYoutubeVideo, - holder.adapterPosition + holder.absoluteAdapterPosition ) } diff --git a/app/src/main/java/com/riders/thelab/utils/DateTimeUtils.kt b/app/src/main/java/com/riders/thelab/utils/DateTimeUtils.kt index 78d49e0d..7371b552 100644 --- a/app/src/main/java/com/riders/thelab/utils/DateTimeUtils.kt +++ b/app/src/main/java/com/riders/thelab/utils/DateTimeUtils.kt @@ -1,7 +1,6 @@ package com.riders.thelab.utils import android.annotation.SuppressLint -import timber.log.Timber import java.text.SimpleDateFormat import java.util.* @@ -45,33 +44,5 @@ class DateTimeUtils { return if (offset > 0) "$UTC+$offset" // Don't contains "+" sign else UTC + offset // Already contains "-" sign } - - private fun compareUTC(currentOffsetMillis: Long, targetOffsetMillis: Long) { - - - // Step 1 : get current UTC offset - val currentUTC = getOffsetTimeZone((TimeZone.getDefault().rawOffset / 1000).toLong()) - - // Step 2 : calculate mills target offset - val targetUTC = getOffsetTimeZone(targetOffsetMillis) - - // Step 3 : compare target offset with current offset, - // this will determine final sunrise/sunset times according to user's utc offset - if (targetUTC < currentUTC) { - Timber.d("target offset is lower than current, calculated final offset should be currentUTC - targetUTC") - } else if (targetUTC > currentUTC) { - Timber.d("target offset is greater than current, calculated final offset should be currentUTC + targetUTC") - } else if (targetUTC == currentUTC) { - Timber.d("target offset is equal to current, calculated final offset should be currentUTC = targetUTC") - } - - // if target offset is lower than user's utc offset -> target offset minus user's offset - // e.g. : - // - Los Angeles = UTC -8 (18h) --> UTC (0) = (3h) - // - Paris = UTC +1 (17h) --> UTC (0) = (16h) - // - // Calculate Los Angeles UTC(-8) with Paris base UTC (+1), - // result should be a 9 hours gap between these two - } } } \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_staggered_layout.xml b/app/src/main/res/drawable/ic_staggered_layout.xml index aee41f88..45f59424 100644 --- a/app/src/main/res/drawable/ic_staggered_layout.xml +++ b/app/src/main/res/drawable/ic_staggered_layout.xml @@ -1,5 +1,10 @@ - - + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index d5fd8eba..c7d0274d 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -12,8 +12,8 @@ diff --git a/app/src/main/res/layout/fragment_one.xml b/app/src/main/res/layout/fragment_one.xml index 2f496fb3..66cf6b20 100644 --- a/app/src/main/res/layout/fragment_one.xml +++ b/app/src/main/res/layout/fragment_one.xml @@ -7,10 +7,12 @@ tools:context=".ui.tabs.fragment.OneFragment"> diff --git a/build.gradle b/build.gradle index 932842ba..3eb01e18 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ ext { // version information versionMajor = 10 versionMinor = 8 - versionPatch = 6 + versionPatch = 7 versionName = "${versionMajor}.${versionMinor}.${versionPatch}" // Kotlin From eaa9fcf2ba0960b1aad492c3f0617229ea59db77 Mon Sep 17 00:00:00 2001 From: MichaelStH Date: Wed, 29 Sep 2021 23:23:39 +0200 Subject: [PATCH 09/11] [feat/041-spring-choice] : Fix build gradle warnings wip --- app/build.gradle | 6 ------ .../riders/thelab/ui/bluetooth/BluetoothActivity.kt | 12 +++++++----- .../thelab/ui/contacts/RecyclerItemTouchHelper.kt | 2 +- .../thelab/ui/googledrive/GoogleDriveActivity.kt | 3 +-- .../thelab/ui/recycler/RecyclerViewActivity.kt | 2 +- .../riders/thelab/ui/recycler/RecyclerViewModel.kt | 3 +-- gradle/wrapper/gradle-wrapper.properties | 4 ++-- 7 files changed, 13 insertions(+), 19 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index fca43e09..721375e8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -35,12 +35,6 @@ android { versionCode buildDateTime versionName rootProject.ext.versionName - javaCompileOptions { - annotationProcessorOptions { - includeCompileClasspath false - } - } - // Enabling multidex support. multiDexEnabled true diff --git a/app/src/main/java/com/riders/thelab/ui/bluetooth/BluetoothActivity.kt b/app/src/main/java/com/riders/thelab/ui/bluetooth/BluetoothActivity.kt index 7786c3b5..743b1650 100644 --- a/app/src/main/java/com/riders/thelab/ui/bluetooth/BluetoothActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/bluetooth/BluetoothActivity.kt @@ -199,7 +199,7 @@ class BluetoothActivity : AppCompatActivity(), override fun onStop() { super.onStop() - mViewModel.stopDiscovery() + mViewModel.stopDiscovery(this@BluetoothActivity) } override fun onDestroy() { @@ -234,12 +234,14 @@ class BluetoothActivity : AppCompatActivity(), private fun initSwitch() { binding.switchBluetooth.text = - if (!mViewModel.getBluetoothState()) getString(R.string.bluetooth_off) else getString(R.string.bluetooth_on) - binding.switchBluetooth.isChecked = mViewModel.getBluetoothState() + if (!mViewModel.getBluetoothState(this@BluetoothActivity)) getString(R.string.bluetooth_off) else getString( + R.string.bluetooth_on + ) + binding.switchBluetooth.isChecked = mViewModel.getBluetoothState(this@BluetoothActivity) } private fun initButton() { - val isBluetoothEnabled = mViewModel.getBluetoothState() + val isBluetoothEnabled = mViewModel.getBluetoothState(this@BluetoothActivity) changeButton( if (!isBluetoothEnabled) getString(R.string.bluetooth_unable_to_discover) else getString( R.string.bluetooth_start_discovery @@ -272,7 +274,7 @@ class BluetoothActivity : AppCompatActivity(), override fun onCheckedChanged(buttonView: CompoundButton?, isChecked: Boolean) { if (binding.switchBluetooth.isShown) { - mViewModel.setBluetooth(isChecked) + mViewModel.setBluetooth(this@BluetoothActivity, isChecked) } } diff --git a/app/src/main/java/com/riders/thelab/ui/contacts/RecyclerItemTouchHelper.kt b/app/src/main/java/com/riders/thelab/ui/contacts/RecyclerItemTouchHelper.kt index ac8be09f..ba49a99a 100644 --- a/app/src/main/java/com/riders/thelab/ui/contacts/RecyclerItemTouchHelper.kt +++ b/app/src/main/java/com/riders/thelab/ui/contacts/RecyclerItemTouchHelper.kt @@ -72,7 +72,7 @@ class RecyclerItemTouchHelper constructor( } override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { - listener!!.onSwiped(viewHolder, direction, viewHolder.adapterPosition) + listener!!.onSwiped(viewHolder, direction, viewHolder.absoluteAdapterPosition) } override fun convertToAbsoluteDirection(flags: Int, layoutDirection: Int): Int { diff --git a/app/src/main/java/com/riders/thelab/ui/googledrive/GoogleDriveActivity.kt b/app/src/main/java/com/riders/thelab/ui/googledrive/GoogleDriveActivity.kt index c253fc2f..3e726ba5 100644 --- a/app/src/main/java/com/riders/thelab/ui/googledrive/GoogleDriveActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/googledrive/GoogleDriveActivity.kt @@ -14,7 +14,6 @@ import com.google.android.gms.common.GoogleApiAvailability import com.google.android.gms.common.api.GoogleApiClient import com.google.android.gms.common.api.Scope import com.google.android.gms.common.api.internal.OnConnectionFailedListener -import com.google.api.client.extensions.android.http.AndroidHttp import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow @@ -242,7 +241,7 @@ class GoogleDriveActivity // and GoogleAccountCredential as parameters return Drive .Builder( - AndroidHttp.newCompatibleTransport(), + NetHttpTransport.Builder().build(), JacksonFactory.getDefaultInstance(), credential ) diff --git a/app/src/main/java/com/riders/thelab/ui/recycler/RecyclerViewActivity.kt b/app/src/main/java/com/riders/thelab/ui/recycler/RecyclerViewActivity.kt index addbe125..91205082 100644 --- a/app/src/main/java/com/riders/thelab/ui/recycler/RecyclerViewActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/recycler/RecyclerViewActivity.kt @@ -111,7 +111,7 @@ class RecyclerViewActivity : AppCompatActivity(), RecyclerClickListener { } override fun onDetailClick(artist: Artist, sharedImageView: ShapeableImageView, position: Int) { - mRecyclerViewModel.onDetailClick(this, artist, sharedImageView, position) + mRecyclerViewModel.onDetailClick(this, artist, sharedImageView) } override fun onDeleteClick(artist: Artist, position: Int) { diff --git a/app/src/main/java/com/riders/thelab/ui/recycler/RecyclerViewModel.kt b/app/src/main/java/com/riders/thelab/ui/recycler/RecyclerViewModel.kt index e35f752a..07b74e1f 100644 --- a/app/src/main/java/com/riders/thelab/ui/recycler/RecyclerViewModel.kt +++ b/app/src/main/java/com/riders/thelab/ui/recycler/RecyclerViewModel.kt @@ -227,8 +227,7 @@ class RecyclerViewModel @Inject constructor( fun onDetailClick( activity: Activity, item: Artist, - sharedImageView: ShapeableImageView, - position: Int + sharedImageView: ShapeableImageView ) { Timber.d("onDetailClick(item, sharedImageView, position)") diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 04785905..79a7ea8c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Sep 29 20:33:16 CEST 2021 +#Wed Sep 29 23:15:33 CEST 2021 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME From 5573c6c70fd82c3138aa5cc2f890df70612e8e78 Mon Sep 17 00:00:00 2001 From: MichaelStH Date: Tue, 5 Oct 2021 17:08:12 +0200 Subject: [PATCH 10/11] [feat/041-spring-choice] : Fix build gradle warnings --- .../core/livedata/ConnectionLiveData.kt | 4 ++ .../thelab/core/okhttp/LabInterceptors.kt | 1 + .../core/service/MusicMediaPlaybackService.kt | 2 +- .../thelab/core/service/TheLabBootService.kt | 1 + .../thelab/core/storage/ExternalStorage.kt | 2 + .../riders/thelab/core/storage/FileManager.kt | 19 +++--- .../core/utils/LabCompatibilityManager.kt | 3 +- .../thelab/core/utils/LabDeviceManager.kt | 3 +- .../core/utils/LabNetworkManagerNewAPI.kt | 1 + .../thelab/core/views/toast/TheLabToast.kt | 67 +++++++++---------- .../riders/thelab/data/local/model/app/App.kt | 5 +- .../riders/thelab/ui/base/SimpleActivity.kt | 2 +- .../thelab/ui/bluetooth/BluetoothActivity.kt | 59 ++++++++-------- .../thelab/ui/bluetooth/BluetoothViewModel.kt | 48 ++++++++----- .../deviceinformation/DeviceInfoViewModel.kt | 2 + .../thelab/ui/download/DownloadActivity.kt | 3 +- .../ui/floatingview/FloatingViewActivity.kt | 5 +- .../ui/googledrive/GoogleDriveActivity.kt | 6 +- .../ui/googlesignin/GoogleSignInActivity.kt | 2 + .../locationonmaps/LocationOnMapsActivity.kt | 2 + .../thelab/ui/mainactivity/MainActivity.kt | 6 +- .../ui/mainactivity/MainActivityAdapter.kt | 2 +- .../fragment/news/NewsFragment.kt | 8 ++- .../thelab/ui/schedule/ScheduleActivity.kt | 25 ++++--- .../ui/songplayer/SongPlayerActivity.kt | 3 +- .../thelab/ui/songplayer/SongPlayerAdapter.kt | 2 +- .../thelab/ui/songplayer/SongPlayerUtils.kt | 2 + .../ui/splashscreen/SplashScreenActivity.kt | 15 +++-- .../main/res/layout/activity_song_player.xml | 1 - .../main/res/layout/custom_toast_layout.xml | 1 + app/src/main/res/xml/song_player_scene.xml | 1 - 31 files changed, 177 insertions(+), 126 deletions(-) diff --git a/app/src/main/java/com/riders/thelab/core/livedata/ConnectionLiveData.kt b/app/src/main/java/com/riders/thelab/core/livedata/ConnectionLiveData.kt index 4e40cc04..3e1bcd83 100644 --- a/app/src/main/java/com/riders/thelab/core/livedata/ConnectionLiveData.kt +++ b/app/src/main/java/com/riders/thelab/core/livedata/ConnectionLiveData.kt @@ -16,6 +16,7 @@ class ConnectionLiveData( override fun onActive() { super.onActive() + @Suppress("DEPRECATION") val filter = IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION) context.registerReceiver(networkReceiver, filter) } @@ -28,12 +29,15 @@ class ConnectionLiveData( private val networkReceiver: BroadcastReceiver = object : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent) { if (intent.extras != null) { + @Suppress("DEPRECATION") val activeNetwork = intent.extras!![ConnectivityManager.EXTRA_NETWORK_INFO] as NetworkInfo? + @Suppress("DEPRECATION") val isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting if (isConnected) { + @Suppress("DEPRECATION") when (activeNetwork!!.type) { ConnectivityManager.TYPE_WIFI -> value = ConnectionModel(ConnectivityManager.TYPE_WIFI, true) diff --git a/app/src/main/java/com/riders/thelab/core/okhttp/LabInterceptors.kt b/app/src/main/java/com/riders/thelab/core/okhttp/LabInterceptors.kt index 4f5edbe4..f2775ae8 100644 --- a/app/src/main/java/com/riders/thelab/core/okhttp/LabInterceptors.kt +++ b/app/src/main/java/com/riders/thelab/core/okhttp/LabInterceptors.kt @@ -40,6 +40,7 @@ class LabInterceptors { Timber.d("Received response : %s", jsonResponse) // Re-create the response before returning it because body can be read only once + @Suppress("DEPRECATION") return response .newBuilder() .body( diff --git a/app/src/main/java/com/riders/thelab/core/service/MusicMediaPlaybackService.kt b/app/src/main/java/com/riders/thelab/core/service/MusicMediaPlaybackService.kt index 1a794d8d..e2073706 100644 --- a/app/src/main/java/com/riders/thelab/core/service/MusicMediaPlaybackService.kt +++ b/app/src/main/java/com/riders/thelab/core/service/MusicMediaPlaybackService.kt @@ -13,7 +13,7 @@ class MusicMediaPlaybackService : Service() { //binder given to client private val mBinder: IBinder = LocalBinder() - private lateinit var mMediaSessionCompat: MediaSessionCompat + private var mMediaSessionCompat: MediaSessionCompat? = null override fun onBind(intent: Intent?): IBinder { Timber.d("onBind()") diff --git a/app/src/main/java/com/riders/thelab/core/service/TheLabBootService.kt b/app/src/main/java/com/riders/thelab/core/service/TheLabBootService.kt index 7f630ec8..7d1a4357 100644 --- a/app/src/main/java/com/riders/thelab/core/service/TheLabBootService.kt +++ b/app/src/main/java/com/riders/thelab/core/service/TheLabBootService.kt @@ -79,6 +79,7 @@ class TheLabBootService : Service() { ) val mBuilder: NotificationCompat.Builder = + @Suppress("DEPRECATION") NotificationCompat.Builder(this).apply { setSmallIcon(R.mipmap.ic_lab_six_round) setContentTitle(getString(R.string.notification_title)) diff --git a/app/src/main/java/com/riders/thelab/core/storage/ExternalStorage.kt b/app/src/main/java/com/riders/thelab/core/storage/ExternalStorage.kt index fe74aad1..bbd5849e 100644 --- a/app/src/main/java/com/riders/thelab/core/storage/ExternalStorage.kt +++ b/app/src/main/java/com/riders/thelab/core/storage/ExternalStorage.kt @@ -25,6 +25,7 @@ class ExternalStorage { return false } + @Suppress("DEPRECATION") fun getSdCardPath(): String { return Environment.getExternalStorageDirectory().path + "/" } @@ -134,6 +135,7 @@ class ExternalStorage { mMounts.clear() if (map.isEmpty()) { + @Suppress("DEPRECATION") map[SD_CARD] = Environment.getExternalStorageDirectory() } return map; diff --git a/app/src/main/java/com/riders/thelab/core/storage/FileManager.kt b/app/src/main/java/com/riders/thelab/core/storage/FileManager.kt index b397f8e6..56a65eef 100644 --- a/app/src/main/java/com/riders/thelab/core/storage/FileManager.kt +++ b/app/src/main/java/com/riders/thelab/core/storage/FileManager.kt @@ -103,25 +103,22 @@ class FileManager private constructor() { } } - fun getMetaDataImage() { + /*fun getMetaDataImage() { val mmr = MediaMetadataRetriever() - // mmr.setDataSource(songsList.get(songIndex).get("songPath")) - - val data = mmr.embeddedPicture - //coverart is an Imageview object + mmr.setDataSource(songsList.get(songIndex).get("songPath")) // convert the byte array to a bitmap - //coverart is an Imageview object + val data = mmr.embeddedPicture // convert the byte array to a bitmap if (data != null) { val bitmap = BitmapFactory.decodeByteArray(data, 0, data.size) - //coverart.setImageBitmap(bitmap) //associated cover art in bitmap + coverart.setImageBitmap(bitmap) //associated cover art in bitmap } else { - //coverart.setImageResource(R.drawable.fallback_cover) //any default cover resourse folder + coverart.setImageResource(R.drawable.fallback_cover) //any default cover resourse folder } - //coverart.setAdjustViewBounds(true) - //coverart.setLayoutParams(LinearLayout.LayoutParams(500, 500)) - } + coverart.setAdjustViewBounds(true) + coverart.setLayoutParams(LinearLayout.LayoutParams(500, 500)) + }*/ } \ No newline at end of file diff --git a/app/src/main/java/com/riders/thelab/core/utils/LabCompatibilityManager.kt b/app/src/main/java/com/riders/thelab/core/utils/LabCompatibilityManager.kt index 7993e06b..9f8f01be 100644 --- a/app/src/main/java/com/riders/thelab/core/utils/LabCompatibilityManager.kt +++ b/app/src/main/java/com/riders/thelab/core/utils/LabCompatibilityManager.kt @@ -140,6 +140,7 @@ class LabCompatibilityManager private constructor() { fields = VERSION_CODES::class.java.fields val builder = StringBuilder() builder.append("android : ").append(Build.VERSION.RELEASE) + for (field in fields) { val fieldName = field.name var fieldValue = -1 @@ -158,7 +159,7 @@ class LabCompatibilityManager private constructor() { .append("sdk=").append(fieldValue) } } - fields = null + Timber.e("OS: %s", builder.toString()) // TEST return OSName diff --git a/app/src/main/java/com/riders/thelab/core/utils/LabDeviceManager.kt b/app/src/main/java/com/riders/thelab/core/utils/LabDeviceManager.kt index 1f4e5f99..e2d26e2c 100644 --- a/app/src/main/java/com/riders/thelab/core/utils/LabDeviceManager.kt +++ b/app/src/main/java/com/riders/thelab/core/utils/LabDeviceManager.kt @@ -184,9 +184,10 @@ class LabDeviceManager private constructor() { * @param activity * @return */ - fun getDisplayMetrics(activity: Activity): DisplayMetrics { + private fun getDisplayMetrics(activity: Activity): DisplayMetrics { //Retrieve Screen's height and width val metrics = DisplayMetrics() + @Suppress("DEPRECATION") activity .windowManager .defaultDisplay diff --git a/app/src/main/java/com/riders/thelab/core/utils/LabNetworkManagerNewAPI.kt b/app/src/main/java/com/riders/thelab/core/utils/LabNetworkManagerNewAPI.kt index dd4b899e..456ff808 100644 --- a/app/src/main/java/com/riders/thelab/core/utils/LabNetworkManagerNewAPI.kt +++ b/app/src/main/java/com/riders/thelab/core/utils/LabNetworkManagerNewAPI.kt @@ -73,6 +73,7 @@ class LabNetworkManagerNewAPI constructor( applicationContext.getSystemService(AppCompatActivity.WIFI_SERVICE) as WifiManager if (!LabCompatibilityManager.isAndroid10()) { val isWifi = wifiManager.isWifiEnabled + @Suppress("DEPRECATION") wifiManager.isWifiEnabled = !isWifi } else { Timber.e("For applications targeting android.os.Build.VERSION_CODES Q or above, this API will always fail and return false") diff --git a/app/src/main/java/com/riders/thelab/core/views/toast/TheLabToast.kt b/app/src/main/java/com/riders/thelab/core/views/toast/TheLabToast.kt index dcecca46..bef10ae2 100644 --- a/app/src/main/java/com/riders/thelab/core/views/toast/TheLabToast.kt +++ b/app/src/main/java/com/riders/thelab/core/views/toast/TheLabToast.kt @@ -4,18 +4,13 @@ import android.app.Activity import android.content.Context import android.graphics.PorterDuff import android.view.Gravity -import android.view.View -import android.view.ViewGroup import android.view.animation.Animation import android.view.animation.AnimationSet import android.view.animation.TranslateAnimation -import android.widget.LinearLayout import android.widget.Toast import androidx.core.content.ContextCompat import androidx.interpolator.view.animation.LinearOutSlowInInterpolator -import com.google.android.material.imageview.ShapeableImageView -import com.google.android.material.textview.MaterialTextView -import com.riders.thelab.R +import com.riders.thelab.databinding.CustomToastLayoutBinding import timber.log.Timber /** @@ -24,12 +19,33 @@ import timber.log.Timber class TheLabToast( private val context: Context ) : Toast(context) { + private var _viewBinding: CustomToastLayoutBinding? = null + private val binding get() = _viewBinding!! + + + /** + * Construct an empty Toast object. You must call [.setView] before you + * can call [.show]. + * + * @param context The context to use. Usually your [Application] + * or [Activity] object. + */ + init { + + run { + _viewBinding = CustomToastLayoutBinding.inflate((context as Activity).layoutInflater) + + // Ref : https://developer.android.com/reference/android/widget/Toast#setGravity(int,%20int,%20int) + setGravity(Gravity.BOTTOM, 0, 250) + this.duration = LENGTH_LONG + + @Suppress("DEPRECATION") + this.view = binding.root + } + } - private val container: LinearLayout - private val imageView: ShapeableImageView - private val textView: MaterialTextView override fun setText(s: CharSequence) { - textView.text = s + binding.text.text = s } fun setType(toastTypeEnum: ToastTypeEnum?) { @@ -39,7 +55,7 @@ class TheLabToast( } fun setImageResource(drawableResourceID: Int) { - imageView.setImageDrawable(ContextCompat.getDrawable(context, drawableResourceID)) + binding.ivLol.setImageDrawable(ContextCompat.getDrawable(context, drawableResourceID)) } /** @@ -48,7 +64,7 @@ class TheLabToast( * @param color */ fun setBackgroundColor(color: Int) { - container + binding.customToastContainer .background .setColorFilter( ContextCompat.getColor(context, color), @@ -59,7 +75,7 @@ class TheLabToast( override fun show() { Timber.d("show()") val translateAnimation = TranslateAnimation( - 0f, 0f, 180f, container.top + 0f, 0f, 180f, binding.customToastContainer.top .toFloat() ) @@ -78,13 +94,14 @@ class TheLabToast( }) val animationSet = AnimationSet(true) animationSet.addAnimation(translateAnimation) - container.startAnimation(animationSet) + binding.customToastContainer.startAnimation(animationSet) super.show() } override fun cancel() { Timber.e("cancel()") super.cancel() + _viewBinding = null } class Builder(var context: Context) { @@ -108,26 +125,4 @@ class TheLabToast( } } - /** - * Construct an empty Toast object. You must call [.setView] before you - * can call [.show]. - * - * @param context The context to use. Usually your [Application] - * or [Activity] object. - */ - init { - val inflater = (context as Activity).layoutInflater - val layout = inflater.inflate( - R.layout.custom_toast_layout, - context.findViewById(R.id.custom_toast_container) as ViewGroup - ) - container = layout.findViewById(R.id.custom_toast_container) as LinearLayout - imageView = layout.findViewById(R.id.ivLol) - textView = layout.findViewById(R.id.text) - - // Ref : https://developer.android.com/reference/android/widget/Toast#setGravity(int,%20int,%20int) - setGravity(Gravity.BOTTOM, 0, 250) - this.duration = LENGTH_LONG - this.view = layout - } } \ No newline at end of file diff --git a/app/src/main/java/com/riders/thelab/data/local/model/app/App.kt b/app/src/main/java/com/riders/thelab/data/local/model/app/App.kt index ec8dd1b0..46e30b9e 100644 --- a/app/src/main/java/com/riders/thelab/data/local/model/app/App.kt +++ b/app/src/main/java/com/riders/thelab/data/local/model/app/App.kt @@ -31,12 +31,13 @@ data class App( var drawable: BitmapDrawable? val bitmap = parcel.readValue(Bitmap::class.java.classLoader)!! as Bitmap - if (bitmap != null) { + if (null != bitmap) { drawable = BitmapDrawable(TheLabApplication.getInstance().getContext().resources, bitmap) } else { drawable = null } + // Custom read implementation return App( parcel.readLong(), @@ -59,7 +60,7 @@ data class App( } parcel.writeParcelable(bitmap, flags) - appName.let { parcel.writeString(appName) } + appName.let { parcel.writeString(it) } parcel.writeString(appVersion) parcel.writeString(appPackageName) parcel.writeString(appTitle) diff --git a/app/src/main/java/com/riders/thelab/ui/base/SimpleActivity.kt b/app/src/main/java/com/riders/thelab/ui/base/SimpleActivity.kt index 1b83eb97..ff02a5f3 100644 --- a/app/src/main/java/com/riders/thelab/ui/base/SimpleActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/base/SimpleActivity.kt @@ -21,6 +21,6 @@ class SimpleActivity : AppCompatActivity() { ab.title = title if (subTitle != null) ab.subtitle = subTitle } - toolbar.setNavigationOnClickListener { view: View? -> onBackPressed() } + toolbar.setNavigationOnClickListener { onBackPressed() } } } \ No newline at end of file diff --git a/app/src/main/java/com/riders/thelab/ui/bluetooth/BluetoothActivity.kt b/app/src/main/java/com/riders/thelab/ui/bluetooth/BluetoothActivity.kt index 743b1650..b41738eb 100644 --- a/app/src/main/java/com/riders/thelab/ui/bluetooth/BluetoothActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/bluetooth/BluetoothActivity.kt @@ -2,6 +2,7 @@ package com.riders.thelab.ui.bluetooth import android.bluetooth.BluetoothAdapter import android.bluetooth.BluetoothDevice +import android.bluetooth.BluetoothManager import android.content.BroadcastReceiver import android.content.Context import android.content.Intent @@ -31,6 +32,7 @@ class BluetoothActivity : AppCompatActivity(), private val mViewModel: BluetoothViewModel by viewModels() + private lateinit var bluetoothManager: BluetoothManager private lateinit var bluetoothDevicesSearchList: ArrayList @@ -143,32 +145,19 @@ class BluetoothActivity : AppCompatActivity(), _viewBinding = ActivityBluetoothBinding.inflate(layoutInflater) setContentView(binding.root) + /* Source : https://stackoverflow.com/questions/69122978/what-do-i-use-now-that-bluetoothadapter-getdefaultadapter-is-deprecated*/ + bluetoothManager = getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager + bluetoothDevicesSearchList = mutableListOf() as ArrayList - binding.switchBluetooth.setOnCheckedChangeListener(this) - binding.btnDiscovery.setOnClickListener(this) + setListeners() initViewModelsObservers() initSwitch() initButton() - val pairedDevices = BluetoothAdapter.getDefaultAdapter().bondedDevices - if (pairedDevices.size > 0) { - - val boundedDevices: ArrayList = mutableListOf() as ArrayList - - for (d in pairedDevices) { - val deviceName = d.name - val macAddress = d.address - Timber.i("paired device: $deviceName at $macAddress") - // do what you need/want this these list items - - boundedDevices.add(deviceName) - } - - bindListView(binding.lvBoundedDevices, boundedDevices) - } + mViewModel.fetchBoundedDevices(bluetoothManager) } override fun onResume() { @@ -199,7 +188,7 @@ class BluetoothActivity : AppCompatActivity(), override fun onStop() { super.onStop() - mViewModel.stopDiscovery(this@BluetoothActivity) + mViewModel.stopDiscovery(bluetoothManager) } override fun onDestroy() { @@ -211,6 +200,11 @@ class BluetoothActivity : AppCompatActivity(), unregisterReceiver(receiver) } + private fun setListeners() { + binding.switchBluetooth.setOnCheckedChangeListener(this) + binding.btnDiscovery.setOnClickListener(this) + } + private fun initViewModelsObservers() { mViewModel.getBluetoothEnabled().observe(this, { Timber.d("getBluetoothEnabled().observe : $it") @@ -230,18 +224,27 @@ class BluetoothActivity : AppCompatActivity(), it ) }) + + mViewModel.getBoundedDevices().observe(this, { + if (it.isEmpty()) { + Timber.e("Bluetooth bounded devices size = 0") + + } else { + bindListView(binding.lvBoundedDevices, it) + } + }) } private fun initSwitch() { binding.switchBluetooth.text = - if (!mViewModel.getBluetoothState(this@BluetoothActivity)) getString(R.string.bluetooth_off) else getString( + if (!mViewModel.getBluetoothState(bluetoothManager)) getString(R.string.bluetooth_off) else getString( R.string.bluetooth_on ) - binding.switchBluetooth.isChecked = mViewModel.getBluetoothState(this@BluetoothActivity) + binding.switchBluetooth.isChecked = mViewModel.getBluetoothState(bluetoothManager) } private fun initButton() { - val isBluetoothEnabled = mViewModel.getBluetoothState(this@BluetoothActivity) + val isBluetoothEnabled = mViewModel.getBluetoothState(bluetoothManager) changeButton( if (!isBluetoothEnabled) getString(R.string.bluetooth_unable_to_discover) else getString( R.string.bluetooth_start_discovery @@ -274,7 +277,7 @@ class BluetoothActivity : AppCompatActivity(), override fun onCheckedChanged(buttonView: CompoundButton?, isChecked: Boolean) { if (binding.switchBluetooth.isShown) { - mViewModel.setBluetooth(this@BluetoothActivity, isChecked) + mViewModel.setBluetooth(bluetoothManager, isChecked) } } @@ -282,14 +285,12 @@ class BluetoothActivity : AppCompatActivity(), when (view?.id) { R.id.btn_discovery -> { - val bluetoothAdapter: BluetoothAdapter = BluetoothAdapter.getDefaultAdapter() - - if (!bluetoothAdapter.isEnabled) { + if (!bluetoothManager.adapter.isEnabled) { Timber.e("Bluetooth not enable cannot start discovery") } else { - if (!bluetoothAdapter.isDiscovering) { - bluetoothAdapter.startDiscovery() + if (!bluetoothManager.adapter.isDiscovering) { + bluetoothManager.adapter.startDiscovery() changeButton( getString(R.string.bluetooth_cancel_discovery), ContextCompat.getDrawable( @@ -300,7 +301,7 @@ class BluetoothActivity : AppCompatActivity(), ) binding.progressSearchedDevices.visibility = View.VISIBLE } else { - bluetoothAdapter.cancelDiscovery() + bluetoothManager.adapter.cancelDiscovery() changeButton( getString(R.string.bluetooth_start_discovery), ContextCompat.getDrawable( diff --git a/app/src/main/java/com/riders/thelab/ui/bluetooth/BluetoothViewModel.kt b/app/src/main/java/com/riders/thelab/ui/bluetooth/BluetoothViewModel.kt index b0490c6c..7527b224 100644 --- a/app/src/main/java/com/riders/thelab/ui/bluetooth/BluetoothViewModel.kt +++ b/app/src/main/java/com/riders/thelab/ui/bluetooth/BluetoothViewModel.kt @@ -1,26 +1,26 @@ package com.riders.thelab.ui.bluetooth import android.bluetooth.BluetoothManager -import android.content.Context import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import timber.log.Timber class BluetoothViewModel : ViewModel() { private val isBluetoothEnabled: MutableLiveData = MutableLiveData() - + private val boundedDevices: MutableLiveData> = MutableLiveData() fun getBluetoothEnabled(): LiveData { return isBluetoothEnabled } - fun setBluetooth(context: Context, enable: Boolean) { + fun getBoundedDevices(): LiveData> { + return boundedDevices + } - /* Source : https://stackoverflow.com/questions/69122978/what-do-i-use-now-that-bluetoothadapter-getdefaultadapter-is-deprecated*/ - val bluetoothManager = - context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager + fun setBluetooth(bluetoothManager: BluetoothManager, enable: Boolean) { val isEnabled = bluetoothManager.adapter.isEnabled if (enable && !isEnabled) { @@ -32,24 +32,38 @@ class BluetoothViewModel : ViewModel() { // isBluetoothEnabled.value = true } - fun getBluetoothState(context: Context): Boolean { - val bluetoothManager = - context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager + fun getBluetoothState(bluetoothManager: BluetoothManager): Boolean { return bluetoothManager.adapter.isEnabled } - fun startDiscovery(context: Context) { - val bluetoothManager = - context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager - + fun startDiscovery(bluetoothManager: BluetoothManager) { if (!bluetoothManager.adapter.isDiscovering) { bluetoothManager.adapter.startDiscovery() } } - fun stopDiscovery(context: Context) { - val bluetoothManager = - context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager - bluetoothManager.adapter.cancelDiscovery() + fun stopDiscovery(bluetoothManager: BluetoothManager) { + if (bluetoothManager.adapter.isDiscovering) + bluetoothManager.adapter.cancelDiscovery() + } + + fun fetchBoundedDevices(bluetoothManager: BluetoothManager) { + val pairedDevices = bluetoothManager.adapter.bondedDevices + if (pairedDevices.size > 0) { + + val boundedDevicesToReturn: ArrayList = + mutableListOf() as ArrayList + + for (d in pairedDevices) { + val deviceName = d.name + val macAddress = d.address + Timber.i("paired device: $deviceName at $macAddress") + // do what you need/want this these list items + + boundedDevicesToReturn.add(deviceName) + } + + boundedDevices.value = boundedDevicesToReturn + } } } \ No newline at end of file diff --git a/app/src/main/java/com/riders/thelab/ui/deviceinformation/DeviceInfoViewModel.kt b/app/src/main/java/com/riders/thelab/ui/deviceinformation/DeviceInfoViewModel.kt index 43f3b3a8..a0d0a445 100644 --- a/app/src/main/java/com/riders/thelab/ui/deviceinformation/DeviceInfoViewModel.kt +++ b/app/src/main/java/com/riders/thelab/ui/deviceinformation/DeviceInfoViewModel.kt @@ -22,6 +22,8 @@ class DeviceInfoViewModel : ViewModel() { //Retrieve Screen's height and width val metrics = DisplayMetrics() + + @Suppress("DEPRECATION") activity.windowManager.defaultDisplay.getMetrics(metrics) val mDeviceInfo = DeviceInformation( diff --git a/app/src/main/java/com/riders/thelab/ui/download/DownloadActivity.kt b/app/src/main/java/com/riders/thelab/ui/download/DownloadActivity.kt index 83e13606..1376baec 100644 --- a/app/src/main/java/com/riders/thelab/ui/download/DownloadActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/download/DownloadActivity.kt @@ -6,6 +6,7 @@ import android.view.MenuItem import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat +import androidx.lifecycle.lifecycleScope import com.riders.thelab.R import com.riders.thelab.data.local.model.Download import com.riders.thelab.databinding.ActivityDownloadBinding @@ -98,7 +99,7 @@ class DownloadActivity @DelicateCoroutinesApi private fun downloadFile() { - GlobalScope.launch { + lifecycleScope.launch(coroutineContext) { try { supervisorScope { mViewModel.downloadFile() diff --git a/app/src/main/java/com/riders/thelab/ui/floatingview/FloatingViewActivity.kt b/app/src/main/java/com/riders/thelab/ui/floatingview/FloatingViewActivity.kt index badb992a..fbc73980 100644 --- a/app/src/main/java/com/riders/thelab/ui/floatingview/FloatingViewActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/floatingview/FloatingViewActivity.kt @@ -42,6 +42,7 @@ class FloatingViewActivity : AppCompatActivity() { Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:$packageName") ) + @Suppress("DEPRECATION") startActivityForResult(intent, CODE_DRAW_OVER_OTHER_APP_PERMISSION) } @@ -74,6 +75,8 @@ class FloatingViewActivity : AppCompatActivity() { finish() } } else { + + @Suppress("DEPRECATION") super.onActivityResult(requestCode, resultCode, data) } } @@ -92,7 +95,7 @@ class FloatingViewActivity : AppCompatActivity() { */ private fun initializeView() { Timber.d("initializeView()") - findViewById(R.id.notify_me).setOnClickListener { view: View? -> + findViewById(R.id.notify_me).setOnClickListener { startService( Intent( this@FloatingViewActivity, diff --git a/app/src/main/java/com/riders/thelab/ui/googledrive/GoogleDriveActivity.kt b/app/src/main/java/com/riders/thelab/ui/googledrive/GoogleDriveActivity.kt index 3e726ba5..f4822ad1 100644 --- a/app/src/main/java/com/riders/thelab/ui/googledrive/GoogleDriveActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/googledrive/GoogleDriveActivity.kt @@ -5,6 +5,7 @@ import android.content.IntentSender import android.os.Bundle import android.widget.Toast import androidx.appcompat.app.AppCompatActivity +import androidx.lifecycle.lifecycleScope import com.google.android.gms.auth.GoogleAuthException import com.google.android.gms.auth.api.signin.GoogleSignIn import com.google.android.gms.auth.api.signin.GoogleSignInClient @@ -174,6 +175,8 @@ class GoogleDriveActivity // From the GoogleSignInClient object we can get the signInIntent // which we can use in startActivityForResult to trigger the login flow val signInIntent = mGoogleSignInClient?.signInIntent + + @Suppress("DEPRECATION") startActivityForResult(signInIntent, CONST_SIGN_IN) } } @@ -263,7 +266,7 @@ class GoogleDriveActivity private fun accessDriveFiles() { Timber.i("accessDriveFiles()") checkLastSignedInAccount()?.let { googleDriveService -> - GlobalScope.launch(Dispatchers.IO) { + lifecycleScope.launch(Dispatchers.IO) { try { Timber.d("googleDriveService.files()") @@ -292,6 +295,7 @@ class GoogleDriveActivity ex.printStackTrace() withContext(Dispatchers.Main) { + @Suppress("DEPRECATION") startActivityForResult(ex.intent, REQUEST_SIGN_IN) } } catch (transientEx: IOException) { diff --git a/app/src/main/java/com/riders/thelab/ui/googlesignin/GoogleSignInActivity.kt b/app/src/main/java/com/riders/thelab/ui/googlesignin/GoogleSignInActivity.kt index edad3791..a8ee0550 100644 --- a/app/src/main/java/com/riders/thelab/ui/googlesignin/GoogleSignInActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/googlesignin/GoogleSignInActivity.kt @@ -64,6 +64,7 @@ class GoogleSignInActivity : AppCompatActivity(), View.OnClickListener { // If the GoogleSignInOptions only asks for IDToken and/or profile and/or email then no // consent screen will be shown here. val signInIntent: Intent = mGoogleSignInClient?.signInIntent!! + @Suppress("DEPRECATION") startActivityForResult(signInIntent, RC_GET_TOKEN) } @@ -111,6 +112,7 @@ class GoogleSignInActivity : AppCompatActivity(), View.OnClickListener { @Deprecated("") override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + @Suppress("DEPRECATION") super.onActivityResult(requestCode, resultCode, data) if (requestCode == RC_GET_TOKEN) { // [START get_id_token] diff --git a/app/src/main/java/com/riders/thelab/ui/locationonmaps/LocationOnMapsActivity.kt b/app/src/main/java/com/riders/thelab/ui/locationonmaps/LocationOnMapsActivity.kt index 41695a2d..ae8159d2 100644 --- a/app/src/main/java/com/riders/thelab/ui/locationonmaps/LocationOnMapsActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/locationonmaps/LocationOnMapsActivity.kt @@ -151,6 +151,7 @@ class LocationOnMapsActivity : AppCompatActivity(), OnMapReadyCallback, } } + @Suppress("DEPRECATION") super.onActivityResult(requestCode, resultCode, data) } @@ -309,6 +310,7 @@ class LocationOnMapsActivity : AppCompatActivity(), OnMapReadyCallback, } } mRequestingLocationUpdates = false + @Suppress("DEPRECATION") mLocationRequest = LocationRequest() mLocationRequest!!.interval = UPDATE_INTERVAL_IN_MILLISECONDS mLocationRequest!!.fastestInterval = FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS diff --git a/app/src/main/java/com/riders/thelab/ui/mainactivity/MainActivity.kt b/app/src/main/java/com/riders/thelab/ui/mainactivity/MainActivity.kt index 9e4250eb..da24c1df 100644 --- a/app/src/main/java/com/riders/thelab/ui/mainactivity/MainActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/mainactivity/MainActivity.kt @@ -186,7 +186,6 @@ class MainActivity : AppCompatActivity(), super.onPause() } - @DelicateCoroutinesApi override fun onResume() { super.onResume() Timber.i("onResume()") @@ -234,6 +233,7 @@ class MainActivity : AppCompatActivity(), override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + @Suppress("DEPRECATION") super.onActivityResult(requestCode, resultCode, data) if (resultCode == Activity.RESULT_OK && requestCode == GPS_REQUEST) { isGPS = true // flag maintain before get location @@ -717,6 +717,7 @@ class MainActivity : AppCompatActivity(), Timber.d("toggleWifi()") if (LabCompatibilityManager.isAndroid10()) { val panelIntent = Intent(Settings.Panel.ACTION_INTERNET_CONNECTIVITY) + @Suppress("DEPRECATION") startActivityForResult(panelIntent, 0) } else { // use previous solution, add appropriate permissions to AndroidManifest file (see answers above) @@ -727,6 +728,7 @@ class MainActivity : AppCompatActivity(), Timber.d("(this.applicationContext.getSystemService(Context.WIFI_SERVICE) as? WifiManager) $isWifiEnabled") Timber.d("This should activate wifi") + @Suppress("DEPRECATION") isWifiEnabled = true UIManager.updateToolbarIcon( @@ -739,6 +741,7 @@ class MainActivity : AppCompatActivity(), Timber.d("(this.applicationContext.getSystemService(Context.WIFI_SERVICE) as? WifiManager) $isWifiEnabled") Timber.d("This should disable wifi") + @Suppress("DEPRECATION") isWifiEnabled = false UIManager.updateToolbarIcon( @@ -748,6 +751,7 @@ class MainActivity : AppCompatActivity(), R.drawable.ic_wifi_off ) } + @Suppress("DEPRECATION") this.isWifiEnabled = !isWifiEnabled } } diff --git a/app/src/main/java/com/riders/thelab/ui/mainactivity/MainActivityAdapter.kt b/app/src/main/java/com/riders/thelab/ui/mainactivity/MainActivityAdapter.kt index 85f6d412..1bc3b0b7 100644 --- a/app/src/main/java/com/riders/thelab/ui/mainactivity/MainActivityAdapter.kt +++ b/app/src/main/java/com/riders/thelab/ui/mainactivity/MainActivityAdapter.kt @@ -101,7 +101,7 @@ class MainActivityAdapter constructor( holder.viewBinding.rowItemCardView?.setOnClickListener { view: View? -> lastPosition = position notifyDataSetChanged() - mListener.onAppItemCLickListener(view!!, item, holder.adapterPosition) + mListener.onAppItemCLickListener(view!!, item, holder.absoluteAdapterPosition) } } diff --git a/app/src/main/java/com/riders/thelab/ui/mainactivity/fragment/news/NewsFragment.kt b/app/src/main/java/com/riders/thelab/ui/mainactivity/fragment/news/NewsFragment.kt index 4a72d5a5..35f57ab9 100644 --- a/app/src/main/java/com/riders/thelab/ui/mainactivity/fragment/news/NewsFragment.kt +++ b/app/src/main/java/com/riders/thelab/ui/mainactivity/fragment/news/NewsFragment.kt @@ -71,10 +71,12 @@ class NewsFragment : BaseFragment(), View.OnClickListener { Timber.e("bundle is null - check the data you are trying to pass through please !") } else { Timber.e("get the data one by one") - (extras.getParcelable(EXTRA_APP) as App?)?.let { - item = it + if (null != extras.getParcelable(EXTRA_APP)) { + item = extras.getParcelable(EXTRA_APP) } - + /*(extras.getParcelable(EXTRA_APP) as App?)?.let { + item = it + }*/ } } diff --git a/app/src/main/java/com/riders/thelab/ui/schedule/ScheduleActivity.kt b/app/src/main/java/com/riders/thelab/ui/schedule/ScheduleActivity.kt index 3f9492f7..2e71e11b 100644 --- a/app/src/main/java/com/riders/thelab/ui/schedule/ScheduleActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/schedule/ScheduleActivity.kt @@ -23,14 +23,16 @@ import timber.log.Timber class ScheduleActivity : AppCompatActivity() { - private lateinit var viewBinding: ActivityScheduleBinding + private var _viewBinding: ActivityScheduleBinding? = null + + private val binding get() = _viewBinding!! private val mViewModel: ScheduleViewModel by viewModels() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - viewBinding = ActivityScheduleBinding.inflate(layoutInflater) - setContentView(viewBinding.root) + _viewBinding = ActivityScheduleBinding.inflate(layoutInflater) + setContentView(binding.root) mViewModel.getCountDown().observe( this, @@ -54,12 +56,12 @@ class ScheduleActivity : AppCompatActivity() { }) - viewBinding.button.setOnClickListener { - viewBinding.time.text.toString().isNotBlank().let { + binding.button.setOnClickListener { + binding.time.text.toString().isNotBlank().let { if (it) - mViewModel.startAlert(this, viewBinding.time.text.toString()) + mViewModel.startAlert(this, binding.time.text.toString()) else UIManager.showCustomToast( - this, + this@ScheduleActivity, ToastTypeEnum.WARNING, "Field cannot be empty. Please enter a valid number" ) @@ -68,6 +70,7 @@ class ScheduleActivity : AppCompatActivity() { } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + @Suppress("DEPRECATION") super.onActivityResult(requestCode, resultCode, data) if (ScheduleAlarmReceiver.REQUEST_CODE == resultCode) { Timber.e("result code caught !!!!"); @@ -111,20 +114,22 @@ class ScheduleActivity : AppCompatActivity() { override fun onDestroy() { mViewModel.unbindService(this) super.onDestroy() + + _viewBinding = null } private fun showCountDownView() { - viewBinding.llDelayTimeContainer.visibility = View.VISIBLE + binding.llDelayTimeContainer.visibility = View.VISIBLE } private fun hideCountDownView() { - viewBinding.llDelayTimeContainer.visibility = View.GONE + binding.llDelayTimeContainer.visibility = View.GONE } @SuppressLint("SetTextI18n") fun updateContDownUI(millisUntilFinished: Long) { - runOnUiThread { viewBinding.tvDelayTime.text = "" + millisUntilFinished } + runOnUiThread { binding.tvDelayTime.text = "" + millisUntilFinished } } //////////////////////////// diff --git a/app/src/main/java/com/riders/thelab/ui/songplayer/SongPlayerActivity.kt b/app/src/main/java/com/riders/thelab/ui/songplayer/SongPlayerActivity.kt index 8f9d80dc..14377570 100644 --- a/app/src/main/java/com/riders/thelab/ui/songplayer/SongPlayerActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/songplayer/SongPlayerActivity.kt @@ -100,6 +100,7 @@ class SongPlayerActivity : AppCompatActivity(), //Log.d("Progress", ""+progress); if (_viewBinding != null) binding.songProgressBar.progress = progress + @Suppress("DEPRECATION") mHandler = Handler() // Running this thread after 100 milliseconds mHandler?.postDelayed(this, 100) @@ -152,6 +153,7 @@ class SongPlayerActivity : AppCompatActivity(), } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + @Suppress("DEPRECATION") super.onActivityResult(requestCode, resultCode, data) if (resultCode == 100) { @@ -434,7 +436,6 @@ class SongPlayerActivity : AppCompatActivity(), binding.cvSongPlayer.isClickable = true mAdapter.setClickable(true) } - } /** diff --git a/app/src/main/java/com/riders/thelab/ui/songplayer/SongPlayerAdapter.kt b/app/src/main/java/com/riders/thelab/ui/songplayer/SongPlayerAdapter.kt index 0705ed87..a8f17047 100644 --- a/app/src/main/java/com/riders/thelab/ui/songplayer/SongPlayerAdapter.kt +++ b/app/src/main/java/com/riders/thelab/ui/songplayer/SongPlayerAdapter.kt @@ -19,7 +19,7 @@ class SongPlayerAdapter( private var lastClickedPosition = -1 // This keeps track of the currently selected position - var selectedPosition by Delegates.observable(-1) { property, oldPos, newPos -> + var selectedPosition by Delegates.observable(-1) { _, oldPos, newPos -> if (newPos in fileList.indices) { notifyItemChanged(oldPos) notifyItemChanged(newPos) diff --git a/app/src/main/java/com/riders/thelab/ui/songplayer/SongPlayerUtils.kt b/app/src/main/java/com/riders/thelab/ui/songplayer/SongPlayerUtils.kt index e1ea76bf..c664aea9 100644 --- a/app/src/main/java/com/riders/thelab/ui/songplayer/SongPlayerUtils.kt +++ b/app/src/main/java/com/riders/thelab/ui/songplayer/SongPlayerUtils.kt @@ -83,9 +83,11 @@ class SongPlayerUtils { } mediaSession.setCallback(callback) + @Suppress("DEPRECATION") mediaSession.setFlags( MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS or MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS ) + mediaSession.setPlaybackState( PlaybackStateCompat.Builder() .setState( diff --git a/app/src/main/java/com/riders/thelab/ui/splashscreen/SplashScreenActivity.kt b/app/src/main/java/com/riders/thelab/ui/splashscreen/SplashScreenActivity.kt index 7c7943ea..7da37173 100644 --- a/app/src/main/java/com/riders/thelab/ui/splashscreen/SplashScreenActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/splashscreen/SplashScreenActivity.kt @@ -15,6 +15,7 @@ import android.view.WindowManager import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity import androidx.core.animation.addListener +import androidx.lifecycle.lifecycleScope import com.riders.thelab.R import com.riders.thelab.core.utils.LabAnimationsManager import com.riders.thelab.core.utils.LabCompatibilityManager @@ -24,12 +25,18 @@ import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.* import timber.log.Timber import java.util.concurrent.TimeUnit +import kotlin.coroutines.CoroutineContext @AndroidEntryPoint -class SplashScreenActivity : AppCompatActivity(), OnPreparedListener, +class SplashScreenActivity : AppCompatActivity(), + CoroutineScope, + OnPreparedListener, OnCompletionListener { + override val coroutineContext: CoroutineContext + get() = Dispatchers.Main + Job() + companion object { private const val ANDROID_RES_PATH = "android.resource://" private const val SEPARATOR = "/" @@ -226,13 +233,11 @@ class SplashScreenActivity : AppCompatActivity(), OnPreparedListener, fadeProgressAnimator.start() } - @DelicateCoroutinesApi private fun clearAllAnimations() { - Timber.d("clearAllAnimations()") + Timber.d("clearAllAnimations() - Use coroutines to clear animations then launch Main Activity") - Timber.d("Use coroutines to clear animations then launch Main Activity") // Use coroutines to clear animations then launch Main Activity - GlobalScope.launch(Dispatchers.Main) { + lifecycleScope.launch(coroutineContext) { Timber.d("Use coroutines to clear animations") LabAnimationsManager.getInstance().clearAnimations( versionTextAnimator, fadeProgressAnimator diff --git a/app/src/main/res/layout/activity_song_player.xml b/app/src/main/res/layout/activity_song_player.xml index 8617c15d..7b06431f 100644 --- a/app/src/main/res/layout/activity_song_player.xml +++ b/app/src/main/res/layout/activity_song_player.xml @@ -36,7 +36,6 @@ tools:motionDebug="SHOW_ALL"> - diff --git a/app/src/main/res/xml/song_player_scene.xml b/app/src/main/res/xml/song_player_scene.xml index e72f87d0..d3a80319 100644 --- a/app/src/main/res/xml/song_player_scene.xml +++ b/app/src/main/res/xml/song_player_scene.xml @@ -50,7 +50,6 @@ - Date: Tue, 5 Oct 2021 17:11:07 +0200 Subject: [PATCH 11/11] [feat/041-spring-choice] : Optimize imports --- .../java/com/riders/thelab/core/livedata/ConnectionLiveData.kt | 1 + app/src/main/java/com/riders/thelab/core/storage/FileManager.kt | 2 -- app/src/main/java/com/riders/thelab/ui/base/SimpleActivity.kt | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/src/main/java/com/riders/thelab/core/livedata/ConnectionLiveData.kt b/app/src/main/java/com/riders/thelab/core/livedata/ConnectionLiveData.kt index 3e1bcd83..78e2cf71 100644 --- a/app/src/main/java/com/riders/thelab/core/livedata/ConnectionLiveData.kt +++ b/app/src/main/java/com/riders/thelab/core/livedata/ConnectionLiveData.kt @@ -32,6 +32,7 @@ class ConnectionLiveData( @Suppress("DEPRECATION") val activeNetwork = intent.extras!![ConnectivityManager.EXTRA_NETWORK_INFO] as NetworkInfo? + @Suppress("DEPRECATION") val isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting diff --git a/app/src/main/java/com/riders/thelab/core/storage/FileManager.kt b/app/src/main/java/com/riders/thelab/core/storage/FileManager.kt index 56a65eef..f6b79786 100644 --- a/app/src/main/java/com/riders/thelab/core/storage/FileManager.kt +++ b/app/src/main/java/com/riders/thelab/core/storage/FileManager.kt @@ -1,8 +1,6 @@ package com.riders.thelab.core.storage import android.content.Context -import android.graphics.BitmapFactory -import android.media.MediaMetadataRetriever import android.os.Build import android.os.Environment import android.os.storage.StorageManager diff --git a/app/src/main/java/com/riders/thelab/ui/base/SimpleActivity.kt b/app/src/main/java/com/riders/thelab/ui/base/SimpleActivity.kt index ff02a5f3..e7a03124 100644 --- a/app/src/main/java/com/riders/thelab/ui/base/SimpleActivity.kt +++ b/app/src/main/java/com/riders/thelab/ui/base/SimpleActivity.kt @@ -1,6 +1,5 @@ package com.riders.thelab.ui.base -import android.view.View import androidx.appcompat.app.AppCompatActivity import com.google.android.material.appbar.MaterialToolbar