This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class App: Application() { | |
| lateinit var appContainer: AppContainer | |
| var ID = "My app" | |
| override fun onCreate() { | |
| super.onCreate() | |
| appContainer = AppContainer(this) | |
| createNotificationChannels() | |
| } | |
| private fun createNotificationChannels() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class AppContainer(val context: Context) { | |
| private var dataSource = DefaultHttpDataSourceFactory( | |
| Util.getUserAgent(context, context.resources.getString(R.string.app_name)),null /*listener*/ ,30 * 1000,30 * 1000, true ) | |
| private var dataBase:DatabaseProvider | |
| private var downloadContentDirectory: File | |
| var downloadCache: Cache | |
| var downloadManager: DownloadManager |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MyDownload: DownloadService(1, DEFAULT_FOREGROUND_NOTIFICATION_UPDATE_INTERVAL, "my app", R.string.app_name, R.string.app_describe){ | |
| private lateinit var notificationHelper: DownloadNotificationHelper | |
| private lateinit var context: Context | |
| override fun onCreate() { | |
| super.onCreate() | |
| context = this | |
| notificationHelper= DownloadNotificationHelper(this, "my app") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private fun downloadMedia(){ | |
| //the download request | |
| val helper = context?.let { DownloadHelper.forProgressive(it, the URI of the media) } | |
| helper?.prepare(object : DownloadHelper.Callback { | |
| override fun onPrepared(helper: DownloadHelper) { | |
| val json = JSONObject() | |
| //extra data about the download like title, artist e.tc below is an example | |
| json.put("title" "Download like youtube") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //to resume download | |
| context?.let { it1 -> DownloadService.sendResumeDownloads(it1, MyDownload::class.java, true) } | |
| //to pause download | |
| context?.let { it1 -> DownloadService.sendPauseDownloads(it1, MyDownload::class.java, true) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private fun getDownloadedItems(): MutableList<Message> { | |
| /*Asumming this is your Media item data class | |
| data class Media(var url: String, var artist: String, var title: String) | |
| */ | |
| val downloadedTracks= ArrayList<Media>() | |
| val downloadCursor: DownloadCursor =(context?.applicationContext as App).appContainer.downloadManager.downloadIndex.getDownloads() | |
| if (downloadCursor.moveToFirst()) { | |
| do{ | |
| val jsonString = Util.fromUtf8Bytes(downloadCursor.download.request.data) | |
| val jsonObject = JSONObject(jsonString) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val dataSourceFactory = DefaultDataSourceFactory(context, Util.getUserAgent(context, getString(R.string.app_name))) | |
| val cachedDataSourceFactory =CacheDataSourceFactory((application as App).appContainer.downloadCache, dataSourceFactory) | |
| val mediaSources = ProgressiveMediaSource.Factory(cachedDataSourceFactory).createMediaSource( | |
| Uri.parse(media.url)) | |
| player.prepare(mediaSources) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:tools="http://schemas.android.com/tools" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| xmlns:app="http://schemas.android.com/apk/res-auto" | |
| tools:context=".ui.home.HomeFragment"> | |
| <ImageView | |
| android:id="@+id/toolBarIcon" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:tools="http://schemas.android.com/tools" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| xmlns:app="http://schemas.android.com/apk/res-auto" | |
| tools:context=".ui.bvnNotVerified.BVNNotVerifiedFragment"> | |
| <ImageView | |
| android:id="@+id/image" |