Fix tracedroid, accept json as responses from api

This commit is contained in:
Matthieu 2021-03-19 10:34:43 +01:00
parent d6fb67357c
commit 2cb2ecdb72
4 changed files with 18 additions and 4 deletions

View File

@ -39,6 +39,7 @@ import com.mikepenz.materialdrawer.model.interfaces.*
import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader
import com.mikepenz.materialdrawer.util.DrawerImageLoader
import com.mikepenz.materialdrawer.widget.AccountHeaderView
import org.ligi.tracedroid.sending.sendTraceDroidStackTracesIfExist
import retrofit2.HttpException
import java.io.IOException
@ -68,6 +69,8 @@ class MainActivity : BaseActivity() {
launchActivity(LoginActivity(), firstTime = true)
finish()
} else {
sendTraceDroidStackTracesIfExist("contact@pixeldroid.org", this)
setupDrawer()
val tabs: List<() -> Fragment> = listOf(

View File

@ -16,7 +16,6 @@ class PixelDroidApplication: Application() {
super.onCreate()
TraceDroid.init(this)
sendTraceDroidStackTracesIfExist("contact@pixeldroid.org", this)
val sharedPreferences =
PreferenceManager.getDefaultSharedPreferences(this)

View File

@ -0,0 +1,5 @@
package com.h.pixeldroid.utils.api.objects
data class Error(
val error: String?
)

View File

@ -2,7 +2,6 @@ package com.h.pixeldroid.utils.di
import com.h.pixeldroid.utils.api.PixelfedAPI
import com.h.pixeldroid.utils.db.AppDatabase
import com.h.pixeldroid.utils.db.addUser
import com.h.pixeldroid.utils.db.entities.UserDatabaseEntity
import dagger.Module
import dagger.Provides
@ -11,7 +10,6 @@ import okhttp3.*
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import java.lang.Exception
import javax.inject.Singleton
@Module
@ -74,9 +72,18 @@ class PixelfedAPIHolder(db: AppDatabase?){
): PixelfedAPI {
val newAPI = intermediate
.baseUrl(user.instance_uri)
.client(OkHttpClient().newBuilder().authenticator(TokenAuthenticator(user, db)).build())
.client(
OkHttpClient().newBuilder().authenticator(TokenAuthenticator(user, db))
.addInterceptor {
it.request().newBuilder().run {
header("Accept", "application/json")
it.proceed(build())
}
}.build()
)
.build().create(PixelfedAPI::class.java)
api = newAPI
return newAPI
}
}