Skip to content

Commit

Permalink
2. Last Retrofit
Browse files Browse the repository at this point in the history
2. Last Retrofit
  • Loading branch information
umerov1999 committed Dec 30, 2022
1 parent e78cbb6 commit c854d8d
Show file tree
Hide file tree
Showing 537 changed files with 26,079 additions and 5,432 deletions.
2 changes: 0 additions & 2 deletions app_fenrir/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ android {
buildConfigField("String", "SERVICE_TOKEN", asStringVar(vk_service_token))
buildConfigField("String", "FAKE_ABI", asStringVar(fake_abi))
buildConfigField("String", "FAKE_DEVICE", asStringVar(fake_device))
buildConfigField("String", "FCM_SESSION_ID_GEN_URL", asStringVar(fcm_session_id_gen_url))
buildConfigField("boolean", "MANAGE_SCOPED_STORAGE", "true")
buildConfigField("boolean", "FORCE_DEVELOPER_MODE", is_developer_build ? "true" : "false")

Expand Down Expand Up @@ -128,7 +127,6 @@ dependencies {
implementation("androidx.webkit:webkit:$webkitVersion")
implementation("androidx.exifinterface:exifinterface:$exifinterfaceVersion")
implementation("io.reactivex.rxjava3:rxjava:$rxJavaVersion")
implementation("com.google.firebase:firebase-database:$firebaseDatabaseVersion")
implementation("com.google.firebase:firebase-datatransport:$firebaseDatatransportVersion")
implementation("com.google.firebase:firebase-messaging:$firebaseMessagingVersion") {
exclude group: "com.google.firebase", module: "firebase-installations"
Expand Down
9 changes: 4 additions & 5 deletions app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ object Constants {

@AccountType
val DEFAULT_ACCOUNT_TYPE: Int = AccountType.toAccountType(BuildConfig.DEFAULT_ACCOUNT_TYPE)
const val FCM_SESSION_ID_GEN_URL: String = BuildConfig.FCM_SESSION_ID_GEN_URL

val AUTH_VERSION = if (DEFAULT_ACCOUNT_TYPE == AccountType.KATE) API_VERSION else "5.122"
const val FILE_PROVIDER_AUTHORITY: String = BuildConfig.APPLICATION_ID + ".file_provider"
const val VK_ANDROID_APP_VERSION_NAME = "8.8"
const val VK_ANDROID_APP_VERSION_CODE = "14796"
const val KATE_APP_VERSION_NAME = "95 lite"
const val KATE_APP_VERSION_CODE = "528"
const val VK_ANDROID_APP_VERSION_NAME = "8.11"
const val VK_ANDROID_APP_VERSION_CODE = "15026"
const val KATE_APP_VERSION_NAME = "96 lite"
const val KATE_APP_VERSION_CODE = "529"
const val API_ID: Int = BuildConfig.VK_API_APP_ID
const val SECRET: String = BuildConfig.VK_CLIENT_SECRET
const val MAIN_OWNER_FIELDS = UserColumns.API_FIELDS + "," + GroupColumns.API_FIELDS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import dev.ragnarok.fenrir.util.toast.CustomToast
import io.reactivex.rxjava3.disposables.Disposable
import java.io.File
import java.io.FileOutputStream
import java.nio.charset.StandardCharsets
import java.text.DateFormat
import java.text.SimpleDateFormat

Expand Down Expand Up @@ -126,7 +125,7 @@ class DeltaOwnerActivity : AppCompatActivity(), PlaceProvider, AppStyleable {
DeltaOwner.serializer(),
delta
).toByteArray(
StandardCharsets.UTF_8
Charsets.UTF_8
)
out = FileOutputStream(file)
val bom = byteArrayOf(0xEF.toByte(), 0xBB.toByte(), 0xBF.toByte())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ import dev.ragnarok.fenrir.model.drawer.AbsMenuItem
import dev.ragnarok.fenrir.model.drawer.RecentChat
import dev.ragnarok.fenrir.model.drawer.SectionMenuItem
import dev.ragnarok.fenrir.module.FenrirNative
import dev.ragnarok.fenrir.module.thorvg.ThorVGRender
import dev.ragnarok.fenrir.place.Place
import dev.ragnarok.fenrir.place.PlaceFactory
import dev.ragnarok.fenrir.place.PlaceProvider
Expand Down Expand Up @@ -322,6 +323,19 @@ open class MainActivity : AppCompatActivity(), NavigationDrawerCallbacks, OnSect
}
setTheme(currentStyle())
Utils.prepareDensity(this)

if (FenrirNative.isNativeLoaded && getMainActivityTransform() == MainActivityTransforms.MAIN) {
ThorVGRender.registerColors(
mapOf(
"primary_color" to CurrentTheme.getColorPrimary(this),
"secondary_color" to CurrentTheme.getColorSecondary(this),
"on_surface_color" to CurrentTheme.getColorOnSurface(this),
"white_color_contrast_fix" to CurrentTheme.getColorWhiteContrastFix(this),
"black_color_contrast_fix" to CurrentTheme.getColorBlackContrastFix(this)
)
)
}

super.onCreate(savedInstanceState)
isActivityDestroyed = false
isZoomPhoto = Settings.get().other().isDo_zoom_photo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ abstract class AbsVkApiInterceptor(private val version: String) :
}
return chain.proceed(
original.newBuilder()
.method("POST", formBuilder.build())
.post(formBuilder.build())
.build()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ class OtherVkRetrofitProvider @SuppressLint("CheckResult") constructor(private v
override fun provideAuthRetrofit(): Single<RetrofitWrapper> {
return Single.fromCallable {
val builder: OkHttpClient.Builder = OkHttpClient.Builder()
.readTimeout(30, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS)
.connectTimeout(15, TimeUnit.SECONDS)
.writeTimeout(15, TimeUnit.SECONDS)
.callTimeout(15, TimeUnit.SECONDS)
.addInterceptor(Interceptor { chain: Interceptor.Chain ->
val request =
chain.toRequestBuilder(false).vkHeader(true)
Expand Down Expand Up @@ -75,7 +78,10 @@ class OtherVkRetrofitProvider @SuppressLint("CheckResult") constructor(private v
override fun provideAuthServiceRetrofit(): Single<RetrofitWrapper> {
return Single.fromCallable {
val builder: OkHttpClient.Builder = OkHttpClient.Builder()
.readTimeout(30, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS)
.connectTimeout(15, TimeUnit.SECONDS)
.writeTimeout(15, TimeUnit.SECONDS)
.callTimeout(15, TimeUnit.SECONDS)
.addInterceptor(Interceptor { chain: Interceptor.Chain ->
val request =
chain.toRequestBuilder(false).vkHeader(true)
Expand Down Expand Up @@ -103,7 +109,10 @@ class OtherVkRetrofitProvider @SuppressLint("CheckResult") constructor(private v
private fun createLocalServerRetrofit(): Retrofit {
val localSettings = Settings.get().other().localServer
val builder: OkHttpClient.Builder = OkHttpClient.Builder()
.readTimeout(30, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS)
.connectTimeout(15, TimeUnit.SECONDS)
.writeTimeout(15, TimeUnit.SECONDS)
.callTimeout(15, TimeUnit.SECONDS)
.addInterceptor(Interceptor { chain: Interceptor.Chain ->
val request =
chain.toRequestBuilder(false).vkHeader(false).addHeader(
Expand All @@ -125,7 +134,7 @@ class OtherVkRetrofitProvider @SuppressLint("CheckResult") constructor(private v
formBuilder.add("password", it)
}
val request = original.newBuilder()
.method("POST", formBuilder.build())
.post(formBuilder.build())
.build()
chain.proceed(request)
}).addInterceptor(UncompressDefaultInterceptor)
Expand All @@ -144,7 +153,10 @@ class OtherVkRetrofitProvider @SuppressLint("CheckResult") constructor(private v

private fun createLongpollRetrofitInstance(): Retrofit {
val builder: OkHttpClient.Builder = OkHttpClient.Builder()
.readTimeout(30, TimeUnit.SECONDS)
.readTimeout(25, TimeUnit.SECONDS)
.connectTimeout(25, TimeUnit.SECONDS)
.writeTimeout(25, TimeUnit.SECONDS)
.callTimeout(25, TimeUnit.SECONDS)
.addInterceptor(Interceptor { chain: Interceptor.Chain ->
val request =
chain.toRequestBuilder(false).vkHeader(true).addHeader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ class UploadRetrofitProvider(private val proxySettings: IProxySettings) : IUploa

private fun createUploadRetrofit(): Retrofit {
val builder: OkHttpClient.Builder = OkHttpClient.Builder()
.readTimeout(40, TimeUnit.SECONDS)
.connectTimeout(40, TimeUnit.SECONDS)
.writeTimeout(40, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS)
.connectTimeout(15, TimeUnit.SECONDS)
.writeTimeout(15, TimeUnit.SECONDS)
.callTimeout(15, TimeUnit.SECONDS)
.addInterceptor(Interceptor { chain: Interceptor.Chain ->
val request =
chain.toRequestBuilder(false).vkHeader(true).addHeader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ class VkMethodHttpClientFactory : IVkMethodHttpClientFactory {
): OkHttpClient {
val builder: OkHttpClient.Builder = OkHttpClient.Builder()
.addInterceptor(interceptor)
.readTimeout(40, TimeUnit.SECONDS)
.connectTimeout(40, TimeUnit.SECONDS)
.writeTimeout(40, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS)
.connectTimeout(15, TimeUnit.SECONDS)
.writeTimeout(15, TimeUnit.SECONDS)
.callTimeout(15, TimeUnit.SECONDS)
.addInterceptor(Interceptor { chain: Interceptor.Chain ->
val request = chain.toRequestBuilder(true).vkHeader(false)
.addHeader("User-Agent", Constants.USER_AGENT(interceptor.type)).build()
Expand All @@ -75,9 +76,10 @@ class VkMethodHttpClientFactory : IVkMethodHttpClientFactory {
config: ProxyConfig?
): OkHttpClient {
val builder: OkHttpClient.Builder = OkHttpClient.Builder()
.readTimeout(40, TimeUnit.SECONDS)
.connectTimeout(40, TimeUnit.SECONDS)
.writeTimeout(40, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS)
.connectTimeout(15, TimeUnit.SECONDS)
.writeTimeout(15, TimeUnit.SECONDS)
.callTimeout(15, TimeUnit.SECONDS)
.addInterceptor(Interceptor { chain: Interceptor.Chain ->
val request = chain.toRequestBuilder(true).vkHeader(false)
.addHeader("User-Agent", Constants.USER_AGENT(type)).build()
Expand Down
38 changes: 21 additions & 17 deletions app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/impl/AbsApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import dev.ragnarok.fenrir.settings.Settings
import dev.ragnarok.fenrir.util.refresh.RefreshToken
import dev.ragnarok.fenrir.util.serializeble.json.decodeFromStream
import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPack
import dev.ragnarok.fenrir.util.serializeble.retrofit.HttpCodeException
import dev.ragnarok.fenrir.util.serializeble.retrofit.kotlinx.serialization.Serializer
import io.reactivex.rxjava3.core.Completable
import io.reactivex.rxjava3.core.Single
import io.reactivex.rxjava3.core.SingleEmitter
import io.reactivex.rxjava3.exceptions.Exceptions
import io.reactivex.rxjava3.functions.Function
import okhttp3.*
import java.io.IOException
import java.lang.reflect.Type
import java.util.*

Expand Down Expand Up @@ -51,19 +51,21 @@ internal open class AbsApi(val accountId: Int, private val retrofitProvider: ISe
.url(
method
)
.method("POST", bodyBuilder.build())
.post(bodyBuilder.build())
.build()
val call = client.newCall(request)
emitter.setCancellable { call.cancel() }
call.enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
emitter.onError(e)
}

override fun onResponse(call: Call, response: Response) {
try {
val response = call.execute()
if (!response.isSuccessful) {
emitter.onError(HttpCodeException(response.code))
} else {
emitter.onSuccess(response)
}
})
response.close()
} catch (e: Exception) {
emitter.onError(e)
}
}
}
.map { response ->
Expand Down Expand Up @@ -112,19 +114,21 @@ internal open class AbsApi(val accountId: Int, private val retrofitProvider: ISe
.url(
method
)
.method("POST", bodyBuilder.build())
.post(bodyBuilder.build())
.build()
val call = client.newCall(request)
emitter.setCancellable { call.cancel() }
call.enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
emitter.onError(e)
}

override fun onResponse(call: Call, response: Response) {
try {
val response = call.execute()
if (!response.isSuccessful) {
emitter.onError(HttpCodeException(response.code))
} else {
emitter.onSuccess(response)
}
})
response.close()
} catch (e: Exception) {
emitter.onError(e)
}
}
}
.map {
Expand Down
25 changes: 15 additions & 10 deletions app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/impl/OtherApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import dev.ragnarok.fenrir.api.interfaces.IOtherApi
import dev.ragnarok.fenrir.settings.Settings
import dev.ragnarok.fenrir.util.Optional
import dev.ragnarok.fenrir.util.Optional.Companion.wrap
import dev.ragnarok.fenrir.util.serializeble.retrofit.HttpCodeException
import io.reactivex.rxjava3.core.Single
import io.reactivex.rxjava3.core.SingleEmitter
import okhttp3.*
import java.io.IOException
import okhttp3.FormBody
import okhttp3.Request
import okhttp3.Response
import okhttp3.ResponseBody

class OtherApi(private val accountId: Int, private val provider: IVkRetrofitProvider) : IOtherApi {
override fun rawRequest(
Expand All @@ -28,19 +31,21 @@ class OtherApi(private val accountId: Int, private val provider: IVkRetrofitProv
"https://" + Settings.get()
.other().get_Api_Domain() + "/method/" + method
)
.method("POST", bodyBuilder.build())
.post(bodyBuilder.build())
.build()
val call = client.newCall(request)
emitter.setCancellable { call.cancel() }
call.enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
emitter.onError(e)
}

override fun onResponse(call: Call, response: Response) {
try {
val response = call.execute()
if (!response.isSuccessful) {
emitter.onError(HttpCodeException(response.code))
} else {
emitter.onSuccess(response)
}
})
response.close()
} catch (e: Exception) {
emitter.onError(e)
}
}
}
.map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,17 @@ internal class UtilsApi(accountId: Int, provider: IServiceProvider) :
.map(extractResponseWithErrorHandling())
}
}

override fun getServerTime(): Single<Long> {
return provideService(
IUtilsService::class.java,
TokenType.USER,
TokenType.COMMUNITY,
TokenType.SERVICE
)
.flatMap { service ->
service.getServerTime()
.map(extractResponseWithErrorHandling())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ interface IUtilsApi {

@CheckResult
fun customScript(code: String?): Single<Int>

@CheckResult
fun getServerTime(): Single<Long>
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import dev.ragnarok.fenrir.api.model.response.VKApiLinkResponse
import io.reactivex.rxjava3.core.Single
import retrofit2.http.Field
import retrofit2.http.FormUrlEncoded
import retrofit2.http.GET
import retrofit2.http.POST

interface IUtilsService {
Expand Down Expand Up @@ -53,4 +54,8 @@ interface IUtilsService {
@FormUrlEncoded
@POST("execute")
fun customScript(@Field("code") code: String?): Single<BaseResponse<Int>>

@FormUrlEncoded
@GET("utils.getServerTime")
fun getServerTime(): Single<BaseResponse<Long>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package dev.ragnarok.fenrir.crypt
import android.util.Base64
import android.util.Log
import java.io.UnsupportedEncodingException
import java.nio.charset.StandardCharsets
import java.security.GeneralSecurityException
import java.security.MessageDigest
import java.security.NoSuchAlgorithmException
Expand Down Expand Up @@ -53,7 +52,7 @@ object AESCrypt {
@Throws(NoSuchAlgorithmException::class)
private fun generateKey(password: String): SecretKeySpec {
val digest = MessageDigest.getInstance(HASH_ALGORITHM)
val bytes = password.toByteArray(StandardCharsets.UTF_8)
val bytes = password.toByteArray(Charsets.UTF_8)
digest.update(bytes, 0, bytes.size)
val key = digest.digest()
log("SHA-256 key ", key)
Expand All @@ -73,7 +72,7 @@ object AESCrypt {
return try {
val key = generateKey(password)
log("message", message)
val cipherText = encrypt(key, ivBytes, message.toByteArray(StandardCharsets.UTF_8))
val cipherText = encrypt(key, ivBytes, message.toByteArray(Charsets.UTF_8))

//NO_WRAP is important as was getting \n at the end
val encoded = Base64.encodeToString(cipherText, Base64.NO_WRAP)
Expand Down Expand Up @@ -121,7 +120,7 @@ object AESCrypt {
log("decodedCipherText", decodedCipherText)
val decryptedBytes = decrypt(key, ivBytes, decodedCipherText)
log("decryptedBytes", decryptedBytes)
val message = String(decryptedBytes, StandardCharsets.UTF_8)
val message = String(decryptedBytes, Charsets.UTF_8)
log("message", message)
message
} catch (e: UnsupportedEncodingException) {
Expand Down
Loading

0 comments on commit c854d8d

Please sign in to comment.