From 63c2063de6730ada17ae495d280c6f7ec7f10ea0 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Sat, 11 Aug 2018 07:37:02 +0200 Subject: [PATCH] More progress on moving to new Retrofit impl Signed-off-by: Mario Danic --- .../talk/controllers/SwitchAccountController.java | 5 ----- .../com/nextcloud/talk/jobs/AccountRemovalWorker.java | 2 +- .../talk/presenters/MentionAutocompletePresenter.java | 11 ++++++++--- .../utils/singletons/ApplicationWideApiHolder.java | 4 ++++ 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/SwitchAccountController.java b/app/src/main/java/com/nextcloud/talk/controllers/SwitchAccountController.java index 2e2a0e129..256d0ef94 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/SwitchAccountController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/SwitchAccountController.java @@ -48,7 +48,6 @@ import com.nextcloud.talk.utils.AccountUtils; import com.nextcloud.talk.utils.bundle.BundleKeys; import com.nextcloud.talk.utils.database.user.UserUtils; -import java.net.CookieManager; import java.util.ArrayList; import java.util.List; @@ -68,9 +67,6 @@ public class SwitchAccountController extends BaseController { @Inject UserUtils userUtils; - @Inject - CookieManager cookieManager; - @BindView(R.id.recycler_view) RecyclerView recyclerView; @@ -109,7 +105,6 @@ public class SwitchAccountController extends BaseController { @Override public void onNext(UserEntity userEntity) { - cookieManager.getCookieStore().removeAll(); userUtils.disableAllUsersWithoutId(userEntity.getId()); if (getActivity() != null) { getActivity().runOnUiThread(new Runnable() { diff --git a/app/src/main/java/com/nextcloud/talk/jobs/AccountRemovalWorker.java b/app/src/main/java/com/nextcloud/talk/jobs/AccountRemovalWorker.java index 5cb8c5143..d453429fc 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/AccountRemovalWorker.java +++ b/app/src/main/java/com/nextcloud/talk/jobs/AccountRemovalWorker.java @@ -83,6 +83,7 @@ public class AccountRemovalWorker extends Worker { PushConfigurationState.class); PushConfigurationState finalPushConfigurationState = pushConfigurationState; + ApplicationWideApiHolder.getInstance().removeNcApiInstanceForAccountId(userEntity.getId()); ncApi = ApplicationWideApiHolder.getInstance().getNcApiInstanceForAccountId(userEntity.getId(), null); credentials = ApiUtils.getCredentials(userEntity.getUserId(), userEntity.getToken()); @@ -139,7 +140,6 @@ public class AccountRemovalWorker extends Worker { @Override public void onComplete() { - } @Override diff --git a/app/src/main/java/com/nextcloud/talk/presenters/MentionAutocompletePresenter.java b/app/src/main/java/com/nextcloud/talk/presenters/MentionAutocompletePresenter.java index 58301e9e3..9202e2e6e 100644 --- a/app/src/main/java/com/nextcloud/talk/presenters/MentionAutocompletePresenter.java +++ b/app/src/main/java/com/nextcloud/talk/presenters/MentionAutocompletePresenter.java @@ -34,6 +34,7 @@ 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; @@ -51,8 +52,8 @@ import io.reactivex.schedulers.Schedulers; @AutoInjector(NextcloudTalkApplication.class) public class MentionAutocompletePresenter extends RecyclerViewPresenter implements FlexibleAdapter.OnItemClickListener { - @Inject - NcApi ncApi; + private NcApi ncApi; + private UserEntity currentUser; @Inject UserUtils userUtils; @@ -77,6 +78,11 @@ public class MentionAutocompletePresenter extends RecyclerViewPresenter NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); } + private void setupNcApi() { + currentUser = userUtils.getCurrentUser(); + ncApi = ApplicationWideApiHolder.getInstance().getNcApiInstanceForAccountId(currentUser.getId(), null); + } + @Override protected RecyclerView.Adapter instantiateAdapter() { adapter = new FlexibleAdapter<>(abstractFlexibleItemList, context, false); @@ -87,7 +93,6 @@ public class MentionAutocompletePresenter extends RecyclerViewPresenter @Override protected void onQuery(@Nullable CharSequence query) { if (!TextUtils.isEmpty(query)) { - UserEntity currentUser = userUtils.getCurrentUser(); adapter.setFilter(query.toString()); ncApi.getMentionAutocompleteSuggestions(ApiUtils.getCredentials(currentUser.getUserId(), currentUser diff --git a/app/src/main/java/com/nextcloud/talk/utils/singletons/ApplicationWideApiHolder.java b/app/src/main/java/com/nextcloud/talk/utils/singletons/ApplicationWideApiHolder.java index c65991879..660567ee1 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/singletons/ApplicationWideApiHolder.java +++ b/app/src/main/java/com/nextcloud/talk/utils/singletons/ApplicationWideApiHolder.java @@ -77,4 +77,8 @@ public class ApplicationWideApiHolder { return ncApiHashMap.get(accountId); } + + public void removeNcApiInstanceForAccountId(long accountId) { + ncApiHashMap.remove(accountId); + } }