Skip to content

Commit

Permalink
[feature|optimize|fix] Support opening non-media files via other apps…
Browse files Browse the repository at this point in the history
…; optimize torrent download code; fix the problem that the About page Badge is not displayed
  • Loading branch information
SkyD666 committed Feb 21, 2024
1 parent c677eb0 commit 0dfe756
Show file tree
Hide file tree
Showing 22 changed files with 536 additions and 398 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@

1. **Subscribe to RSS**, Update RSS, **Read** RSS
2. **Download enclosures** (enclosure tags) of **torrent or magnet** links in RSS articles
3. **Play downloaded videos**
4. Support variable playback **speed**, **long press** to speed up playback
5. **Double-finger** gesture to **rotate and zoom** video
6. **Swipe** on the video to **control volume**, **brightness**, and **playback position**
7. Support **searching** existing **RSS subscription content**
8. Support **dark mode**
9. ......
2. **Seeding** downloaded files
4. **Play downloaded videos**
5. Support variable playback **speed**, **long press** to speed up playback
6. **Double-finger** gesture to **rotate and zoom** video
7. **Swipe** on the video to **control volume**, **brightness**, and **playback position**
8. **Searching** existing **RSS subscription content**
9. **Play other videos on the phone**
10. Support **dark mode**
11. ......

## 🚧 Todo

1. **Automatically update RSS** subscriptions and **download videos**
2. **Customize player settings**, such as default screen scale, surface type used by the player, and more
3. **Float** video playback **window**
4. **Automatically** play the **next video**
5. **Seeding** downloaded files
6. **Play other videos on the phone**

## 🤩 Screenshots

Expand Down
12 changes: 10 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ android {
applicationId = "com.skyd.anivu"
minSdk = 24
targetSdk = 34
versionCode = 3
versionName = "1.0-beta05"
versionCode = 4
versionName = "1.0-beta06"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down Expand Up @@ -49,6 +49,14 @@ android {
}
}

applicationVariants.all {
outputs
.map { it as com.android.build.gradle.internal.api.BaseVariantOutputImpl }
.forEach {
it.outputFileName = "AniVu_${versionName}_${buildType.name}_${flavorName}.apk"
}
}

