Skip to content

Commit

Permalink
21
Browse files Browse the repository at this point in the history
21
  • Loading branch information
umerov1999 committed Apr 16, 2023
1 parent 5d538ee commit 2815419
Show file tree
Hide file tree
Showing 65 changed files with 2,421 additions and 1,148 deletions.
3 changes: 0 additions & 3 deletions app_fenrir/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ android {
buildFeatures {
aidl = true
}
configurations {
compile.exclude module: 'support-v4'
}
packagingOptions {
exclude("META-INF/notice.txt")
exclude("META-INF/license.txt")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,25 @@ abstract class AbsAdapter<T>(name: String) : KSerializer<T> {
}
}

@JvmOverloads
fun optString(json: JsonObject?, names: List<String>, fallback: String? = null): String? {
contract {
returns(true) implies (json != null)
}
json ?: return fallback
for (i in names) {
try {
val element = json[i]
if (element is JsonPrimitive) return element.content else continue
} catch (e: Exception) {
if (Constants.IS_DEBUG) {
e.printStackTrace()
}
continue
}
}
return fallback
}

fun optBoolean(json: JsonObject?, name: String): Boolean {
contract {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class VideoDtoAdapter : AbsAdapter<VKApiVideo>("VKApiVideo") {
dto.mp4_1440 = optString(filesRoot, "mp4_1440")
dto.mp4_2160 = optString(filesRoot, "mp4_2160")
dto.external = optString(filesRoot, "external")
dto.hls = optString(filesRoot, "hls")
dto.hls = optString(filesRoot, listOf("hls", "hls_ondemand"))
dto.live = optString(filesRoot, "live")
}
val sz =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package dev.ragnarok.fenrir.fragment.base

import android.text.util.Linkify.EMAIL_ADDRESSES
import android.text.util.Linkify.PHONE_NUMBERS
import android.text.util.Linkify.WEB_URLS
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -75,7 +78,6 @@ class RecyclerMenuAdapter : RecyclerView.Adapter<MenuItemHolder> {
section != previous.section
}
}
holder.headerRoot.setOnClickListener { }
if (headerVisible) {
holder.headerRoot.visibility = View.VISIBLE
holder.headerText.text = section?.title?.getText(context)
Expand All @@ -93,6 +95,11 @@ class RecyclerMenuAdapter : RecyclerView.Adapter<MenuItemHolder> {
holder.itemTitle.text = item.title?.getText(context)
holder.itemSubtitle.visibility =
if (item.subtitle == null) View.GONE else View.VISIBLE
if (item.autolink) {
holder.itemSubtitle.autoLinkMask = WEB_URLS or EMAIL_ADDRESSES or PHONE_NUMBERS
} else {
holder.itemSubtitle.autoLinkMask = 0
}
holder.itemSubtitle.text = item.subtitle?.getText(context)
val last = position == itemCount - 1
val dividerVisible: Boolean = if (last) {
Expand All @@ -106,11 +113,8 @@ class RecyclerMenuAdapter : RecyclerView.Adapter<MenuItemHolder> {
actionListener?.onClick(item)
}
holder.itemRoot.setOnLongClickListener {
if (actionListener != null) {
actionListener?.onLongClick(item)
return@setOnLongClickListener true
}
false
actionListener?.onLongClick(item) ?: return@setOnLongClickListener false
true
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ class UserDetailsPresenter(
val domain =
if (user.domain.nonNullNoEmpty()) "@" + user.domain else "@" + user.getOwnerObjectId()
items.add(
AdvancedItem(1, AdvancedItem.TYPE_COPY_DETAILS_ONLY, Text(R.string.id))
AdvancedItem(
1, Text(R.string.id),
AdvancedItem.TYPE_COPY_DETAILS_ONLY,
autolink = false
)
.setSubtitle(Text(domain))
.setIcon(Icon.fromResources(R.drawable.person))
.setSection(mainSection)
Expand Down Expand Up @@ -125,7 +129,7 @@ class UserDetailsPresenter(
if (user.bdate.nonNullNoEmpty()) {
val formatted = getDateWithZeros(user.bdate)
items.add(
AdvancedItem(3, Text(R.string.birthday))
AdvancedItem(3, Text(R.string.birthday), autolink = false)
.setSubtitle(Text(formatted))
.setIcon(Icon.fromResources(R.drawable.cake))
.setSection(mainSection)
Expand Down Expand Up @@ -173,15 +177,15 @@ class UserDetailsPresenter(
}
if (details.getSkype().nonNullNoEmpty()) {
items.add(
AdvancedItem(9, AdvancedItem.TYPE_COPY_DETAILS_ONLY, Text(R.string.skype))
AdvancedItem(9, Text(R.string.skype), AdvancedItem.TYPE_COPY_DETAILS_ONLY)
.setSubtitle(Text(details.getSkype()))
.setIcon(R.drawable.ic_skype)
.setSection(mainSection)
)
}
if (details.getInstagram().nonNullNoEmpty()) {
items.add(
AdvancedItem(10, AdvancedItem.TYPE_OPEN_URL, Text(R.string.instagram))
AdvancedItem(10, Text(R.string.instagram), AdvancedItem.TYPE_OPEN_URL)
.setSubtitle(Text(details.getInstagram()))
.setUrlPrefix("https://www.instagram.com")
.setIcon(R.drawable.instagram)
Expand All @@ -190,7 +194,7 @@ class UserDetailsPresenter(
}
if (details.getTwitter().nonNullNoEmpty()) {
items.add(
AdvancedItem(11, AdvancedItem.TYPE_OPEN_URL, Text(R.string.twitter))
AdvancedItem(11, Text(R.string.twitter), AdvancedItem.TYPE_OPEN_URL)
.setSubtitle(Text(details.getTwitter()))
.setIcon(R.drawable.twitter)
.setUrlPrefix("https://mobile.twitter.com")
Expand All @@ -199,7 +203,7 @@ class UserDetailsPresenter(
}
if (details.getFacebook().nonNullNoEmpty()) {
items.add(
AdvancedItem(12, AdvancedItem.TYPE_OPEN_URL, Text(R.string.facebook))
AdvancedItem(12, Text(R.string.facebook), AdvancedItem.TYPE_OPEN_URL)
.setSubtitle(Text(details.getFacebook()))
.setIcon(R.drawable.facebook)
.setUrlPrefix("https://m.facebook.com")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import androidx.annotation.DrawableRes
import dev.ragnarok.fenrir.model.Icon
import dev.ragnarok.fenrir.model.Text

class AdvancedItem(val key: Long, val type: Int, val title: Text?) {
class AdvancedItem(
val key: Long,
val title: Text?,
val type: Int = TYPE_DEFAULT,
val autolink: Boolean = true
) {
var urlPrefix: String? = null
private set
var icon: Icon? = null
Expand All @@ -16,8 +21,6 @@ class AdvancedItem(val key: Long, val type: Int, val title: Text?) {
var tag: Any? = null
private set

constructor(key: Long, title: Text?) : this(key, TYPE_DEFAULT, title)

fun setUrlPrefix(urlPrefix: String?): AdvancedItem {
this.urlPrefix = urlPrefix
return this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ open class TouchImageView @JvmOverloads constructor(

public override fun onSaveInstanceState(): Parcelable? {
val bundle = Bundle()
bundle.putParcelable("instanceState", super.onSaveInstanceState())
bundle.putParcelable(STATE, super.onSaveInstanceState())
bundle.putInt("orientation", orientation)
bundle.putFloat("saveScale", currentZoom)
bundle.putFloat("matchViewHeight", matchViewHeight)
Expand Down Expand Up @@ -430,7 +430,7 @@ open class TouchImageView @JvmOverloads constructor(
if (orientation != oldOrientation) {
orientationJustChanged = true
}
super.onRestoreInstanceState(state.getParcelableCompat("instanceState"))
super.onRestoreInstanceState(state.getParcelableCompat(STATE))
return
}
super.onRestoreInstanceState(state)
Expand Down Expand Up @@ -574,10 +574,8 @@ open class TouchImageView @JvmOverloads constructor(
resetZoom()
scaleImage(scale.toDouble(), viewWidth / 2.toFloat(), viewHeight / 2.toFloat(), true)
touchMatrix.getValues(floatMatrix)
floatMatrix[Matrix.MTRANS_X] =
(viewWidth - matchViewWidth) / 2 - focusX * (scale - 1) * matchViewWidth
floatMatrix[Matrix.MTRANS_Y] =
(viewHeight - matchViewHeight) / 2 - focusY * (scale - 1) * matchViewHeight
floatMatrix[Matrix.MTRANS_X] = -(focusX * imageWidth - viewWidth * 0.5f)
floatMatrix[Matrix.MTRANS_Y] = -(focusY * imageHeight - viewHeight * 0.5f)
touchMatrix.setValues(floatMatrix)
fixTrans()
savePreviousImageValues()
Expand Down Expand Up @@ -784,6 +782,10 @@ open class TouchImageView @JvmOverloads constructor(
if (drawable == null || drawable.intrinsicWidth == 0 || drawable.intrinsicHeight == 0) {
return
}
@Suppress("SENSELESS_COMPARISON")
if (touchMatrix == null || prevMatrix == null) {
return
}
if (userSpecifiedMinScale == AUTOMATIC_MIN_ZOOM) {
minZoom = AUTOMATIC_MIN_ZOOM
if (currentZoom < minScale) {
Expand Down Expand Up @@ -1548,6 +1550,8 @@ open class TouchImageView @JvmOverloads constructor(
}

companion object {
private const val STATE = "instanceState"

// SuperMin and SuperMax multipliers. Determine how much the image can be zoomed below or above the zoom boundaries,
// before animating back to the min/max zoom boundary.
private const val SUPER_MIN_MULTIPLIER = .75f
Expand Down
1 change: 0 additions & 1 deletion app_fenrir/src/main/res/layout/item_advanced_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
android:id="@+id/item_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="all"
android:textAppearance="@style/TextAppearance.Material3.TitleSmall"
tools:text="Example" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
android:id="@+id/item_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="all"
android:textAppearance="@style/TextAppearance.Material3.TitleSmall"
tools:text="Example" />

Expand Down
3 changes: 0 additions & 3 deletions app_filegallery/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ android {
buildFeatures {
aidl = true
}
configurations {
compile.exclude module: 'support-v4'
}
packagingOptions {
exclude("META-INF/notice.txt")
exclude("META-INF/license.txt")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,25 @@ abstract class AbsAdapter<T>(name: String) : KSerializer<T> {
}
}

@JvmOverloads
fun optString(json: JsonObject?, names: List<String>, fallback: String? = null): String? {
contract {
returns(true) implies (json != null)
}
json ?: return fallback
for (i in names) {
try {
val element = json[i]
if (element is JsonPrimitive) return element.content else continue
} catch (e: Exception) {
if (Constants.IS_DEBUG) {
e.printStackTrace()
}
continue
}
}
return fallback
}

fun optBoolean(json: JsonObject?, name: String): Boolean {
contract {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ open class TouchImageView @JvmOverloads constructor(

public override fun onSaveInstanceState(): Parcelable? {
val bundle = Bundle()
bundle.putParcelable("instanceState", super.onSaveInstanceState())
bundle.putParcelable(STATE, super.onSaveInstanceState())
bundle.putInt("orientation", orientation)
bundle.putFloat("saveScale", currentZoom)
bundle.putFloat("matchViewHeight", matchViewHeight)
Expand Down Expand Up @@ -343,7 +343,7 @@ open class TouchImageView @JvmOverloads constructor(
if (orientation != oldOrientation) {
orientationJustChanged = true
}
super.onRestoreInstanceState(state.getParcelableCompat("instanceState"))
super.onRestoreInstanceState(state.getParcelableCompat(STATE))
return
}
super.onRestoreInstanceState(state)
Expand Down Expand Up @@ -487,10 +487,8 @@ open class TouchImageView @JvmOverloads constructor(
resetZoom()
scaleImage(scale.toDouble(), viewWidth / 2.toFloat(), viewHeight / 2.toFloat(), true)
touchMatrix.getValues(floatMatrix)
floatMatrix[Matrix.MTRANS_X] =
(viewWidth - matchViewWidth) / 2 - focusX * (scale - 1) * matchViewWidth
floatMatrix[Matrix.MTRANS_Y] =
(viewHeight - matchViewHeight) / 2 - focusY * (scale - 1) * matchViewHeight
floatMatrix[Matrix.MTRANS_X] = -(focusX * imageWidth - viewWidth * 0.5f)
floatMatrix[Matrix.MTRANS_Y] = -(focusY * imageHeight - viewHeight * 0.5f)
touchMatrix.setValues(floatMatrix)
fixTrans()
savePreviousImageValues()
Expand Down Expand Up @@ -697,6 +695,10 @@ open class TouchImageView @JvmOverloads constructor(
if (drawable == null || drawable.intrinsicWidth == 0 || drawable.intrinsicHeight == 0) {
return
}
@Suppress("SENSELESS_COMPARISON")
if (touchMatrix == null || prevMatrix == null) {
return
}
if (userSpecifiedMinScale == AUTOMATIC_MIN_ZOOM) {
minZoom = AUTOMATIC_MIN_ZOOM
if (currentZoom < minScale) {
Expand Down Expand Up @@ -1461,6 +1463,8 @@ open class TouchImageView @JvmOverloads constructor(
}

companion object {
private const val STATE = "instanceState"

// SuperMin and SuperMax multipliers. Determine how much the image can be zoomed below or above the zoom boundaries,
// before animating back to the min/max zoom boundary.
private const val SUPER_MIN_MULTIPLIER = .75f
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:8.0.0-rc01"
classpath "com.android.tools.build:gradle:8.0.0"
classpath "com.google.gms:google-services:4.3.15"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ android.useAndroidX=true
kotlin.code.style=official
android.nonTransitiveRClass=true
org.gradle.warning.mode=all
android.defaults.buildfeatures.buildconfig=true
android.defaults.buildfeatures.buildconfig=true
android.enableJetifier=true
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Aug 17 12:17:04 MSK 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
19 changes: 19 additions & 0 deletions libfenrir/src/main/java/com/github/luben/zstd/Zstd.java
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,25 @@ public static long decompressedDirectByteBufferSize(ByteBuffer src, int srcPosit
*/
public static native long getDictIdFromDict(byte[] dict);

private static native long getDictIdFromDictDirect(ByteBuffer dict, int offset, int length);

/**
* Get DictId of a dictionary
*
* @param dict dictionary as Direct ByteBuffer
* @return DictId or 0 if not available
*/
public static long getDictIdFromDictDirect(ByteBuffer dict) {
int length = dict.limit() - dict.position();
if (!dict.isDirect()) {
throw new IllegalArgumentException("dict must be a direct buffer");
}
if (length < 0) {
throw new IllegalArgumentException("dict cannot be empty.");
}
return getDictIdFromDictDirect(dict, dict.position(), length);
}

/* Stub methods for backward comatibility
*/

Expand Down
Loading

0 comments on commit 2815419

Please sign in to comment.