-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature|optimize] Support downloading or opening images in the brows…
…er from article content; support configuring player seek method; pptimize download page experience
- Loading branch information
Showing
21 changed files
with
361 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.skyd.anivu.ext | ||
|
||
import android.content.ContentValues | ||
import android.content.Context | ||
import android.graphics.Bitmap | ||
import android.graphics.drawable.BitmapDrawable | ||
import android.os.Environment | ||
import android.provider.MediaStore | ||
import kotlin.random.Random | ||
|
||
fun BitmapDrawable.saveToGallery( | ||
context: Context, | ||
filename: String = System.currentTimeMillis().toString() + "_" + Random.nextInt(), | ||
): Boolean { | ||
val contentResolver = context.contentResolver | ||
|
||
val values = ContentValues().apply { | ||
put(MediaStore.Images.Media.DISPLAY_NAME, "$filename.png") | ||
put(MediaStore.Images.Media.MIME_TYPE, "image/png") | ||
put( | ||
MediaStore.Images.Media.RELATIVE_PATH, | ||
Environment.DIRECTORY_PICTURES + "/" + context.getAppName() | ||
) | ||
} | ||
|
||
val uri = contentResolver | ||
.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values) ?: return false | ||
contentResolver.openOutputStream(uri)?.use { outputStream -> | ||
val out = bitmap?.compress(Bitmap.CompressFormat.PNG, 100, outputStream) | ||
return out == true | ||
} ?: return false | ||
} |
This file contains 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
This file contains 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
48 changes: 48 additions & 0 deletions
48
app/src/main/java/com/skyd/anivu/model/preference/player/PlayerSeekOptionPreference.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.skyd.anivu.model.preference.player | ||
|
||
import android.content.Context | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.stringPreferencesKey | ||
import com.skyd.anivu.R | ||
import com.skyd.anivu.base.BasePreference | ||
import com.skyd.anivu.ext.dataStore | ||
import com.skyd.anivu.ext.getOrDefault | ||
import com.skyd.anivu.ext.put | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
|
||
object PlayerSeekOptionPreference : BasePreference<String> { | ||
private const val PLAYER_SEEK_OPTION = "playerSeekOption" | ||
|
||
const val FAST = "Fast" | ||
const val EXACT = "Exact" | ||
|
||
val values = arrayOf(FAST, EXACT) | ||
|
||
override val default = FAST | ||
|
||
val key = stringPreferencesKey(PLAYER_SEEK_OPTION) | ||
|
||
fun put(context: Context, scope: CoroutineScope, value: String) { | ||
scope.launch(Dispatchers.IO) { | ||
context.dataStore.put(key, value) | ||
} | ||
} | ||
|
||
override fun fromPreferences(preferences: Preferences): String = preferences[key] ?: default | ||
|
||
fun isPrecise( | ||
context: Context, | ||
value: String = context.dataStore.getOrDefault(this), | ||
): Boolean = value == EXACT | ||
|
||
fun toDisplayName( | ||
context: Context, | ||
value: String = context.dataStore.getOrDefault(this), | ||
): String = when (value) { | ||
FAST -> context.getString(R.string.player_seek_fast) | ||
EXACT -> context.getString(R.string.player_seek_exact) | ||
else -> context.getString(R.string.unknown) | ||
} | ||
} |
This file contains 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
This file contains 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
34 changes: 34 additions & 0 deletions
34
app/src/main/java/com/skyd/anivu/ui/component/html/ImgTagHandler.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.skyd.anivu.ui.component.html | ||
|
||
import android.text.Editable | ||
import android.text.Html.TagHandler | ||
import android.text.Spanned | ||
import android.text.style.ClickableSpan | ||
import android.text.style.ImageSpan | ||
import android.view.View | ||
import org.xml.sax.XMLReader | ||
|
||
internal class ImgTagHandler(private val onClick: (String) -> Unit) : TagHandler { | ||
override fun handleTag(opening: Boolean, tag: String, output: Editable, xmlReader: XMLReader) { | ||
if (tag.equals("img", ignoreCase = true)) { | ||
val len = output.length | ||
val images = output.getSpans(0, len, ImageSpan::class.java) | ||
val imgURL = images.firstOrNull()?.source ?: return | ||
output.setSpan( | ||
ClickableImage(imgURL, onClick), | ||
0, | ||
len, | ||
Spanned.SPAN_INCLUSIVE_EXCLUSIVE, | ||
) | ||
} | ||
} | ||
} | ||
|
||
internal class ClickableImage( | ||
private val url: String, | ||
private val onClick: (String) -> Unit, | ||
) : ClickableSpan() { | ||
override fun onClick(widget: View) { | ||
onClick(url) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/skyd/anivu/ui/component/html/TagHandler.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.skyd.anivu.ui.component.html | ||
|
||
import android.text.Editable | ||
import android.text.Html.TagHandler | ||
import org.xml.sax.XMLReader | ||
|
||
internal class TagHandler(private val handlers: List<TagHandler>) : TagHandler { | ||
override fun handleTag(opening: Boolean, tag: String, output: Editable, xmlReader: XMLReader) { | ||
handlers.forEach { it.handleTag(opening, tag, output, xmlReader) } | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.