Skip to content

Commit 6ef6e42

Browse files
authored
Merge pull request #148 from pravinyo/fix_multi_download_screen
Fix multi download screen
2 parents ae3d53a + e2bd98c commit 6ef6e42

File tree

46 files changed

+519
-324
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+519
-324
lines changed

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ dependencies {
8686
debugImplementation(LibraryDependency.LEAKY_CANARY)
8787
implementation(LibraryDependency.SUPPORT_V13)
8888
implementation(LibraryDependency.OSS_LICENSES)
89+
implementation(LibraryDependency.TOOL_TIP)
8990

9091
//crash analytics report
9192
implementation(LibraryDependency.FIREBASE_ANALYTICS)

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
</intent-filter>
3535
</activity>
3636

37-
<activity android:name=".feature_downloader.presentation.DownloadManagementActivity" />
37+
<activity
38+
android:launchMode= "singleTop"
39+
android:name=".feature_downloader.presentation.DownloadManagementActivity" />
3840

3941
<activity
4042
android:name="com.google.android.gms.oss.licenses.OssLicensesMenuActivity"

app/src/main/java/com/allsoftdroid/audiobook/presentation/MainActivity.kt

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import com.allsoftdroid.audiobook.feature_downloader.presentation.DownloadManage
1818
import com.allsoftdroid.audiobook.feature_mini_player.presentation.MiniPlayerFragment
1919
import com.allsoftdroid.audiobook.presentation.viewModel.MainActivityViewModel
2020
import com.allsoftdroid.audiobook.utility.MovableFrameLayout
21-
import com.allsoftdroid.common.base.utils.StoragePermissionHandler
21+
import com.allsoftdroid.audiobook.utility.OnSwipeTouchListener
2222
import com.allsoftdroid.common.base.activity.BaseActivity
2323
import com.allsoftdroid.common.base.extension.Event
2424
import com.allsoftdroid.common.base.network.ConnectionLiveData
@@ -27,12 +27,14 @@ import com.allsoftdroid.common.base.store.downloader.DownloadEvent
2727
import com.allsoftdroid.common.base.store.downloader.DownloadEventStore
2828
import com.allsoftdroid.common.base.store.downloader.DownloadNothing
2929
import com.allsoftdroid.common.base.store.userAction.*
30+
import com.allsoftdroid.common.base.utils.StoragePermissionHandler
3031
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity
3132
import com.google.android.material.snackbar.BaseTransientBottomBar
3233
import com.google.android.material.snackbar.Snackbar
3334
import io.reactivex.android.schedulers.AndroidSchedulers
3435
import io.reactivex.disposables.CompositeDisposable
3536
import io.reactivex.schedulers.Schedulers
37+
import it.sephiroth.android.library.xtooltip.Tooltip
3638
import org.koin.android.ext.android.inject
3739
import org.koin.androidx.viewmodel.ext.android.viewModel
3840
import org.koin.core.parameter.parametersOf
@@ -55,6 +57,7 @@ class MainActivity : BaseActivity() {
5557
private val downloader: IDownloaderCore by inject{parametersOf(this)}
5658
private val userActionEventStore:UserActionEventStore by inject()
5759
private val disposables = CompositeDisposable()
60+
private var isShownTooltip = false
5861

5962

6063
private val snackBar by lazy {
@@ -233,7 +236,19 @@ class MainActivity : BaseActivity() {
233236
.commit()
234237
}
235238

236-
findViewById<MovableFrameLayout>(R.id.miniPlayerContainer).visibility = View.VISIBLE
239+
findViewById<MovableFrameLayout>(R.id.miniPlayerContainer).apply {
240+
visibility = View.VISIBLE
241+
setOnTouchListener(object : OnSwipeTouchListener(context) {
242+
243+
override fun onSwipeTop() {
244+
super.onSwipeTop()
245+
Timber.d("Event sent for opening main player event")
246+
userActionEventStore.publish(Event(OpenMainPlayerUI(this::class.java.simpleName)))
247+
}
248+
})
249+
}.post {
250+
if(!isShownTooltip) showToolTipForMiniPlayer()
251+
}
237252

238253
findViewById<View>(R.id.navHostFragment).apply {
239254

@@ -243,6 +258,8 @@ class MainActivity : BaseActivity() {
243258
layoutParams = layout
244259
}
245260

261+
262+
246263
}else{
247264
val fragment = supportFragmentManager.findFragmentByTag(MINI_PLAYER_TAG)
248265

@@ -301,6 +318,10 @@ class MainActivity : BaseActivity() {
301318
}
302319
}
303320

321+
is Finished -> {
322+
mainActivityViewModel.playerStatus(showPlayer = false)
323+
}
324+
304325
else -> {
305326
Timber.d("Unknown event received")
306327
Timber.d("Unknown Event has message of type TrackDetails: ${event is TrackDetails}")
@@ -364,4 +385,28 @@ class MainActivity : BaseActivity() {
364385
}
365386

366387
}
388+
389+
private fun showToolTipForMiniPlayer(){
390+
val containerView:View = findViewById<MovableFrameLayout>(R.id.miniPlayerContainer)
391+
392+
val metrics = resources.displayMetrics
393+
val gravity = Tooltip.Gravity.TOP
394+
395+
var tooltip:Tooltip? = Tooltip.Builder(containerView.context)
396+
.anchor(containerView,100,70,false)
397+
.text(getString(R.string.tooltip_open_player_message))
398+
.maxWidth(metrics.widthPixels / 2)
399+
.arrow(false)
400+
.floatingAnimation(Tooltip.Animation.DEFAULT)
401+
.showDuration(3000)
402+
.overlay(true)
403+
.create()
404+
405+
tooltip
406+
?.doOnHidden {
407+
tooltip = null
408+
isShownTooltip = true
409+
}
410+
?.show(containerView.rootView, gravity, true)
411+
}
367412
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package com.allsoftdroid.audiobook.utility
2+
3+
import android.annotation.SuppressLint
4+
import android.content.Context
5+
import android.view.GestureDetector
6+
import android.view.MotionEvent
7+
import android.view.View
8+
import kotlin.math.abs
9+
10+
open class OnSwipeTouchListener(ctx: Context) : View.OnTouchListener {
11+
12+
private val gestureDetector: GestureDetector
13+
14+
companion object {
15+
16+
private const val SWIPE_THRESHOLD = 100
17+
private const val SWIPE_VELOCITY_THRESHOLD = 100
18+
}
19+
20+
init {
21+
gestureDetector = GestureDetector(ctx, GestureListener())
22+
}
23+
24+
@SuppressLint("ClickableViewAccessibility")
25+
override fun onTouch(v: View, event: MotionEvent): Boolean {
26+
return gestureDetector.onTouchEvent(event)
27+
}
28+
29+
private inner class GestureListener : GestureDetector.SimpleOnGestureListener() {
30+
31+
32+
override fun onDown(e: MotionEvent): Boolean {
33+
return true
34+
}
35+
36+
override fun onFling(e1: MotionEvent, e2: MotionEvent, velocityX: Float, velocityY: Float): Boolean {
37+
var result = false
38+
try {
39+
val diffY = e2.y - e1.y
40+
val diffX = e2.x - e1.x
41+
if (abs(diffX) > abs(diffY)) {
42+
if (abs(diffX) > SWIPE_THRESHOLD && abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
43+
if (diffX > 0) {
44+
onSwipeRight()
45+
} else {
46+
onSwipeLeft()
47+
}
48+
result = true
49+
}
50+
} else if (abs(diffY) > SWIPE_THRESHOLD && abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
51+
if (diffY > 0) {
52+
onSwipeBottom()
53+
} else {
54+
onSwipeTop()
55+
}
56+
result = true
57+
}
58+
} catch (exception: Exception) {
59+
exception.printStackTrace()
60+
}
61+
62+
return result
63+
}
64+
65+
66+
}
67+
68+
open fun onSwipeRight() {}
69+
70+
open fun onSwipeLeft() {}
71+
72+
open fun onSwipeTop() {}
73+
74+
open fun onSwipeBottom() {}
75+
}
-867 Bytes
Loading
-333 Bytes
Loading
-223 Bytes
Loading
-400 Bytes
Loading
-599 Bytes
Loading
-867 Bytes
Loading

0 commit comments

Comments
 (0)