Skip to content

Commit

Permalink
3. First My Rest
Browse files Browse the repository at this point in the history
3. First My Rest
  • Loading branch information
umerov1999 committed Dec 30, 2022
1 parent c854d8d commit e771207
Show file tree
Hide file tree
Showing 220 changed files with 6,241 additions and 11,209 deletions.
1 change: 0 additions & 1 deletion app_fenrir/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ dependencies {
implementation project(path: ":viewpager2")
implementation project(path: ":material")
implementation project(path: ":preference")
implementation project(path: ":retrofit")
implementation project(path: ":camera2")
implementation("com.squareup.okhttp3:okhttp-android:$okhttpLibraryVersion")
//implementation("com.squareup.okhttp3:logging-interceptor:$okhttpLibraryVersion")
Expand Down
1 change: 1 addition & 0 deletions app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class App : Application() {
}, RxUtils.ignore())
)
RxJavaPlugins.setErrorHandler {
it.printStackTrace()
Handler(mainLooper).post {
if (Settings.get().other().isDeveloper_mode) {
createCustomToast(this).showToastError(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.ragnarok.fenrir.api

import dev.ragnarok.fenrir.api.rest.SimplePostHttp
import io.reactivex.rxjava3.core.Single

interface IOtherVkRestProvider {
fun provideAuthRest(): Single<SimplePostHttp>
fun provideAuthServiceRest(): Single<SimplePostHttp>
fun provideLongpollRest(): Single<SimplePostHttp>
fun provideLocalServerRest(): Single<SimplePostHttp>
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package dev.ragnarok.fenrir.api

import dev.ragnarok.fenrir.api.rest.IServiceRest
import io.reactivex.rxjava3.core.Single

interface IServiceProvider {
fun <T : Any> provideService(
fun <T : IServiceRest> provideService(
accountId: Int,
serviceClass: Class<T>,
serviceClass: T,
vararg tokenTypes: Int
): Single<T>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package dev.ragnarok.fenrir.api

import dev.ragnarok.fenrir.api.rest.SimplePostHttp
import io.reactivex.rxjava3.core.Single

interface IUploadRestProvider {
fun provideUploadRest(): Single<SimplePostHttp>
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import dev.ragnarok.fenrir.model.ProxyConfig
import okhttp3.OkHttpClient

interface IVkMethodHttpClientFactory {
fun createDefaultVkHttpClient(accountId: Int, config: ProxyConfig?): OkHttpClient
fun createDefaultVkHttpClient(accountId: Int, config: ProxyConfig?): OkHttpClient.Builder
fun createCustomVkHttpClient(
accountId: Int,
token: String,
config: ProxyConfig?
): OkHttpClient
): OkHttpClient.Builder

fun createServiceVkHttpClient(config: ProxyConfig?): OkHttpClient
fun createRawVkApiOkHttpClient(@AccountType type: Int, config: ProxyConfig?): OkHttpClient
fun createServiceVkHttpClient(config: ProxyConfig?): OkHttpClient.Builder
fun createRawVkApiOkHttpClient(
@AccountType type: Int,
config: ProxyConfig?
): OkHttpClient.Builder
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package dev.ragnarok.fenrir.api

import dev.ragnarok.fenrir.AccountType
import dev.ragnarok.fenrir.api.rest.SimplePostHttp
import io.reactivex.rxjava3.core.Single
import okhttp3.OkHttpClient

interface IVkRestProvider {
fun provideNormalRest(accountId: Int): Single<SimplePostHttp>
fun provideCustomRest(accountId: Int, token: String): Single<SimplePostHttp>
fun provideServiceRest(): Single<SimplePostHttp>
fun provideNormalHttpClient(accountId: Int): Single<OkHttpClient.Builder>
fun provideRawHttpClient(@AccountType type: Int): Single<OkHttpClient.Builder>
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,40 @@ import dev.ragnarok.fenrir.Constants
import dev.ragnarok.fenrir.Constants.USER_AGENT
import dev.ragnarok.fenrir.api.HttpLoggerAndParser.toRequestBuilder
import dev.ragnarok.fenrir.api.HttpLoggerAndParser.vkHeader
import dev.ragnarok.fenrir.api.RetrofitWrapper.Companion.wrap
import dev.ragnarok.fenrir.kJson
import dev.ragnarok.fenrir.api.rest.SimplePostHttp
import dev.ragnarok.fenrir.nonNullNoEmpty
import dev.ragnarok.fenrir.settings.IProxySettings
import dev.ragnarok.fenrir.settings.Settings
import dev.ragnarok.fenrir.util.UncompressDefaultInterceptor
import dev.ragnarok.fenrir.util.Utils
import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPack
import dev.ragnarok.fenrir.util.serializeble.retrofit.kotlinx.serialization.jsonMsgPackConverterFactory
import dev.ragnarok.fenrir.util.serializeble.retrofit.rxjava3.RxJava3CallAdapterFactory
import io.reactivex.rxjava3.core.Single
import okhttp3.FormBody
import okhttp3.Interceptor
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import java.util.concurrent.TimeUnit

class OtherVkRetrofitProvider @SuppressLint("CheckResult") constructor(private val proxySettings: IProxySettings) :
IOtherVkRetrofitProvider {
private val longpollRetrofitLock = Any()
private val localServerRetrofitLock = Any()
private var longpollRetrofitInstance: RetrofitWrapper? = null
private var localServerRetrofitInstance: RetrofitWrapper? = null
class OtherVkRestProvider @SuppressLint("CheckResult") constructor(private val proxySettings: IProxySettings) :
IOtherVkRestProvider {
private val longpollRestLock = Any()
private val localServerRestLock = Any()
private var longpollRestInstance: SimplePostHttp? = null
private var localServerRestInstance: SimplePostHttp? = null
private fun onProxySettingsChanged() {
synchronized(longpollRetrofitLock) {
if (longpollRetrofitInstance != null) {
longpollRetrofitInstance?.cleanup()
longpollRetrofitInstance = null
synchronized(longpollRestLock) {
if (longpollRestInstance != null) {
longpollRestInstance?.stop()
longpollRestInstance = null
}
}
synchronized(localServerRetrofitLock) {
if (localServerRetrofitInstance != null) {
localServerRetrofitInstance?.cleanup()
localServerRetrofitInstance = null
synchronized(localServerRestLock) {
if (localServerRestInstance != null) {
localServerRestInstance?.stop()
localServerRestInstance = null
}
}
}

override fun provideAuthRetrofit(): Single<RetrofitWrapper> {
override fun provideAuthRest(): Single<SimplePostHttp> {
return Single.fromCallable {
val builder: OkHttpClient.Builder = OkHttpClient.Builder()
.readTimeout(15, TimeUnit.SECONDS)
Expand All @@ -65,17 +60,11 @@ class OtherVkRetrofitProvider @SuppressLint("CheckResult") constructor(private v
ProxyUtil.applyProxyConfig(builder, proxySettings.activeProxy)
HttpLoggerAndParser.adjust(builder)
HttpLoggerAndParser.configureToIgnoreCertificates(builder)
val retrofit = Retrofit.Builder()
.baseUrl("https://" + Settings.get().other().get_Auth_Domain() + "/")
.addConverterFactory(KCONVERTER_FACTORY)
.addCallAdapterFactory(RxJava3CallAdapterFactory.create())
.client(builder.build())
.build()
wrap(retrofit, false)
SimplePostHttp("https://" + Settings.get().other().get_Auth_Domain(), builder)
}
}

override fun provideAuthServiceRetrofit(): Single<RetrofitWrapper> {
override fun provideAuthServiceRest(): Single<SimplePostHttp> {
return Single.fromCallable {
val builder: OkHttpClient.Builder = OkHttpClient.Builder()
.readTimeout(15, TimeUnit.SECONDS)
Expand All @@ -96,17 +85,14 @@ class OtherVkRetrofitProvider @SuppressLint("CheckResult") constructor(private v
ProxyUtil.applyProxyConfig(builder, proxySettings.activeProxy)
HttpLoggerAndParser.adjust(builder)
HttpLoggerAndParser.configureToIgnoreCertificates(builder)
val retrofit = Retrofit.Builder()
.baseUrl("https://" + Settings.get().other().get_Api_Domain() + "/method/")
.addConverterFactory(KCONVERTER_FACTORY)
.addCallAdapterFactory(RX_ADAPTER_FACTORY)
.client(builder.build())
.build()
wrap(retrofit, false)
SimplePostHttp(
"https://" + Settings.get().other().get_Api_Domain() + "/method",
builder
)
}
}

private fun createLocalServerRetrofit(): Retrofit {
private fun createLocalServerRest(): SimplePostHttp {
val localSettings = Settings.get().other().localServer
val builder: OkHttpClient.Builder = OkHttpClient.Builder()
.readTimeout(15, TimeUnit.SECONDS)
Expand Down Expand Up @@ -141,17 +127,10 @@ class OtherVkRetrofitProvider @SuppressLint("CheckResult") constructor(private v
HttpLoggerAndParser.adjust(builder)
HttpLoggerAndParser.configureToIgnoreCertificates(builder)
val url = Utils.firstNonEmptyString(localSettings.url, "https://debug.dev")!!
return Retrofit.Builder()
.baseUrl("$url/method/")
.addConverterFactory(
KCONVERTER_FACTORY
)
.addCallAdapterFactory(RX_ADAPTER_FACTORY)
.client(builder.build())
.build()
return SimplePostHttp("$url/method", builder)
}

private fun createLongpollRetrofitInstance(): Retrofit {
private fun createLongpollRestInstance(): SimplePostHttp {
val builder: OkHttpClient.Builder = OkHttpClient.Builder()
.readTimeout(25, TimeUnit.SECONDS)
.connectTimeout(25, TimeUnit.SECONDS)
Expand All @@ -170,45 +149,38 @@ class OtherVkRetrofitProvider @SuppressLint("CheckResult") constructor(private v
ProxyUtil.applyProxyConfig(builder, proxySettings.activeProxy)
HttpLoggerAndParser.adjust(builder)
HttpLoggerAndParser.configureToIgnoreCertificates(builder)
return Retrofit.Builder()
.baseUrl("https://" + Settings.get().other().get_Api_Domain() + "/method/") // dummy
.addConverterFactory(KCONVERTER_FACTORY)
.addCallAdapterFactory(RX_ADAPTER_FACTORY)
.client(builder.build())
.build()
return SimplePostHttp(
"https://" + Settings.get().other().get_Api_Domain() + "/method",
builder
)
}

override fun provideLocalServerRetrofit(): Single<RetrofitWrapper> {
override fun provideLocalServerRest(): Single<SimplePostHttp> {
return Single.fromCallable {
if (localServerRetrofitInstance == null) {
synchronized(localServerRetrofitLock) {
if (localServerRetrofitInstance == null) {
localServerRetrofitInstance = wrap(createLocalServerRetrofit())
if (localServerRestInstance == null) {
synchronized(localServerRestLock) {
if (localServerRestInstance == null) {
localServerRestInstance = createLocalServerRest()
}
}
}
localServerRetrofitInstance!!
localServerRestInstance!!
}
}

override fun provideLongpollRetrofit(): Single<RetrofitWrapper> {
override fun provideLongpollRest(): Single<SimplePostHttp> {
return Single.fromCallable {
if (longpollRetrofitInstance == null) {
synchronized(longpollRetrofitLock) {
if (longpollRetrofitInstance == null) {
longpollRetrofitInstance = wrap(createLongpollRetrofitInstance())
if (longpollRestInstance == null) {
synchronized(longpollRestLock) {
if (longpollRestInstance == null) {
longpollRestInstance = createLongpollRestInstance()
}
}
}
longpollRetrofitInstance!!
longpollRestInstance!!
}
}

companion object {
private val KCONVERTER_FACTORY = jsonMsgPackConverterFactory(kJson, MsgPack())
private val RX_ADAPTER_FACTORY = RxJava3CallAdapterFactory.create()
}

init {
proxySettings.observeActive()
.subscribe { onProxySettingsChanged() }
Expand Down

This file was deleted.

Loading

0 comments on commit e771207

Please sign in to comment.