Skip to content

Instantly share code, notes, and snippets.

View Ochornma's full-sized avatar
🎯
Looking for new opportunities

Promise Ochornma Ochornma

🎯
Looking for new opportunities
View GitHub Profile
@Ochornma
Ochornma / App.kt
Last active September 7, 2020 21:35
class App: Application() {
lateinit var appContainer: AppContainer
var ID = "My app"
override fun onCreate() {
super.onCreate()
appContainer = AppContainer(this)
createNotificationChannels()
}
private fun createNotificationChannels() {
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
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")
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")
//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) }
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)
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)
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph"
app:startDestination="@id/navigation_onBoarding">
<fragment
android:id="@+id/navigation_onBoarding"
android:name="com.app.softkash.onboarding.OnboardingFragment"
<?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"
<?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"