mirror of https://github.com/tuskyapp/Tusky.git
Browse Source
* Add Dagger DI * Preemptively fix tests * Add missing licenses * DI fixes * ci fixespull/556/head
41 changed files with 1041 additions and 416 deletions
@ -0,0 +1,63 @@
|
||||
/* Copyright 2018 charlag |
||||
* |
||||
* This file is a part of Tusky. |
||||
* |
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the |
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even |
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
||||
* Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License along with Tusky; if not, |
||||
* see <http://www.gnu.org/licenses>. */ |
||||
|
||||
package com.keylesspalace.tusky.di |
||||
|
||||
import com.keylesspalace.tusky.* |
||||
import dagger.Module |
||||
import dagger.android.ContributesAndroidInjector |
||||
|
||||
/** |
||||
* Created by charlag on 3/24/18. |
||||
*/ |
||||
|
||||
@Module |
||||
abstract class ActivitiesModule { |
||||
@ContributesAndroidInjector(modules = [FragmentBuildersModule::class]) |
||||
abstract fun contributesMainActivity(): MainActivity |
||||
|
||||
@ContributesAndroidInjector(modules = [FragmentBuildersModule::class]) |
||||
abstract fun contributesAccountActivity(): AccountActivity |
||||
|
||||
@ContributesAndroidInjector(modules = [FragmentBuildersModule::class]) |
||||
abstract fun contributesListsActivity(): ListsActivity |
||||
|
||||
@ContributesAndroidInjector |
||||
abstract fun contributesComposeActivity(): ComposeActivity |
||||
|
||||
@ContributesAndroidInjector |
||||
abstract fun contributesEditProfileActivity(): EditProfileActivity |
||||
|
||||
@ContributesAndroidInjector(modules = [FragmentBuildersModule::class]) |
||||
abstract fun contributesAccountListActivity(): AccountListActivity |
||||
|
||||
@ContributesAndroidInjector(modules = [FragmentBuildersModule::class]) |
||||
abstract fun contributesModalTimelineActivity(): ModalTimelineActivity |
||||
|
||||
@ContributesAndroidInjector(modules = [FragmentBuildersModule::class]) |
||||
abstract fun contributesViewTagActivity(): ViewTagActivity |
||||
|
||||
@ContributesAndroidInjector(modules = [FragmentBuildersModule::class]) |
||||
abstract fun contributesViewThreadActivity(): ViewThreadActivity |
||||
|
||||
@ContributesAndroidInjector(modules = [FragmentBuildersModule::class]) |
||||
abstract fun contributesFavouritesActivity(): FavouritesActivity |
||||
|
||||
@ContributesAndroidInjector(modules = [FragmentBuildersModule::class]) |
||||
abstract fun contribtutesSearchAvtivity(): SearchActivity |
||||
|
||||
@ContributesAndroidInjector() |
||||
abstract fun contributesAboutActivity(): AboutActivity |
||||
} |
||||
@ -0,0 +1,46 @@
|
||||
/* Copyright 2018 charlag |
||||
* |
||||
* This file is a part of Tusky. |
||||
* |
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the |
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even |
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
||||
* Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License along with Tusky; if not, |
||||
* see <http://www.gnu.org/licenses>. */ |
||||
|
||||
package com.keylesspalace.tusky.di |
||||
|
||||
import com.keylesspalace.tusky.TuskyApplication |
||||
import dagger.BindsInstance |
||||
import dagger.Component |
||||
import dagger.android.AndroidInjectionModule |
||||
import javax.inject.Singleton |
||||
|
||||
|
||||
/** |
||||
* Created by charlag on 3/21/18. |
||||
*/ |
||||
|
||||
@Singleton |
||||
@Component(modules = [ |
||||
AppModule::class, |
||||
NetworkModule::class, |
||||
AndroidInjectionModule::class, |
||||
ActivitiesModule::class |
||||
]) |
||||
interface AppComponent { |
||||
@Component.Builder |
||||
interface Builder { |
||||
@BindsInstance |
||||
fun application(tuskyApp: TuskyApplication): Builder |
||||
|
||||
fun build(): AppComponent |
||||
} |
||||
|
||||
fun inject(app: TuskyApplication) |
||||
} |
||||
@ -0,0 +1,80 @@
|
||||
/* Copyright 2018 charlag |
||||
* |
||||
* This file is a part of Tusky. |
||||
* |
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the |
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even |
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
||||
* Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License along with Tusky; if not, |
||||
* see <http://www.gnu.org/licenses>. */ |
||||
|
||||
package com.keylesspalace.tusky.di |
||||
|
||||
import android.app.Activity |
||||
import android.app.Application |
||||
import android.os.Bundle |
||||
import android.support.v4.app.Fragment |
||||
import android.support.v4.app.FragmentActivity |
||||
import android.support.v4.app.FragmentManager |
||||
import com.keylesspalace.tusky.TuskyApplication |
||||
import dagger.android.AndroidInjection |
||||
import dagger.android.support.AndroidSupportInjection |
||||
import dagger.android.support.HasSupportFragmentInjector |
||||
|
||||
/** |
||||
* Created by charlag on 3/24/18. |
||||
*/ |
||||
|
||||
object AppInjector { |
||||
fun init(app: TuskyApplication) { |
||||
DaggerAppComponent.builder().application(app) |
||||
.build().inject(app) |
||||
|
||||
app.registerActivityLifecycleCallbacks(object : Application.ActivityLifecycleCallbacks { |
||||
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) { |
||||
handleActivity(activity) |
||||
} |
||||
|
||||
override fun onActivityPaused(activity: Activity?) { |
||||
} |
||||
|
||||
override fun onActivityResumed(activity: Activity?) { |
||||
} |
||||
|
||||
override fun onActivityStarted(activity: Activity?) { |
||||
} |
||||
|
||||
override fun onActivityDestroyed(activity: Activity?) { |
||||
} |
||||
|
||||
override fun onActivitySaveInstanceState(activity: Activity?, outState: Bundle?) { |
||||
} |
||||
|
||||
override fun onActivityStopped(activity: Activity?) { |
||||
} |
||||
|
||||
}) |
||||
} |
||||
|
||||
private fun handleActivity(activity: Activity) { |
||||
if (activity is HasSupportFragmentInjector || activity is Injectable) { |
||||
AndroidInjection.inject(activity) |
||||
} |
||||
if (activity is FragmentActivity) { |
||||
activity.supportFragmentManager.registerFragmentLifecycleCallbacks( |
||||
object : FragmentManager.FragmentLifecycleCallbacks() { |
||||
override fun onFragmentCreated(fm: FragmentManager?, f: Fragment?, |
||||
savedInstanceState: Bundle?) { |
||||
if (f is Injectable) { |
||||
AndroidSupportInjection.inject(f) |
||||
} |
||||
} |
||||
}, true) |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,68 @@
|
||||
/* Copyright 2018 charlag |
||||
* |
||||
* This file is a part of Tusky. |
||||
* |
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the |
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even |
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
||||
* Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License along with Tusky; if not, |
||||
* see <http://www.gnu.org/licenses>. */ |
||||
|
||||
|
||||
package com.keylesspalace.tusky.di |
||||
|
||||
import android.app.Application |
||||
import android.content.Context |
||||
import android.content.SharedPreferences |
||||
import android.preference.PreferenceManager |
||||
import android.support.v4.content.LocalBroadcastManager |
||||
import com.keylesspalace.tusky.R |
||||
import com.keylesspalace.tusky.TuskyApplication |
||||
import com.keylesspalace.tusky.db.AccountManager |
||||
import com.keylesspalace.tusky.network.MastodonApi |
||||
import com.keylesspalace.tusky.network.TimelineCases |
||||
import com.keylesspalace.tusky.network.TimelineCasesImpl |
||||
import dagger.Module |
||||
import dagger.Provides |
||||
import javax.inject.Singleton |
||||
|
||||
/** |
||||
* Created by charlag on 3/21/18. |
||||
*/ |
||||
|
||||
@Module |
||||
class AppModule { |
||||
|
||||
@Provides |
||||
fun providesApplication(app: TuskyApplication): Application = app |
||||
|
||||
@Provides |
||||
fun providesContext(app: Application): Context = app |
||||
|
||||
@Provides |
||||
fun providesSharedPreferences(app: Application): SharedPreferences { |
||||
return PreferenceManager.getDefaultSharedPreferences(app) |
||||
} |
||||
|
||||
@Provides |
||||
fun providesBroadcastManager(app: Application): LocalBroadcastManager { |
||||
return LocalBroadcastManager.getInstance(app) |
||||
} |
||||
|
||||
@Provides |
||||
fun providesTimelineUseCases(api: MastodonApi, |
||||
broadcastManager: LocalBroadcastManager): TimelineCases { |
||||
return TimelineCasesImpl(api, broadcastManager) |
||||
} |
||||
|
||||
@Provides |
||||
@Singleton |
||||
fun providesAccountManager(app: TuskyApplication): AccountManager { |
||||
return app.serviceLocator.get(AccountManager::class.java) |
||||
} |
||||
} |
||||
@ -0,0 +1,43 @@
|
||||
/* Copyright 2018 charlag |
||||
* |
||||
* This file is a part of Tusky. |
||||
* |
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the |
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even |
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
||||
* Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License along with Tusky; if not, |
||||
* see <http://www.gnu.org/licenses>. */ |
||||
|
||||
|
||||
package com.keylesspalace.tusky.di |
||||
|
||||
import com.keylesspalace.tusky.fragment.* |
||||
import dagger.Module |
||||
import dagger.android.ContributesAndroidInjector |
||||
|
||||
/** |
||||
* Created by charlag on 3/24/18. |
||||
*/ |
||||
|
||||
@Module |
||||
abstract class FragmentBuildersModule { |
||||
@ContributesAndroidInjector |
||||
abstract fun accountListFragment(): AccountListFragment |
||||
|
||||
@ContributesAndroidInjector |
||||
abstract fun accountMediaFragment(): AccountMediaFragment |
||||
|
||||
@ContributesAndroidInjector |
||||
abstract fun viewThreadFragment(): ViewThreadFragment |
||||
|
||||
@ContributesAndroidInjector |
||||
abstract fun timelineFragment(): TimelineFragment |
||||
|
||||
@ContributesAndroidInjector |
||||
abstract fun notificationsFragment(): NotificationsFragment |
||||
} |
||||
@ -0,0 +1,23 @@
|
||||
/* Copyright 2018 charlag |
||||
* |
||||
* This file is a part of Tusky. |
||||
* |
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the |
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even |
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
||||
* Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License along with Tusky; if not, |
||||
* see <http://www.gnu.org/licenses>. */ |
||||
|
||||
|
||||
package com.keylesspalace.tusky.di |
||||
|
||||
/** |
||||
* Created by charlag on 3/24/18. |
||||
*/ |
||||
|
||||
interface Injectable |
||||
@ -0,0 +1,111 @@
|
||||
/* Copyright 2018 charlag |
||||
* |
||||
* This file is a part of Tusky. |
||||
* |
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the |
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even |
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
||||
* Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License along with Tusky; if not, |
||||
* see <http://www.gnu.org/licenses>. */ |
||||
|
||||
|
||||
package com.keylesspalace.tusky.di |
||||
|
||||
import android.content.SharedPreferences |
||||
import android.text.Spanned |
||||
import com.google.gson.Gson |
||||
import com.google.gson.GsonBuilder |
||||
import com.google.gson.JsonDeserializer |
||||
import com.keylesspalace.tusky.db.AccountManager |
||||
import com.keylesspalace.tusky.json.SpannedTypeAdapter |
||||
import com.keylesspalace.tusky.network.InstanceSwitchAuthInterceptor |
||||
import com.keylesspalace.tusky.network.MastodonApi |
||||
import com.keylesspalace.tusky.util.OkHttpUtils |
||||
import dagger.Module |
||||
import dagger.Provides |
||||
import dagger.multibindings.ClassKey |
||||
import dagger.multibindings.IntoMap |
||||
import dagger.multibindings.IntoSet |
||||
import okhttp3.Interceptor |
||||
import okhttp3.OkHttpClient |
||||
import retrofit2.Converter |
||||
import retrofit2.Retrofit |
||||
import retrofit2.converter.gson.GsonConverterFactory |
||||
import javax.inject.Singleton |
||||
|
||||
/** |
||||
* Created by charlag on 3/24/18. |
||||
*/ |
||||
|
||||
@Module |
||||
class NetworkModule { |
||||
@Provides |
||||
@IntoMap() |
||||
@ClassKey(Spanned::class) |
||||
fun providesSpannedTypeAdapter(): JsonDeserializer<*> = SpannedTypeAdapter() |
||||
|
||||
@Provides |
||||
@Singleton |
||||
fun providesGson(adapters: @JvmSuppressWildcards Map<Class<*>, JsonDeserializer<*>>): Gson { |
||||
return GsonBuilder() |
||||
.apply { |
||||
for ((k, v) in adapters) { |
||||
registerTypeAdapter(k, v) |
||||
} |
||||
} |
||||
.create() |
||||
} |
||||
|
||||
@Provides |
||||
@IntoSet |
||||
@Singleton |
||||
fun providesConverterFactory(gson: Gson): Converter.Factory = GsonConverterFactory.create(gson) |
||||
|
||||
@Provides |
||||
@IntoSet |
||||
@Singleton |
||||
fun providesAuthInterceptor(accountManager: AccountManager): Interceptor { |
||||
// should accept AccountManager here probably but I don't want to break things yet |
||||
return InstanceSwitchAuthInterceptor(accountManager) |
||||
} |
||||
|
||||
@Provides |
||||
@Singleton |
||||
fun providesHttpClient(interceptors: @JvmSuppressWildcards Set<Interceptor>, |
||||
preferences: SharedPreferences): OkHttpClient { |
||||
return OkHttpUtils.getCompatibleClientBuilder(preferences) |
||||
.apply { |
||||
interceptors.fold(this) { b, i -> |
||||
b.addInterceptor(i) |
||||
} |
||||
} |
||||
.build() |
||||
} |
||||
|
||||
|
||||
@Provides |
||||
@Singleton |
||||
fun providesRetrofit(httpClient: OkHttpClient, |
||||
converters: @JvmSuppressWildcards Set<Converter.Factory>): Retrofit { |
||||
return Retrofit.Builder().baseUrl("https://dummy.placeholder/") |
||||
.client(httpClient) |
||||
.let { builder -> |
||||
// Doing it this way in case builder will be immutable so we return the final |
||||
// instance |
||||
converters.fold(builder) { b, c -> |
||||
b.addConverterFactory(c) |
||||
} |
||||
} |
||||
.build() |
||||
|
||||
} |
||||
|
||||
@Provides |
||||
@Singleton |
||||
fun providesApi(retrofit: Retrofit): MastodonApi = retrofit.create(MastodonApi::class.java) |
||||
} |
||||
@ -1,42 +0,0 @@
|
||||
package com.keylesspalace.tusky.network; |
||||
|
||||
import android.support.annotation.NonNull; |
||||
|
||||
import com.keylesspalace.tusky.TuskyApplication; |
||||
import com.keylesspalace.tusky.db.AccountEntity; |
||||
import com.keylesspalace.tusky.db.AccountManager; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
import okhttp3.Interceptor; |
||||
import okhttp3.Request; |
||||
import okhttp3.Response; |
||||
|
||||
/** |
||||
* Created by charlag on 31/10/17. |
||||
*/ |
||||
|
||||
public final class AuthInterceptor implements Interceptor { |
||||
|
||||
AccountManager accountManager; |
||||
|
||||
public AuthInterceptor(AccountManager accountManager) { |
||||
this.accountManager = accountManager; |
||||
} |
||||
|
||||
@Override |
||||
public Response intercept(@NonNull Chain chain) throws IOException { |
||||
|
||||
Request originalRequest = chain.request(); |
||||
AccountEntity currentAccount = accountManager.getActiveAccount(); |
||||
|
||||
Request.Builder builder = originalRequest.newBuilder(); |
||||
if (currentAccount != null) { |
||||
builder.header("Authorization", String.format("Bearer %s", currentAccount.getAccessToken())); |
||||
} |
||||
Request newRequest = builder.build(); |
||||
|
||||
return chain.proceed(newRequest); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,69 @@
|
||||
/* Copyright 2018 charlag |
||||
* |
||||
* This file is a part of Tusky. |
||||
* |
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the |
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even |
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
||||
* Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License along with Tusky; if not, |
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
package com.keylesspalace.tusky.network; |
||||
|
||||
import android.support.annotation.NonNull; |
||||
|
||||
import com.keylesspalace.tusky.db.AccountEntity; |
||||
import com.keylesspalace.tusky.db.AccountManager; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
import okhttp3.HttpUrl; |
||||
import okhttp3.Interceptor; |
||||
import okhttp3.Request; |
||||
import okhttp3.Response; |
||||
|
||||
/** |
||||
* Created by charlag on 31/10/17. |
||||
*/ |
||||
|
||||
public final class InstanceSwitchAuthInterceptor implements Interceptor { |
||||
private AccountManager accountManager; |
||||
|
||||
public InstanceSwitchAuthInterceptor(AccountManager accountManager) { |
||||
this.accountManager = accountManager; |
||||
} |
||||
|
||||
@Override |
||||
public Response intercept(@NonNull Chain chain) throws IOException { |
||||
|
||||
Request originalRequest = chain.request(); |
||||
AccountEntity currentAccount = accountManager.getActiveAccount(); |
||||
|
||||
Request.Builder builder = originalRequest.newBuilder(); |
||||
|
||||
String instanceHeader = originalRequest.header(MastodonApi.DOMAIN_HEADER); |
||||
if (instanceHeader != null) { |
||||
// use domain explicitly specified in custom header
|
||||
builder.url(swapHost(originalRequest.url(), instanceHeader)); |
||||
builder.removeHeader(MastodonApi.DOMAIN_HEADER); |
||||
} else if (currentAccount != null) { |
||||
//use domain of current account
|
||||
builder.url(swapHost(originalRequest.url(), currentAccount.getDomain())) |
||||
.header("Authorization", |
||||
String.format("Bearer %s", currentAccount.getAccessToken())); |
||||
} |
||||
Request newRequest = builder.build(); |
||||
|
||||
return chain.proceed(newRequest); |
||||
} |
||||
|
||||
@NonNull |
||||
private HttpUrl swapHost(@NonNull HttpUrl url, @NonNull String host) { |
||||
return url.newBuilder().host(host).build(); |
||||
} |
||||
} |
||||
@ -0,0 +1,99 @@
|
||||
/* Copyright 2018 charlag |
||||
* |
||||
* This file is a part of Tusky. |
||||
* |
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the |
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even |
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
||||
* Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License along with Tusky; if not, |
||||
* see <http://www.gnu.org/licenses>. */ |
||||
|
||||
package com.keylesspalace.tusky.network |
||||
|
||||
import android.content.Intent |
||||
import android.support.v4.content.LocalBroadcastManager |
||||
import com.keylesspalace.tusky.entity.Relationship |
||||
import com.keylesspalace.tusky.entity.Status |
||||
import com.keylesspalace.tusky.receiver.TimelineReceiver |
||||
import okhttp3.ResponseBody |
||||
import retrofit2.Call |
||||
import retrofit2.Callback |
||||
import retrofit2.Response |
||||
|
||||
/** |
||||
* Created by charlag on 3/24/18. |
||||
*/ |
||||
|
||||
interface TimelineCases { |
||||
fun reblogWithCallback(status: Status, reblog: Boolean, callback: Callback<Status>) |
||||
fun favouriteWithCallback(status: Status, favourite: Boolean, callback: Callback<Status>) |
||||
fun mute(id: String) |
||||
fun block(id: String) |
||||
fun delete(id: String) |
||||
} |
||||
|
||||
class TimelineCasesImpl( |
||||
private val mastodonApi: MastodonApi, |
||||
private val broadcastManager: LocalBroadcastManager |
||||
) : TimelineCases { |
||||
override fun reblogWithCallback(status: Status, reblog: Boolean, callback: Callback<Status>) { |
||||
val id = status.actionableId |
||||
|
||||
val call = if (reblog) { |
||||
mastodonApi.reblogStatus(id) |
||||
} else { |
||||
mastodonApi.unreblogStatus(id) |
||||
} |
||||
call.enqueue(callback) |
||||
} |
||||
|
||||
override fun favouriteWithCallback(status: Status, favourite: Boolean, callback: Callback<Status>) { |
||||
val id = status.actionableId |
||||
|
||||
val call = if (favourite) { |
||||
mastodonApi.favouriteStatus(id) |
||||
} else { |
||||
mastodonApi.unfavouriteStatus(id) |
||||
} |
||||
call.enqueue(callback) |
||||
} |
||||
|
||||
override fun mute(id: String) { |
||||
val call = mastodonApi.muteAccount(id) |
||||
call.enqueue(object : Callback<Relationship> { |
||||
override fun onResponse(call: Call<Relationship>, response: Response<Relationship>) {} |
||||
|
||||
override fun onFailure(call: Call<Relationship>, t: Throwable) {} |
||||
}) |
||||
val intent = Intent(TimelineReceiver.Types.MUTE_ACCOUNT) |
||||
intent.putExtra("id", id) |
||||
broadcastManager.sendBroadcast(intent) |
||||
} |
||||
|
||||
override fun block(id: String) { |
||||
val call = mastodonApi.blockAccount(id) |
||||
call.enqueue(object : Callback<Relationship> { |
||||
override fun onResponse(call: Call<Relationship>, response: retrofit2.Response<Relationship>) {} |
||||
|
||||
override fun onFailure(call: Call<Relationship>, t: Throwable) {} |
||||
}) |
||||
val intent = Intent(TimelineReceiver.Types.BLOCK_ACCOUNT) |
||||
intent.putExtra("id", id) |
||||
broadcastManager.sendBroadcast(intent) |
||||
} |
||||
|
||||
override fun delete(id: String) { |
||||
val call = mastodonApi.deleteStatus(id) |
||||
call.enqueue(object : Callback<ResponseBody> { |
||||
override fun onResponse(call: Call<ResponseBody>, response: retrofit2.Response<ResponseBody>) {} |
||||
|
||||
override fun onFailure(call: Call<ResponseBody>, t: Throwable) {} |
||||
}) |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue