mirror of
https://github.com/nextcloud/talk-android
synced 2025-03-06 14:27:24 +00:00
Back to regular inject :(
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
3a83a1783e
commit
e514c24316
@ -80,7 +80,6 @@ import com.nextcloud.talk.utils.bundle.BundleKeys;
|
||||
import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||
import com.nextcloud.talk.utils.glide.GlideApp;
|
||||
import com.nextcloud.talk.utils.preferences.AppPreferences;
|
||||
import com.nextcloud.talk.utils.singletons.ApplicationWideApiHolder;
|
||||
import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder;
|
||||
import com.nextcloud.talk.webrtc.MagicAudioManager;
|
||||
import com.nextcloud.talk.webrtc.MagicPeerConnectionWrapper;
|
||||
@ -182,6 +181,7 @@ public class CallController extends BaseController {
|
||||
@BindView(R.id.conversationRelativeLayoutView)
|
||||
RelativeLayout conversationView;
|
||||
|
||||
@Inject
|
||||
NcApi ncApi;
|
||||
@Inject
|
||||
EventBus eventBus;
|
||||
@ -299,8 +299,6 @@ public class CallController extends BaseController {
|
||||
.setRepeatMode(PulseAnimation.REVERSE);
|
||||
|
||||
|
||||
ncApi = ApplicationWideApiHolder.getInstance().getNcApiInstanceForAccountId(conversationUser.getId(), baseUrl);
|
||||
|
||||
if (isVoiceOnlyCall) {
|
||||
callControlEnableSpeaker.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
@ -76,7 +76,6 @@ import com.nextcloud.talk.utils.MagicFlipView;
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys;
|
||||
import com.nextcloud.talk.utils.glide.GlideApp;
|
||||
import com.nextcloud.talk.utils.preferences.AppPreferences;
|
||||
import com.nextcloud.talk.utils.singletons.ApplicationWideApiHolder;
|
||||
import com.nextcloud.talk.utils.singletons.AvatarStatusCodeHolder;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
@ -103,7 +102,8 @@ public class CallNotificationController extends BaseController {
|
||||
|
||||
private static final String TAG = "CallNotificationController";
|
||||
|
||||
private NcApi ncApi;
|
||||
@Inject
|
||||
NcApi ncApi;
|
||||
|
||||
@Inject
|
||||
AppPreferences appPreferences;
|
||||
@ -297,7 +297,6 @@ public class CallNotificationController extends BaseController {
|
||||
|
||||
if (handler == null) {
|
||||
handler = new Handler();
|
||||
ncApi = ApplicationWideApiHolder.getInstance().getNcApiInstanceForAccountId(userBeingCalled.getId(), null);
|
||||
}
|
||||
|
||||
if (currentConversation == null) {
|
||||
|
@ -83,7 +83,6 @@ import com.nextcloud.talk.utils.NotificationUtils;
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys;
|
||||
import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||
import com.nextcloud.talk.utils.glide.GlideApp;
|
||||
import com.nextcloud.talk.utils.singletons.ApplicationWideApiHolder;
|
||||
import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder;
|
||||
import com.otaliastudios.autocomplete.Autocomplete;
|
||||
import com.otaliastudios.autocomplete.AutocompleteCallback;
|
||||
@ -124,6 +123,7 @@ import retrofit2.Response;
|
||||
public class ChatController extends BaseController implements MessagesListAdapter.OnLoadMoreListener,
|
||||
MessagesListAdapter.Formatter<Date>, MessagesListAdapter.OnMessageLongClickListener, MessageHolders.ContentChecker {
|
||||
private static final String TAG = "ChatController";
|
||||
@Inject
|
||||
NcApi ncApi;
|
||||
@Inject
|
||||
UserUtils userUtils;
|
||||
@ -296,8 +296,6 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
||||
sendHiTextView.setText(String.format(getResources().getString(R.string.nc_chat_empty), getResources()
|
||||
.getString(R.string.nc_hello)));
|
||||
|
||||
ncApi = ApplicationWideApiHolder.getInstance().getNcApiInstanceForAccountId(conversationUser.getId(), baseUrl);
|
||||
|
||||
if (adapter == null) {
|
||||
|
||||
loadingProgressBar.setVisibility(View.VISIBLE);
|
||||
|
@ -68,7 +68,6 @@ import com.nextcloud.talk.models.json.sharees.ShareesOverall;
|
||||
import com.nextcloud.talk.utils.ApiUtils;
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys;
|
||||
import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||
import com.nextcloud.talk.utils.singletons.ApplicationWideApiHolder;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
@ -129,7 +128,8 @@ public class ContactsController extends BaseController implements SearchView.OnQ
|
||||
@BindView(R.id.fast_scroller)
|
||||
FastScroller fastScroller;
|
||||
|
||||
private NcApi ncApi;
|
||||
@Inject
|
||||
NcApi ncApi;
|
||||
private String credentials;
|
||||
private UserEntity currentUser;
|
||||
private Disposable contactsQueryDisposable;
|
||||
@ -208,7 +208,6 @@ public class ContactsController extends BaseController implements SearchView.OnQ
|
||||
currentUser = userUtils.getCurrentUser();
|
||||
|
||||
if (currentUser != null) {
|
||||
ncApi = ApplicationWideApiHolder.getInstance().getNcApiInstanceForAccountId(currentUser.getId(), null);
|
||||
credentials = ApiUtils.getCredentials(currentUser.getUserId(), currentUser.getToken());
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,6 @@ import com.nextcloud.talk.utils.ApiUtils;
|
||||
import com.nextcloud.talk.utils.KeyboardUtils;
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys;
|
||||
import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||
import com.nextcloud.talk.utils.singletons.ApplicationWideApiHolder;
|
||||
|
||||
import org.apache.commons.lang3.builder.CompareToBuilder;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
@ -107,6 +106,7 @@ public class ConversationsListController extends BaseController implements Searc
|
||||
@Inject
|
||||
EventBus eventBus;
|
||||
|
||||
@Inject
|
||||
NcApi ncApi;
|
||||
|
||||
@BindView(R.id.recycler_view)
|
||||
@ -155,7 +155,6 @@ public class ConversationsListController extends BaseController implements Searc
|
||||
currentUser = userUtils.getCurrentUser();
|
||||
|
||||
if (currentUser != null) {
|
||||
ncApi = ApplicationWideApiHolder.getInstance().getNcApiInstanceForAccountId(currentUser.getId(), null);
|
||||
credentials = ApiUtils.getCredentials(currentUser.getUserId(), currentUser.getToken());
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,6 @@ import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||
import com.nextcloud.talk.utils.glide.GlideApp;
|
||||
import com.nextcloud.talk.utils.preferences.AppPreferences;
|
||||
import com.nextcloud.talk.utils.preferences.MagicUserInputModule;
|
||||
import com.nextcloud.talk.utils.singletons.ApplicationWideApiHolder;
|
||||
import com.nextcloud.talk.utils.singletons.ApplicationWideMessageHolder;
|
||||
import com.yarolegovich.mp.MaterialChoicePreference;
|
||||
import com.yarolegovich.mp.MaterialEditTextPreference;
|
||||
@ -161,7 +160,8 @@ public class SettingsController extends BaseController {
|
||||
@Inject
|
||||
AppPreferences appPreferences;
|
||||
|
||||
private NcApi ncApi;
|
||||
@Inject
|
||||
NcApi ncApi;
|
||||
|
||||
@Inject
|
||||
UserUtils userUtils;
|
||||
@ -183,7 +183,6 @@ public class SettingsController extends BaseController {
|
||||
private void getCurrentUser() {
|
||||
currentUser = userUtils.getCurrentUser();
|
||||
credentials = ApiUtils.getCredentials(currentUser.getUserId(), currentUser.getToken());
|
||||
ncApi = ApplicationWideApiHolder.getInstance().getNcApiInstanceForAccountId(currentUser.getId(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -56,11 +56,10 @@ import com.nextcloud.talk.models.json.participants.AddParticipantOverall;
|
||||
import com.nextcloud.talk.models.json.rooms.Conversation;
|
||||
import com.nextcloud.talk.models.json.rooms.RoomOverall;
|
||||
import com.nextcloud.talk.utils.ApiUtils;
|
||||
import com.nextcloud.talk.utils.singletons.ApplicationWideApiHolder;
|
||||
import com.nextcloud.talk.utils.singletons.ApplicationWideMessageHolder;
|
||||
import com.nextcloud.talk.utils.DisplayUtils;
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys;
|
||||
import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||
import com.nextcloud.talk.utils.singletons.ApplicationWideMessageHolder;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.parceler.Parcels;
|
||||
@ -96,6 +95,7 @@ public class OperationsMenuController extends BaseController {
|
||||
@BindView(R.id.web_button)
|
||||
Button webButton;
|
||||
|
||||
@Inject
|
||||
NcApi ncApi;
|
||||
|
||||
@Inject
|
||||
@ -156,8 +156,6 @@ public class OperationsMenuController extends BaseController {
|
||||
super.onViewBound(view);
|
||||
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
|
||||
|
||||
ncApi = ApplicationWideApiHolder.getInstance().getNcApiInstanceForAccountId(userUtils.getCurrentUser().getId
|
||||
(), null);
|
||||
processOperation();
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,6 @@ import com.nextcloud.talk.utils.ssl.MagicKeyManager;
|
||||
import com.nextcloud.talk.utils.ssl.MagicTrustManager;
|
||||
import com.nextcloud.talk.utils.ssl.SSLSocketFactoryCompat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.CookieManager;
|
||||
import java.net.InetSocketAddress;
|
||||
@ -47,7 +46,6 @@ import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.UnrecoverableKeyException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
@ -77,6 +75,7 @@ public class RestModule {
|
||||
|
||||
private static final String TAG = "RestModule";
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
NcApi provideNcApi(Retrofit retrofit) {
|
||||
return retrofit.create(NcApi.class);
|
||||
@ -102,6 +101,7 @@ public class RestModule {
|
||||
}
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
Retrofit provideRetrofit(OkHttpClient httpClient) {
|
||||
Retrofit.Builder retrofitBuilder = new Retrofit.Builder()
|
||||
@ -152,25 +152,18 @@ public class RestModule {
|
||||
return new SSLSocketFactoryCompat(keyManager, magicTrustManager);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
CookieManager provideCookieManager() {
|
||||
return new CookieManager();
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
Cache provideCache(UserUtils userUtils) {
|
||||
Cache provideCache() {
|
||||
int cacheSize = 128 * 1024 * 1024; // 128 MB
|
||||
String userId = "";
|
||||
|
||||
if (userUtils.getCurrentUser() != null) {
|
||||
userId = Long.toString(userUtils.getCurrentUser().getId());
|
||||
} else {
|
||||
Random r = new Random( System.currentTimeMillis() );
|
||||
userId = "nc-temp-" + (10000 + r.nextInt(20000));
|
||||
}
|
||||
|
||||
return new Cache(new File(NextcloudTalkApplication.getSharedApplication().getCacheDir() + "/" +
|
||||
userId), cacheSize);
|
||||
return new Cache(NextcloudTalkApplication.getSharedApplication().getCacheDir(), cacheSize);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@ -182,6 +175,7 @@ public class RestModule {
|
||||
return dispatcher;
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
OkHttpClient provideHttpClient(Proxy proxy, AppPreferences appPreferences,
|
||||
MagicTrustManager magicTrustManager,
|
||||
|
@ -37,7 +37,6 @@ import com.nextcloud.talk.models.json.generic.GenericOverall;
|
||||
import com.nextcloud.talk.models.json.push.PushConfigurationState;
|
||||
import com.nextcloud.talk.utils.ApiUtils;
|
||||
import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||
import com.nextcloud.talk.utils.singletons.ApplicationWideApiHolder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
@ -66,6 +65,7 @@ public class AccountRemovalWorker extends Worker {
|
||||
@Inject
|
||||
OkHttpClient okHttpClient;
|
||||
|
||||
@Inject
|
||||
NcApi ncApi;
|
||||
|
||||
@NonNull
|
||||
@ -83,7 +83,6 @@ public class AccountRemovalWorker extends Worker {
|
||||
PushConfigurationState.class);
|
||||
PushConfigurationState finalPushConfigurationState = pushConfigurationState;
|
||||
|
||||
ncApi = ApplicationWideApiHolder.getInstance().getNcApiInstanceForAccountId(userEntity.getId(), null);
|
||||
credentials = ApiUtils.getCredentials(userEntity.getUserId(), userEntity.getToken());
|
||||
|
||||
String finalCredentials = credentials;
|
||||
@ -107,7 +106,7 @@ public class AccountRemovalWorker extends Worker {
|
||||
|
||||
ncApi.unregisterDeviceForNotificationsWithProxy
|
||||
(finalCredentials, ApiUtils.getUrlPushProxy(), queryMap)
|
||||
.blockingSubscribe(new Observer<Void>() {
|
||||
.subscribe(new Observer<Void>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
|
||||
@ -116,8 +115,6 @@ public class AccountRemovalWorker extends Worker {
|
||||
@Override
|
||||
public void onNext(Void aVoid) {
|
||||
|
||||
ApplicationWideApiHolder.getInstance().removeNcApiInstanceForAccountId(userEntity.getId());
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
String groupName = String.format(getApplicationContext().getResources()
|
||||
.getString(R.string
|
||||
|
@ -32,7 +32,6 @@ import com.nextcloud.talk.models.json.capabilities.CapabilitiesOverall;
|
||||
import com.nextcloud.talk.utils.ApiUtils;
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys;
|
||||
import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||
import com.nextcloud.talk.utils.singletons.ApplicationWideApiHolder;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
@ -66,6 +65,7 @@ public class CapabilitiesWorker extends Worker {
|
||||
@Inject
|
||||
OkHttpClient okHttpClient;
|
||||
|
||||
@Inject
|
||||
NcApi ncApi;
|
||||
|
||||
private void updateUser(CapabilitiesOverall capabilitiesOverall, UserEntity internalUserEntity) {
|
||||
@ -124,8 +124,6 @@ public class CapabilitiesWorker extends Worker {
|
||||
for (Object userEntityObject : userEntityObjectList) {
|
||||
UserEntity internalUserEntity = (UserEntity) userEntityObject;
|
||||
|
||||
ncApi = ApplicationWideApiHolder.getInstance().getNcApiInstanceForAccountId(internalUserEntity.getId(), null);
|
||||
|
||||
ncApi.getCapabilities(ApiUtils.getCredentials(internalUserEntity.getUsername(),
|
||||
internalUserEntity.getToken()), ApiUtils.getUrlForCapabilities(internalUserEntity.getBaseUrl()))
|
||||
.retry(3)
|
||||
|
@ -60,7 +60,6 @@ import com.nextcloud.talk.utils.PushUtils;
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys;
|
||||
import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||
import com.nextcloud.talk.utils.preferences.AppPreferences;
|
||||
import com.nextcloud.talk.utils.singletons.ApplicationWideApiHolder;
|
||||
import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder;
|
||||
import com.nextcloud.talk.utils.singletons.ApplicationWideStateHolder;
|
||||
|
||||
@ -94,6 +93,7 @@ public class NotificationWorker extends Worker {
|
||||
@Inject
|
||||
AppPreferences appPreferences;
|
||||
|
||||
@Inject
|
||||
NcApi ncApi;
|
||||
|
||||
private DecryptedPushMessage decryptedPushMessage;
|
||||
@ -392,7 +392,6 @@ public class NotificationWorker extends Worker {
|
||||
decryptedPushMessage = LoganSquare.parse(new String(decryptedSubject),
|
||||
DecryptedPushMessage.class);
|
||||
|
||||
ncApi = ApplicationWideApiHolder.getInstance().getNcApiInstanceForAccountId(signatureVerification.getUserEntity().getId(), null);
|
||||
credentials = ApiUtils.getCredentials(signatureVerification.getUserEntity().getUserId(),
|
||||
signatureVerification.getUserEntity().getToken());
|
||||
|
||||
|
@ -34,7 +34,6 @@ import com.nextcloud.talk.models.json.mention.Mention;
|
||||
import com.nextcloud.talk.models.json.mention.MentionOverall;
|
||||
import com.nextcloud.talk.utils.ApiUtils;
|
||||
import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||
import com.nextcloud.talk.utils.singletons.ApplicationWideApiHolder;
|
||||
import com.otaliastudios.autocomplete.RecyclerViewPresenter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -52,7 +51,8 @@ import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
@AutoInjector(NextcloudTalkApplication.class)
|
||||
public class MentionAutocompletePresenter extends RecyclerViewPresenter<Mention> implements FlexibleAdapter.OnItemClickListener {
|
||||
private NcApi ncApi;
|
||||
@Inject
|
||||
NcApi ncApi;
|
||||
private UserEntity currentUser;
|
||||
|
||||
@Inject
|
||||
@ -69,7 +69,7 @@ public class MentionAutocompletePresenter extends RecyclerViewPresenter<Mention>
|
||||
super(context);
|
||||
this.context = context;
|
||||
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
|
||||
setupNcApi();
|
||||
currentUser = userUtils.getCurrentUser();
|
||||
}
|
||||
|
||||
public MentionAutocompletePresenter(Context context, String roomToken) {
|
||||
@ -77,12 +77,7 @@ public class MentionAutocompletePresenter extends RecyclerViewPresenter<Mention>
|
||||
this.roomToken = roomToken;
|
||||
this.context = context;
|
||||
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
|
||||
setupNcApi();
|
||||
}
|
||||
|
||||
private void setupNcApi() {
|
||||
currentUser = userUtils.getCurrentUser();
|
||||
ncApi = ApplicationWideApiHolder.getInstance().getNcApiInstanceForAccountId(currentUser.getId(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,7 +36,6 @@ import com.nextcloud.talk.models.json.push.PushConfigurationState;
|
||||
import com.nextcloud.talk.models.json.push.PushRegistrationOverall;
|
||||
import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||
import com.nextcloud.talk.utils.preferences.AppPreferences;
|
||||
import com.nextcloud.talk.utils.singletons.ApplicationWideApiHolder;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
@ -82,6 +81,7 @@ public class PushUtils {
|
||||
@Inject
|
||||
EventBus eventBus;
|
||||
|
||||
@Inject
|
||||
NcApi ncApi;
|
||||
|
||||
private File keysFile;
|
||||
@ -260,7 +260,6 @@ public class PushUtils {
|
||||
queryMap.put("devicePublicKey", publicKey);
|
||||
queryMap.put("proxyServer", proxyServer);
|
||||
|
||||
ncApi = ApplicationWideApiHolder.getInstance().getNcApiInstanceForAccountId(userEntity.getId(), null);
|
||||
credentials = ApiUtils.getCredentials(userEntity.getUserId(), userEntity.getToken());
|
||||
|
||||
String finalCredentials = credentials;
|
||||
|
@ -1,84 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Talk application
|
||||
*
|
||||
* @author Mario Danic
|
||||
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.nextcloud.talk.utils.singletons;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.nextcloud.talk.api.NcApi;
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||
import com.nextcloud.talk.models.database.UserEntity;
|
||||
import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import autodagger.AutoInjector;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
@AutoInjector(NextcloudTalkApplication.class)
|
||||
public class ApplicationWideApiHolder {
|
||||
private static final String TAG = "ApplicationWideApiHolder";
|
||||
|
||||
@SuppressLint("UseSparseArrays")
|
||||
private Map<Long, NcApi> ncApiHashMap;
|
||||
|
||||
@Inject
|
||||
UserUtils userUtils;
|
||||
|
||||
@Inject
|
||||
Retrofit retrofit;
|
||||
|
||||
private static final ApplicationWideApiHolder holder = new ApplicationWideApiHolder();
|
||||
|
||||
public static ApplicationWideApiHolder getInstance() {
|
||||
return holder;
|
||||
}
|
||||
|
||||
@SuppressLint("UseSparseArrays")
|
||||
public NcApi getNcApiInstanceForAccountId(long accountId, @Nullable String baseUrl) {
|
||||
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
|
||||
|
||||
if (ncApiHashMap == null) {
|
||||
ncApiHashMap = new HashMap<>();
|
||||
}
|
||||
|
||||
if (!ncApiHashMap.containsKey(accountId)) {
|
||||
UserEntity userAccount = userUtils.getUserWithId(accountId);
|
||||
if (userAccount == null || (userAccount.getId() == -1 && !TextUtils.isEmpty(baseUrl))) {
|
||||
retrofit = retrofit.newBuilder().baseUrl(baseUrl).build();
|
||||
return retrofit.create(NcApi.class);
|
||||
} else {
|
||||
retrofit = retrofit.newBuilder().baseUrl(userAccount.getBaseUrl() + "/").build();
|
||||
ncApiHashMap.put(accountId, retrofit.create(NcApi.class));
|
||||
}
|
||||
}
|
||||
|
||||
return ncApiHashMap.get(accountId);
|
||||
}
|
||||
|
||||
public void removeNcApiInstanceForAccountId(long accountId) {
|
||||
ncApiHashMap.remove(accountId);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user