Skip to content

Instantly share code, notes, and snippets.

View sajjadyousefnia's full-sized avatar
🤒
Out sick

Sajjad Yousefnia sajjadyousefnia

🤒
Out sick
View GitHub Profile
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.card.MaterialCardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
package com.sands.android.view.activity
import android.Manifest
import android.annotation.SuppressLint
import android.app.DownloadManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.IntentFilter
import android.content.pm.PackageManager
import android.database.Cursor
@SuppressLint("Range")
private suspend fun downloadFromScratch() {
try {
val currentDownloadModel = runningDownloadList.last()
val downloadManager = getSystemService(DownloadManager::class.java)
val request =
DownloadManager.Request(currentDownloadModel.url.toUri()).setMimeType("video/*")
.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI and DownloadManager.Request.NETWORK_MOBILE)
fun sendPing(address: String): Boolean {
val policy = ThreadPolicy.Builder().permitAll().build()
StrictMode.setThreadPolicy(policy)
return try {
val inetAddress = InetAddress.getByName(address)
inetAddress.isReachable(5000) // Timeout in milliseconds (5 seconds)
} catch (e: Exception) {
false
}
}
@SuppressLint("Range")
private suspend fun downloadFromScratch() {
try {
val downloadManager = getSystemService(DownloadManager::class.java)
val request = DownloadManager.Request(currentUrl.toUri()).setMimeType("video/*")
.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI and DownloadManager.Request.NETWORK_MOBILE)
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)
.setTitle("در حال دانلود فیلم " + currentTitle).setDestinationInExternalPublicDir(
Environment.DIRECTORY_DOWNLOADS, DOWNLOADS_SUB_DIRECTORY + currentTitle
@SuppressLint("Range")
private suspend fun downloadFromScratch() {
try {
val downloadManager = getSystemService(DownloadManager::class.java)
val request = DownloadManager.Request(currentUrl.toUri()).setMimeType("video/*")
.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI and DownloadManager.Request.NETWORK_MOBILE)
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)
.setTitle("در حال دانلود فیلم " + currentTitle).setDestinationInExternalPublicDir(
Environment.DIRECTORY_DOWNLOADS, DOWNLOADS_SUB_DIRECTORY + currentTitle
@SuppressLint("Range")
private suspend fun downloadFromScratch() {
try {
val downloadManager = getSystemService(DownloadManager::class.java)
val request = DownloadManager.Request(currentUrl.toUri()).setMimeType("video/*")
.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI and DownloadManager.Request.NETWORK_MOBILE)
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)
.setTitle("در حال دانلود فیلم " + currentTitle).setDestinationInExternalPublicDir(
Environment.DIRECTORY_DOWNLOADS, DOWNLOADS_SUB_DIRECTORY + currentTitle
val request = DownloadManager.Request(Uri.parse(url))
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)
.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "filename.ext")
.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI or DownloadManager.Request.NETWORK_MOBILE)
val manager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
val downloadId = manager.enqueue(request)
val query = DownloadManager.Query().setFilterById(downloadId)
@Database(
entities = [MdlMovie::class, MdlLastPlay::class],
version = 16, exportSchema = false
)
@TypeConverters(Converters::class)
abstract class RoomDB : RoomDatabase() {
abstract fun appDao(): AppDao
companion object {
private var INSTANCE: RoomDB? = null
fun EditText.addThousandSeparator() {
this.addTextChangedListener(object : TextWatcher {
private var current = ""
override fun beforeTextChanged(
s: CharSequence?,
start: Int,
count: Int,
after: Int
) {
}