buildTypes {
debug {
isMinifyEnabled = false
Expand Down
18 changes: 0 additions & 18 deletions app/src/main/java/com/skyd/anivu/ext/ContextExt.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
package com.skyd.anivu.ext

import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.ContextWrapper
import android.content.Intent
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.content.res.TypedArray
import android.graphics.Point
import android.net.Uri
import android.os.Build
import android.util.TypedValue
import android.view.WindowManager
import android.widget.Toast
import com.skyd.anivu.R
import com.skyd.anivu.ui.component.showToast

val Context.activity: Activity
get() {
Expand Down Expand Up @@ -91,16 +85,4 @@ fun Context.getAppName(): String? {
e.printStackTrace()
null
}
}

fun Context.openBrowser(url: String) {
try {
val uri: Uri = Uri.parse(url)
val intent = Intent(Intent.ACTION_VIEW, uri)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startActivity(intent)
} catch (e: ActivityNotFoundException) {
e.printStackTrace()
getString(R.string.no_browser_found, url).showToast(Toast.LENGTH_LONG)
}
}
40 changes: 40 additions & 0 deletions app/src/main/java/com/skyd/anivu/ext/IOExt.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package com.skyd.anivu.ext

import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.provider.OpenableColumns
import android.widget.Toast
import androidx.core.content.ContextCompat
import com.skyd.anivu.R
import com.skyd.anivu.appContext
import com.skyd.anivu.ui.component.showToast
import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
Expand Down Expand Up @@ -36,6 +43,39 @@ fun Uri.fileName(): String? {
return name ?: path?.substringAfterLast("/")?.toDecodedUrl()
}

fun String.openBrowser(context: Context) {
Uri.parse(this).openBrowser(context)
}

fun Uri.openBrowser(context: Context) {
try {
val intent = Intent(Intent.ACTION_VIEW, this)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
context.startActivity(intent)
} catch (e: ActivityNotFoundException) {
e.printStackTrace()
context.getString(R.string.no_browser_found, path).showToast(Toast.LENGTH_LONG)
}
}

fun Uri.openWith(context: Context) {
try {
val mimeType = context.contentResolver.getType(this)
val intent = Intent.createChooser(
Intent().apply {
action = Intent.ACTION_VIEW
setDataAndType(this@openWith, mimeType)
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
},
context.getString(R.string.open_with)
)
ContextCompat.startActivity(context, intent, null)
} catch (e: Exception) {
e.printStackTrace()
context.getString(R.string.failed_msg, e.message).showToast(Toast.LENGTH_LONG)
}
}

fun InputStream.saveTo(target: File): File {
val parentFile = target.parentFile
if (parentFile?.exists() == false) {
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/skyd/anivu/ext/NumberExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ val Int.sp: Int
TypedValue.COMPLEX_UNIT_SP,
this.toFloat(),
Resources.getSystem().displayMetrics
).toInt()
).toInt()

fun Float.toPercentage(): String = "%.2f%%".format(this * 100)
18 changes: 18 additions & 0 deletions app/src/main/java/com/skyd/anivu/ext/ViewExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import android.graphics.Rect
import android.view.DisplayCutout
import android.view.View
import android.view.ViewGroup
import android.view.ViewTreeObserver
import android.view.Window
import android.view.animation.AlphaAnimation
import android.view.inputmethod.InputMethodManager
import androidx.annotation.OptIn
import androidx.core.view.ViewCompat
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
Expand All @@ -21,6 +23,9 @@ import androidx.core.view.marginLeft
import androidx.core.view.marginRight
import androidx.core.view.marginTop
import androidx.core.view.updatePadding
import com.google.android.material.badge.BadgeDrawable
import com.google.android.material.badge.BadgeUtils
import com.google.android.material.badge.ExperimentalBadgeUtils
import com.skyd.anivu.R
import com.skyd.anivu.appContext

Expand Down Expand Up @@ -292,4 +297,17 @@ fun View.inSafeInset(displayCutout: DisplayCutout): Boolean {
if (overlapConsiderPaddingMargin(it)) return false
}
return true
}

@OptIn(ExperimentalBadgeUtils::class)
fun View.addBadge(init: BadgeDrawable.() -> Unit) {
viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
BadgeDrawable.create(context).apply {
this.init()
BadgeUtils.attachBadgeDrawable(this, this@addBadge)
}
viewTreeObserver.removeOnGlobalLayoutListener(this)
}
})
}
12 changes: 6 additions & 6 deletions app/src/main/java/com/skyd/anivu/model/db/dao/DownloadInfoDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface DownloadInfoDao {
fun updateDownloadInfoRequestId(
link: String,
downloadRequestId: String,
)
): Int

@Transaction
@Query(
Expand Down Expand Up @@ -78,7 +78,7 @@ interface DownloadInfoDao {
fun updateDownloadState(
link: String,
downloadState: DownloadInfoBean.DownloadState,
)
): Int

@Transaction
@Query(
Expand Down Expand Up @@ -124,7 +124,7 @@ interface DownloadInfoDao {
fun updateDownloadDescription(
link: String,
description: String?,
)
): Int

@Transaction
@Query(
Expand All @@ -148,7 +148,7 @@ interface DownloadInfoDao {
fun updateDownloadSize(
link: String,
size: Long,
)
): Int

@Transaction
@Query(
Expand All @@ -172,7 +172,7 @@ interface DownloadInfoDao {
fun updateDownloadProgress(
link: String,
progress: Float,
)
): Int

@Transaction
@Query(
Expand Down Expand Up @@ -207,7 +207,7 @@ interface DownloadInfoDao {
fun updateDownloadName(
link: String,
name: String,
)
): Int

@Transaction
@Query(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DownloadRepository @Inject constructor(
list.map { downloadInfoBean ->
downloadInfoBean.copy().apply {
peerInfoList = peerInfoMap.getOrDefault(downloadRequestId, emptyList()).toList()
val torrentStatus = uploadPayloadRateMap.get(downloadRequestId)
val torrentStatus = uploadPayloadRateMap[downloadRequestId]
if (torrentStatus != null) {
uploadPayloadRate = torrentStatus.uploadPayloadRate()
downloadPayloadRate = torrentStatus.downloadPayloadRate()
Expand Down
Loading

0 comments on commit 0dfe756

Please sign in to comment.