Skip to content

Commit

Permalink
9
Browse files Browse the repository at this point in the history
9
  • Loading branch information
umerov1999 committed Jan 31, 2023
1 parent 87297f9 commit 3e21acc
Show file tree
Hide file tree
Showing 882 changed files with 16,739 additions and 4,259 deletions.
4 changes: 4 additions & 0 deletions app_fenrir/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ plugins {

android {
namespace "dev.ragnarok.fenrir"
buildFeatures {
aidl = true
}
configurations {
compile.exclude module: 'support-v4'
}
Expand Down Expand Up @@ -40,6 +43,7 @@ android {
buildConfigField("boolean", "FORCE_DEVELOPER_MODE", is_developer_build ? "true" : "false")

ndk {
//noinspection ChromeOsAbiSupport
abiFilters = targetAbi
}
resConfigs "en", "ru", "be"
Expand Down
78 changes: 32 additions & 46 deletions app_fenrir/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<uses-feature
android:name="android.hardware.microphone"
android:required="false" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-feature
android:name="android.hardware.camera2"
android:required="false" />
Expand Down Expand Up @@ -54,10 +57,7 @@
<application
android:name="dev.ragnarok.fenrir.App"
android:allowAudioPlaybackCapture="true"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:enableOnBackInvokedCallback="true"
android:fullBackupContent="true"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand Down Expand Up @@ -361,30 +361,12 @@
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="vk.com"
android:scheme="http" />
<data
android:host="vk.com"
android:scheme="https" />
<data
android:host="vk.cc"
android:scheme="http" />
<data
android:host="vk.cc"
android:scheme="https" />
<data
android:host="vk.me"
android:scheme="http" />
<data
android:host="vk.me"
android:scheme="https" />
<data
android:host="m.vk.com"
android:scheme="http" />
<data
android:host="m.vk.com"
android:scheme="https" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="vk.com" />
<data android:host="vk.cc" />
<data android:host="vk.me" />
<data android:host="m.vk.com" />
</intent-filter>
</activity>

Expand Down Expand Up @@ -428,7 +410,11 @@
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />

<data android:mimeType="image/*" />
<data android:host="*" />
<data android:scheme="file" />
<data android:scheme="content" />
</intent-filter>
</activity>

Expand All @@ -453,13 +439,13 @@
<data android:scheme="file" />
<data android:scheme="content" />

<data android:mimeType="application/javascript" />
<data android:mimeType="application/json" />
<data android:mimeType="application/typescript" />
<data android:mimeType="application/x-sh" />
<data android:mimeType="application/x-shellscript" />
<data android:mimeType="application/xml" />
<data android:mimeType="text/*" />
<data android:mimeType="application/x-javascript" />
<data android:mimeType="text/javascript" />
<data android:mimeType="text/x-javascript" />
<data android:mimeType="text/x-json" />
<data android:mimeType="text/json" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>

Expand All @@ -480,13 +466,13 @@
<data android:scheme="file" />
<data android:scheme="content" />

<data android:mimeType="application/javascript" />
<data android:mimeType="application/json" />
<data android:mimeType="application/typescript" />
<data android:mimeType="application/x-sh" />
<data android:mimeType="application/x-shellscript" />
<data android:mimeType="application/xml" />
<data android:mimeType="text/*" />
<data android:mimeType="application/x-javascript" />
<data android:mimeType="text/javascript" />
<data android:mimeType="text/x-javascript" />
<data android:mimeType="text/x-json" />
<data android:mimeType="text/json" />
<data android:mimeType="text/plain" />
</intent-filter>

</activity>
Expand Down Expand Up @@ -560,13 +546,14 @@
<data android:host="*" />
<data android:scheme="file" />
<data android:scheme="content" />
<data android:mimeType="application/javascript" />

<data android:mimeType="application/json" />
<data android:mimeType="application/typescript" />
<data android:mimeType="application/x-sh" />
<data android:mimeType="application/x-shellscript" />
<data android:mimeType="application/xml" />
<data android:mimeType="text/*" />
<data android:mimeType="application/x-javascript" />
<data android:mimeType="text/javascript" />
<data android:mimeType="text/x-javascript" />
<data android:mimeType="text/x-json" />
<data android:mimeType="text/json" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>

Expand All @@ -577,7 +564,6 @@
<activity
android:name="dev.ragnarok.fenrir.activity.VideoPlayerActivity"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
android:label="@string/app_name"
android:launchMode="singleTask"
android:resizeableActivity="true"
android:supportsPictureInPicture="true"
Expand Down
4 changes: 2 additions & 2 deletions app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/AccountType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dev.ragnarok.fenrir
import androidx.annotation.IntDef

@IntDef(
AccountType.BY_TYPE,
AccountType.NULL,
AccountType.VK_ANDROID,
AccountType.VK_ANDROID_HIDDEN,
AccountType.KATE,
Expand All @@ -24,7 +24,7 @@ annotation class AccountType {
}
}

const val BY_TYPE = 0
const val NULL = 0
const val VK_ANDROID = 1
const val VK_ANDROID_HIDDEN = 2
const val KATE = 3
Expand Down
129 changes: 0 additions & 129 deletions app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/Constants.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package dev.ragnarok.fenrir

import android.content.res.Resources
import android.os.Build
import dev.ragnarok.fenrir.settings.ISettings
import dev.ragnarok.fenrir.settings.Settings
import dev.ragnarok.fenrir.util.Utils
import java.util.*

object Constants {
Expand Down Expand Up @@ -37,134 +33,9 @@ object Constants {

var DEVICE_COUNTRY_CODE = "ru"

val KATE_USER_AGENT
get() = String.format(
Locale.US,
"KateMobileAndroid/%s-%s (Android %s; SDK %d; %s; %s; %s; %s)",
KATE_APP_VERSION_NAME,
KATE_APP_VERSION_CODE,
Build.VERSION.RELEASE,
Build.VERSION.SDK_INT,
Build.SUPPORTED_ABIS[0],
Utils.deviceName,
DEVICE_COUNTRY_CODE,
SCREEN_RESOLUTION
)

private val KATE_USER_AGENT_FAKE
get() = String.format(
Locale.US,
"KateMobileAndroid/%s-%s (Android %s; SDK %d; %s; %s; %s; %s)",
KATE_APP_VERSION_NAME,
KATE_APP_VERSION_CODE,
Build.VERSION.RELEASE,
Build.VERSION.SDK_INT,
BuildConfig.FAKE_ABI,
BuildConfig.FAKE_DEVICE,
DEVICE_COUNTRY_CODE,
SCREEN_RESOLUTION
)
private val VK_ANDROID_USER_AGENT
get() = String.format(
Locale.US,
"VKAndroidApp/%s-%s (Android %s; SDK %d; %s; %s; %s; %s)",
VK_ANDROID_APP_VERSION_NAME,
VK_ANDROID_APP_VERSION_CODE,
Build.VERSION.RELEASE,
Build.VERSION.SDK_INT,
Build.SUPPORTED_ABIS[0],
Utils.deviceName,
DEVICE_COUNTRY_CODE,
SCREEN_RESOLUTION
)
private val VK_ANDROID_USER_AGENT_FAKE
get() = String.format(
Locale.US,
"VKAndroidApp/%s-%s (Android %s; SDK %d; %s; %s; %s; %s)",
VK_ANDROID_APP_VERSION_NAME,
VK_ANDROID_APP_VERSION_CODE,
Build.VERSION.RELEASE,
Build.VERSION.SDK_INT,
BuildConfig.FAKE_ABI,
BuildConfig.FAKE_DEVICE,
DEVICE_COUNTRY_CODE,
SCREEN_RESOLUTION
)

private val SCREEN_RESOLUTION
get() = Resources.getSystem().displayMetrics?.let {
it.heightPixels.toString() + "x" + it.widthPixels
} ?: "1920x1080"

val SCREEN_WIDTH
get() = Resources.getSystem().displayMetrics?.widthPixels ?: 1920

val SCREEN_HEIGHT
get() = Resources.getSystem().displayMetrics?.heightPixels ?: 1080

private fun getTypedUserAgent(@AccountType type: Int): String {
if (type == AccountType.VK_ANDROID_HIDDEN || type == AccountType.KATE_HIDDEN) {
val device = Settings.get().accounts().getDevice(Settings.get().accounts().current)
if (device.nonNullNoEmpty()) {
return if (type == AccountType.KATE_HIDDEN) String.format(
Locale.US,
"KateMobileAndroid/%s-%s (Android %s; SDK %d; %s; %s; %s; %s)",
KATE_APP_VERSION_NAME,
KATE_APP_VERSION_CODE,
Build.VERSION.RELEASE,
Build.VERSION.SDK_INT,
BuildConfig.FAKE_ABI,
device,
DEVICE_COUNTRY_CODE,
SCREEN_RESOLUTION
) else String.format(
Locale.US,
"VKAndroidApp/%s-%s (Android %s; SDK %d; %s; %s; %s; %s)",
VK_ANDROID_APP_VERSION_NAME,
VK_ANDROID_APP_VERSION_CODE,
Build.VERSION.RELEASE,
Build.VERSION.SDK_INT,
BuildConfig.FAKE_ABI,
device,
DEVICE_COUNTRY_CODE,
SCREEN_RESOLUTION
)
}
}
when (type) {
AccountType.BY_TYPE, AccountType.VK_ANDROID -> return VK_ANDROID_USER_AGENT
AccountType.VK_ANDROID_HIDDEN -> return VK_ANDROID_USER_AGENT_FAKE
AccountType.KATE -> return KATE_USER_AGENT
AccountType.KATE_HIDDEN -> return KATE_USER_AGENT_FAKE
}
return Utils.BY_DEFAULT_ACCOUNT_TYPE(VK_ANDROID_USER_AGENT, KATE_USER_AGENT)
}

val USER_AGENT_ACCOUNT
get() = Settings.get().accounts().current.let {
if (it == ISettings.IAccountsSettings.INVALID_ID) {
Utils.BY_DEFAULT_ACCOUNT_TYPE(
VK_ANDROID_USER_AGENT,
KATE_USER_AGENT
)
} else getTypedUserAgent(
Settings.get().accounts().getType(it)
)
}


fun USER_AGENT(@AccountType type: Int): String {
if (type != AccountType.BY_TYPE) {
return getTypedUserAgent(type)
}
val accountId = Settings.get().accounts().current
return if (accountId == ISettings.IAccountsSettings.INVALID_ID) {
Utils.BY_DEFAULT_ACCOUNT_TYPE(
VK_ANDROID_USER_AGENT,
KATE_USER_AGENT
)
} else getTypedUserAgent(
Settings.get().accounts().getType(accountId)
)
}
}
14 changes: 9 additions & 5 deletions app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ inline fun <reified T> Collection<T>?.nonNullNoEmpty(): Boolean {
contract {
returns(true) implies (this@nonNullNoEmpty != null)
}
return this != null && !this.isEmpty()
return !this.isNullOrEmpty()
}

inline fun <reified T : CharSequence> T?.nonNullNoEmpty(): Boolean {
contract {
returns(true) implies (this@nonNullNoEmpty != null)
}
return this != null && this.isNotEmpty()
return !this.isNullOrEmpty()
}

inline fun <reified T : CharSequence> T?.ifNonNullNoEmpty(yes: (T) -> Unit, no: () -> Unit) {
Expand Down Expand Up @@ -142,7 +142,7 @@ inline fun <reified T> Array<T>?.nonNullNoEmpty(): Boolean {
contract {
returns(true) implies (this@nonNullNoEmpty != null)
}
return this != null && this.isNotEmpty()
return !this.isNullOrEmpty()
}

fun ByteArray?.nonNullNoEmpty(): Boolean {
Expand Down Expand Up @@ -184,7 +184,7 @@ inline fun <reified T> Array<T>?.nullOrEmpty(): Boolean {
contract {
returns(false) implies (this@nullOrEmpty != null)
}
return this == null || this.isEmpty()
return this.isNullOrEmpty()
}

fun ByteArray?.nullOrEmpty(): Boolean {
Expand Down Expand Up @@ -266,7 +266,7 @@ inline fun IntArray?.nonNullNoEmpty(block: (IntArray) -> Unit) {
}

inline fun <reified T> Array<T>?.nonNullNoEmpty(block: (Array<T>) -> Unit) {
if (this != null && this.isNotEmpty()) apply(block)
if (!this.isNullOrEmpty()) apply(block)
}

inline fun DoubleArray?.nonNullNoEmpty(block: (DoubleArray) -> Unit) {
Expand Down Expand Up @@ -444,6 +444,10 @@ fun ResponseBody.isMsgPack(): Boolean {
return contentType()?.toString()?.contains("msgpack") == true
}

fun ResponseBody.isJson(): Boolean {
return contentType()?.toString()?.contains("json") == true
}

inline fun <reified T : Parcelable> Parcel.readTypedObjectCompat(c: Parcelable.Creator<T>): T? {
return if (readInt() != 0) {
c.createFromParcel(this)
Expand Down
Loading

0 comments on commit 3e21acc

Please sign in to comment.