diff --git a/ring-android/app/src/main/java/cx/ring/client/ConversationSelectionActivity.kt b/ring-android/app/src/main/java/cx/ring/client/ConversationSelectionActivity.kt index 673b3cb95aca8885fdd8d38b915bec70154d3fb9..801864f84d8a048b1d55031f408933c29c4e5d1c 100644 --- a/ring-android/app/src/main/java/cx/ring/client/ConversationSelectionActivity.kt +++ b/ring-android/app/src/main/java/cx/ring/client/ConversationSelectionActivity.kt @@ -81,7 +81,7 @@ class ConversationSelectionActivity : AppCompatActivity() { if (conference == null) return@map vm val filteredVms: MutableList<SmartListViewModel> = ArrayList(vm.size) models@ for (v in vm) { - val contact = v.contact ?: continue // We only add contacts and one to one + val contact = v.getContact() ?: continue // We only add contacts and one to one for (call in conference.participants) { if (call.contact === contact) { continue@models diff --git a/ring-android/app/src/main/java/cx/ring/contactrequests/BlockListFragment.kt b/ring-android/app/src/main/java/cx/ring/contactrequests/BlockListFragment.kt index 8512752e90f9d246a29685310092458a12972ae5..082c3c25e9630fd43172a5a8e435c8d0c4e1b601 100644 --- a/ring-android/app/src/main/java/cx/ring/contactrequests/BlockListFragment.kt +++ b/ring-android/app/src/main/java/cx/ring/contactrequests/BlockListFragment.kt @@ -65,12 +65,9 @@ class BlockListFragment : BaseSupportFragment<BlockListPresenter, BlockListView> override fun onResume() { super.onResume() - if (arguments == null || requireArguments().getString(AccountEditionFragment.ACCOUNT_ID_KEY) == null) { - return - } - val mAccountId = requireArguments().getString(AccountEditionFragment.ACCOUNT_ID_KEY) + val accountId = arguments?.getString(AccountEditionFragment.ACCOUNT_ID_KEY) ?: return mOnBackPressedCallback.isEnabled = true - presenter.setAccountId(mAccountId) + presenter.setAccountId(accountId) } override fun onAttach(context: Context) { @@ -102,12 +99,11 @@ class BlockListFragment : BaseSupportFragment<BlockListPresenter, BlockListView> binding!!.placeholder.visibility = if (display) View.VISIBLE else View.GONE } - fun setAccount(accountId: String?) { + fun setAccount(accountId: String) { presenter.setAccountId(accountId) } companion object { - @JvmStatic val TAG: String = BlockListFragment::class.simpleName!! } diff --git a/ring-android/app/src/main/java/cx/ring/tv/contact/TVContactPresenter.kt b/ring-android/app/src/main/java/cx/ring/tv/contact/TVContactPresenter.kt index 31c10e90d02385d33bff856b05bb64c8484a9cec..dea9074838d0923ec039cb923454ffc35ffdca98 100644 --- a/ring-android/app/src/main/java/cx/ring/tv/contact/TVContactPresenter.kt +++ b/ring-android/app/src/main/java/cx/ring/tv/contact/TVContactPresenter.kt @@ -51,7 +51,7 @@ class TVContactPresenter @Inject constructor( mCompositeDisposable.clear() mCompositeDisposable.add(mConversationService .getAccountSubject(path.accountId) - .map { a: Account -> SmartListViewModel(a.getByUri(mUri), true) } + .map { a: Account -> SmartListViewModel(a.getByUri(mUri)!!, true) } .observeOn(mUiScheduler) .subscribe { c: SmartListViewModel -> view!!.showContact(c) }) } diff --git a/ring-android/app/src/main/java/cx/ring/tv/main/MainPresenter.java b/ring-android/app/src/main/java/cx/ring/tv/main/MainPresenter.java deleted file mode 100644 index 98951ac65ba204170a2982fda701bce6d85f2dc3..0000000000000000000000000000000000000000 --- a/ring-android/app/src/main/java/cx/ring/tv/main/MainPresenter.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (C) 2004-2021 Savoir-faire Linux Inc. - * - * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> - * Author: Adrien Béraud <adrien.beraud@savoirfairelinux.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, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -package cx.ring.tv.main; - -import android.util.Log; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import javax.inject.Inject; -import javax.inject.Named; - -import net.jami.services.ConversationFacade; -import net.jami.mvp.RootPresenter; -import net.jami.navigation.HomeNavigationViewModel; -import net.jami.services.AccountService; -import net.jami.smartlist.SmartListViewModel; - -import io.reactivex.rxjava3.core.Observable; -import io.reactivex.rxjava3.core.Scheduler; - -public class MainPresenter extends RootPresenter<MainView> { - - private static final String TAG = MainPresenter.class.getSimpleName(); - - private final AccountService mAccountService; - private final ConversationFacade mConversationFacade; - private final Scheduler mUiScheduler; - - @Inject - public MainPresenter(AccountService accountService, - ConversationFacade conversationFacade, - @Named("UiScheduler") Scheduler uiScheduler) { - mAccountService = accountService; - mConversationFacade = conversationFacade; - mUiScheduler = uiScheduler; - } - - @Override - public void bindView(MainView view) { - super.bindView(view); - loadConversations(); - reloadAccountInfo(); - } - - private void loadConversations() { - getView().showLoading(true); - - mCompositeDisposable.add(mConversationFacade.getSmartList(true) - .switchMap(viewModels -> viewModels.isEmpty() ? SmartListViewModel.EMPTY_RESULTS - : Observable.combineLatest(viewModels, obs -> { - List<SmartListViewModel> vms = new ArrayList<>(obs.length); - for (Object ob : obs) - vms.add((SmartListViewModel) ob); - return vms; - })) - .throttleLatest(150, TimeUnit.MILLISECONDS, mUiScheduler) - .observeOn(mUiScheduler) - .subscribe(viewModels -> { - final MainView view = getView(); - view.showLoading(false); - view.showContacts(viewModels); - }, e -> Log.w(TAG, "showConversations error ", e))); - - mCompositeDisposable.add(mConversationFacade.getPendingList() - .switchMap(viewModels -> viewModels.isEmpty() ? SmartListViewModel.EMPTY_RESULTS - : Observable.combineLatest(viewModels, obs -> { - List<SmartListViewModel> vms = new ArrayList<>(obs.length); - for (Object ob : obs) - vms.add((SmartListViewModel) ob); - return vms; - })) - .throttleLatest(150, TimeUnit.MILLISECONDS, mUiScheduler) - .observeOn(mUiScheduler) - .subscribe(viewModels -> { - final MainView view = getView(); - view.showContactRequests(viewModels); - }, e -> Log.w(TAG, "showConversations error ", e))); - } - - public void reloadAccountInfo() { - mCompositeDisposable.add(mAccountService.getCurrentAccountSubject() - .observeOn(mUiScheduler) - .subscribe( - account -> getView().displayAccountInfo(new HomeNavigationViewModel(account, null)), - e-> Log.d(TAG, "reloadAccountInfos getProfileAccountList onError", e))); - mCompositeDisposable.add(mAccountService.getObservableAccounts() - .observeOn(mUiScheduler) - .subscribe(account -> { - MainView v = getView(); - if (v != null) - v.updateModel(account); - }, e -> Log.e(TAG, "Error loading account list !", e))); - } - - public void onExportClicked() { - getView().showExportDialog(mAccountService.getCurrentAccount().getAccountID(), mAccountService.getCurrentAccount().hasPassword()); - } - - public void onEditProfileClicked() { - getView().showProfileEditing(); - } - - public void onShareAccountClicked() { - getView().showAccountShare(); - } - - public void onSettingsClicked() { - getView().showSettings(); - } - -} \ No newline at end of file diff --git a/ring-android/app/src/main/java/cx/ring/tv/main/MainPresenter.kt b/ring-android/app/src/main/java/cx/ring/tv/main/MainPresenter.kt new file mode 100644 index 0000000000000000000000000000000000000000..78fd9ff6d24624723271885d5a40a8309c3011f2 --- /dev/null +++ b/ring-android/app/src/main/java/cx/ring/tv/main/MainPresenter.kt @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2004-2021 Savoir-faire Linux Inc. + * + * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> + * Author: Adrien Béraud <adrien.beraud@savoirfairelinux.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, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +package cx.ring.tv.main + +import android.util.Log +import io.reactivex.rxjava3.core.Observable +import io.reactivex.rxjava3.core.Scheduler +import net.jami.model.Account +import net.jami.mvp.RootPresenter +import net.jami.navigation.HomeNavigationViewModel +import net.jami.services.AccountService +import net.jami.services.ConversationFacade +import net.jami.smartlist.SmartListViewModel +import java.util.* +import java.util.concurrent.TimeUnit +import javax.inject.Inject +import javax.inject.Named + +class MainPresenter @Inject constructor( + private val mAccountService: AccountService, + private val mConversationFacade: ConversationFacade, + @param:Named("UiScheduler") private val mUiScheduler: Scheduler +) : RootPresenter<MainView>() { + override fun bindView(view: MainView) { + super.bindView(view) + loadConversations() + reloadAccountInfo() + } + + private fun loadConversations() { + view!!.showLoading(true) + mCompositeDisposable.add(mConversationFacade.getSmartList(true) + .switchMap { viewModels: List<Observable<SmartListViewModel>> -> + if (viewModels.isEmpty()) SmartListViewModel.EMPTY_RESULTS + else Observable.combineLatest<SmartListViewModel, List<SmartListViewModel>>(viewModels) + { obs: Array<Any> -> obs.mapTo(ArrayList(obs.size)) { ob -> ob as SmartListViewModel } } + } + .throttleLatest(150, TimeUnit.MILLISECONDS, mUiScheduler) + .observeOn(mUiScheduler) + .subscribe({ viewModels: List<SmartListViewModel> -> + val view = view + view!!.showLoading(false) + view.showContacts(viewModels) + }) { e: Throwable? -> Log.w(TAG, "showConversations error ", e) }) + mCompositeDisposable.add(mConversationFacade.pendingList + .switchMap { viewModels: List<Observable<SmartListViewModel>> -> + if (viewModels.isEmpty()) SmartListViewModel.EMPTY_RESULTS + else Observable.combineLatest<SmartListViewModel, List<SmartListViewModel>>(viewModels) + { obs: Array<Any> -> obs.mapTo(ArrayList(obs.size)) { ob -> ob as SmartListViewModel } } + } + .throttleLatest(150, TimeUnit.MILLISECONDS, mUiScheduler) + .observeOn(mUiScheduler) + .subscribe({ viewModels: List<SmartListViewModel> -> + view?.showContactRequests(viewModels) + }) { e: Throwable -> Log.w(TAG, "showConversations error ", e) }) + } + + fun reloadAccountInfo() { + mCompositeDisposable.add(mAccountService.currentAccountSubject + .observeOn(mUiScheduler) + .subscribe({ account: Account -> view?.displayAccountInfo(HomeNavigationViewModel(account, null)) }) + { e: Throwable -> Log.d(TAG, "reloadAccountInfos getProfileAccountList onError", e) }) + + mCompositeDisposable.add(mAccountService.observableAccounts + .observeOn(mUiScheduler) + .subscribe({ account: Account -> view?.updateModel(account) }) + { e: Throwable -> Log.e(TAG, "Error loading account list !", e) }) + } + + fun onExportClicked() { + view?.showExportDialog(mAccountService.currentAccount!!.accountID, mAccountService.currentAccount!!.hasPassword()) + } + + fun onEditProfileClicked() { + view!!.showProfileEditing() + } + + fun onShareAccountClicked() { + view!!.showAccountShare() + } + + fun onSettingsClicked() { + view?.showSettings() + } + + companion object { + private val TAG = MainPresenter::class.simpleName!! + } +} \ No newline at end of file diff --git a/ring-android/app/src/main/java/cx/ring/viewholders/SmartListViewHolder.kt b/ring-android/app/src/main/java/cx/ring/viewholders/SmartListViewHolder.kt index 6ecfaab133b678adb70eccfed5777e31e7d0dc13..e99b90922eb33164e75bff6c216a2bf791e9f5d6 100644 --- a/ring-android/app/src/main/java/cx/ring/viewholders/SmartListViewHolder.kt +++ b/ring-android/app/src/main/java/cx/ring/viewholders/SmartListViewHolder.kt @@ -82,8 +82,7 @@ class SmartListViewHolder : RecyclerView.ViewHolder { binding.convLastItem.text = itemView.context.getString(R.string.ongoing_call) } else if (smartListViewModel.lastEvent != null) { binding.convLastItem.visibility = View.VISIBLE - binding.convLastItem.text = - getLastEventSummary(smartListViewModel.lastEvent, itemView.context) + binding.convLastItem.text = getLastEventSummary(smartListViewModel.lastEvent!!, itemView.context) } else { binding.convLastItem.visibility = View.GONE } @@ -96,12 +95,10 @@ class SmartListViewHolder : RecyclerView.ViewHolder { binding.convLastTime.setTypeface(null, Typeface.NORMAL) binding.convLastItem.setTypeface(null, Typeface.NORMAL) } - binding.photo.setImageDrawable( - AvatarDrawable.Builder() + binding.photo.setImageDrawable(AvatarDrawable.Builder() .withViewModel(smartListViewModel) .withCircleCrop(true) - .build(binding.photo.context) - ) + .build(binding.photo.context)) } else headerBinding?.headerTitle?.setText( if (smartListViewModel.headerTitle == SmartListViewModel.Title.Conversations) R.string.navigation_item_conversation else R.string.search_results_public_directory ) diff --git a/ring-android/libringclient/src/main/java/net/jami/account/JamiAccountCreationPresenter.kt b/ring-android/libringclient/src/main/java/net/jami/account/JamiAccountCreationPresenter.kt index 315cfaa90586dda982d0836fef52bce7c4708521..0b5e640c9c293453393c1b540a79672e9d049c08 100644 --- a/ring-android/libringclient/src/main/java/net/jami/account/JamiAccountCreationPresenter.kt +++ b/ring-android/libringclient/src/main/java/net/jami/account/JamiAccountCreationPresenter.kt @@ -78,9 +78,9 @@ class JamiAccountCreationPresenter @Inject constructor( } fun registerUsernameChanged(isChecked: Boolean) { - if (mAccountCreationModel != null) { + mAccountCreationModel?.let { model -> if (!isChecked) { - mAccountCreationModel!!.username = "" + model.username = "" } checkForms() } @@ -90,8 +90,8 @@ class JamiAccountCreationPresenter @Inject constructor( if (mAccountCreationModel != null) mAccountCreationModel!!.password = null isPasswordCorrect = true isConfirmCorrect = true - view!!.showInvalidPasswordError(false) - view!!.enableNextButton(true) + view?.showInvalidPasswordError(false) + view?.enableNextButton(true) } fun passwordChanged(password: String, repeat: CharSequence) { diff --git a/ring-android/libringclient/src/main/java/net/jami/contactrequests/BlockListPresenter.java b/ring-android/libringclient/src/main/java/net/jami/contactrequests/BlockListPresenter.java deleted file mode 100644 index ca74a14c6f8146f7680100d686852617b18d8a54..0000000000000000000000000000000000000000 --- a/ring-android/libringclient/src/main/java/net/jami/contactrequests/BlockListPresenter.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2004-2021 Savoir-faire Linux Inc. - * - * Author: Aline Bonnet <aline.bonnet@savoirfairelinux.com> - * Author: Adrien Béraud <adrien.beraud@savoirfairelinux.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 net.jami.contactrequests; - -import java.util.Collection; - -import javax.inject.Inject; -import javax.inject.Named; - -import net.jami.model.Account; -import net.jami.model.Contact; -import net.jami.mvp.RootPresenter; -import net.jami.services.AccountService; -import net.jami.utils.Log; - -import io.reactivex.rxjava3.core.Scheduler; - -public class BlockListPresenter extends RootPresenter<BlockListView> { - static private final String TAG = BlockListPresenter.class.getSimpleName(); - - private final AccountService mAccountService; - private String mAccountID; - - @Inject - @Named("UiScheduler") - protected Scheduler mUiScheduler; - - @Inject - public BlockListPresenter(AccountService accountService) { - mAccountService = accountService; - } - - @Override - public void bindView(BlockListView view) { - super.bindView(view); - if (mAccountID != null) { - setAccountId(mAccountID); - } - } - - @Override - public void unbindView() { - super.unbindView(); - } - - private void updateList(Collection<Contact> list) { - if (getView() == null) { - return; - } - if(list.isEmpty()) { - getView().hideListView(); - getView().displayEmptyListMessage(true); - } else { - getView().updateView(list); - getView().displayEmptyListMessage(false); - } - } - - public void setAccountId(String accountID) { - if (getView() == null) { - return; - } - mCompositeDisposable.clear(); - mCompositeDisposable.add(mAccountService - .getAccountSingle(accountID) - .flatMapObservable(Account::getBannedContactsUpdates) - .observeOn(mUiScheduler) - .subscribe(this::updateList, e -> Log.e(TAG, "Error showing blacklist", e))); - mAccountID = accountID; - } - - public void unblockClicked(Contact contact) { - String contactId = contact.getUri().getRawRingId(); - mAccountService.addContact(mAccountID, contactId); - } -} diff --git a/ring-android/libringclient/src/main/java/net/jami/contactrequests/BlockListPresenter.kt b/ring-android/libringclient/src/main/java/net/jami/contactrequests/BlockListPresenter.kt new file mode 100644 index 0000000000000000000000000000000000000000..6a8b4eb6b5f4f7ebf2d2379863cad9f0f4f43876 --- /dev/null +++ b/ring-android/libringclient/src/main/java/net/jami/contactrequests/BlockListPresenter.kt @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2004-2021 Savoir-faire Linux Inc. + * + * Author: Aline Bonnet <aline.bonnet@savoirfairelinux.com> + * Author: Adrien Béraud <adrien.beraud@savoirfairelinux.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 net.jami.contactrequests + +import io.reactivex.rxjava3.core.Scheduler +import net.jami.contactrequests.BlockListPresenter +import net.jami.model.Account +import net.jami.model.Contact +import net.jami.mvp.RootPresenter +import net.jami.services.AccountService +import net.jami.utils.Log +import javax.inject.Inject +import javax.inject.Named + +class BlockListPresenter @Inject constructor( + private val mAccountService: AccountService, + @param:Named("UiScheduler") private val mUiScheduler: Scheduler +) : RootPresenter<BlockListView>() { + private var mAccountID: String? = null + + override fun bindView(view: BlockListView) { + super.bindView(view) + /*if (mAccountID != null) { + setAccountId(mAccountID) + }*/ + } + + private fun updateList(list: Collection<Contact>) { + if (view == null) { + return + } + if (list.isEmpty()) { + view!!.hideListView() + view!!.displayEmptyListMessage(true) + } else { + view!!.updateView(list) + view!!.displayEmptyListMessage(false) + } + } + + fun setAccountId(accountID: String) { + if (view == null) { + return + } + mCompositeDisposable.clear() + mCompositeDisposable.add(mAccountService + .getAccountSingle(accountID) + .flatMapObservable(Account::bannedContactsUpdates) + .observeOn(mUiScheduler) + .subscribe({ list: Collection<Contact> -> updateList(list) }) { e: Throwable -> + Log.e( + TAG, + "Error showing blacklist", + e + ) + }) + mAccountID = accountID + } + + fun unblockClicked(contact: Contact) { + val contactId = contact.uri.rawRingId + mAccountService.addContact(mAccountID!!, contactId) + } + + companion object { + private val TAG = BlockListPresenter::class.simpleName!! + } +} \ No newline at end of file diff --git a/ring-android/libringclient/src/main/java/net/jami/contactrequests/BlockListView.java b/ring-android/libringclient/src/main/java/net/jami/contactrequests/BlockListView.kt similarity index 75% rename from ring-android/libringclient/src/main/java/net/jami/contactrequests/BlockListView.java rename to ring-android/libringclient/src/main/java/net/jami/contactrequests/BlockListView.kt index 86c2b736e18f86ac7e57a4a81ec80e030fdef8f4..32a608c2301fdd86c040efc7a5c34e5d194969d4 100644 --- a/ring-android/libringclient/src/main/java/net/jami/contactrequests/BlockListView.java +++ b/ring-android/libringclient/src/main/java/net/jami/contactrequests/BlockListView.kt @@ -16,18 +16,12 @@ * 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 net.jami.contactrequests -package net.jami.contactrequests; +import net.jami.model.Contact -import net.jami.model.Contact; - -import java.util.Collection; - -public interface BlockListView { - - void updateView(Collection<Contact> list); - - void hideListView(); - - void displayEmptyListMessage(boolean display); -} +interface BlockListView { + fun updateView(list: Collection<Contact>) + fun hideListView() + fun displayEmptyListMessage(display: Boolean) +} \ No newline at end of file diff --git a/ring-android/libringclient/src/main/java/net/jami/contactrequests/ContactRequestsPresenter.java b/ring-android/libringclient/src/main/java/net/jami/contactrequests/ContactRequestsPresenter.java deleted file mode 100644 index 1a526d962ba51c2002bcaf305f408665ff9b21b6..0000000000000000000000000000000000000000 --- a/ring-android/libringclient/src/main/java/net/jami/contactrequests/ContactRequestsPresenter.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2004-2021 Savoir-faire Linux Inc. - * - * Author: Aline Bonnet <aline.bonnet@savoirfairelinux.com> - * Author: Adrien Béraud <adrien.beraud@savoirfairelinux.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 net.jami.contactrequests; - -import java.util.ArrayList; -import java.util.List; - -import javax.inject.Inject; -import javax.inject.Named; - -import net.jami.services.ConversationFacade; -import net.jami.model.Account; -import net.jami.model.Uri; -import net.jami.mvp.RootPresenter; -import net.jami.services.AccountService; -import net.jami.smartlist.SmartListViewModel; -import net.jami.utils.Log; - -import io.reactivex.rxjava3.core.Observable; -import io.reactivex.rxjava3.core.Scheduler; -import io.reactivex.rxjava3.subjects.BehaviorSubject; - -public class ContactRequestsPresenter extends RootPresenter<net.jami.contactrequests.ContactRequestsView> { - - static private final String TAG = ContactRequestsPresenter.class.getSimpleName(); - - private final Scheduler mUiScheduler; - private final AccountService mAccountService; - private final ConversationFacade mConversationFacade; - private final BehaviorSubject<Account> mAccount = BehaviorSubject.create(); - - @Inject - ContactRequestsPresenter(ConversationFacade conversationFacade, AccountService accountService, @Named("UiScheduler") Scheduler scheduler) { - mConversationFacade = conversationFacade; - mAccountService = accountService; - mUiScheduler = scheduler; - } - - @Override - public void bindView(ContactRequestsView view) { - super.bindView(view); - mCompositeDisposable.add(mConversationFacade.getPendingList(mAccount) - .switchMap(viewModels -> viewModels.isEmpty() ? SmartListViewModel.EMPTY_RESULTS - : Observable.combineLatest(viewModels, obs -> { - List<SmartListViewModel> vms = new ArrayList<>(obs.length); - for (Object ob : obs) - vms.add((SmartListViewModel) ob); - return vms; - })) - .observeOn(mUiScheduler) - .subscribe(viewModels -> getView().updateView(viewModels, mCompositeDisposable), - e -> Log.d(TAG, "updateList subscribe onError", e))); - } - - @Override - public void onDestroy() { - mAccount.onComplete(); - super.onDestroy(); - } - - public void updateAccount(String accountId) { - if (accountId == null) { - mAccountService.getCurrentAccountSubject().subscribe(mAccount); - } else { - mAccount.onNext(mAccountService.getAccount(accountId)); - } - } - - public void contactRequestClicked(String accountId, Uri uri) { - getView().goToConversation(accountId, uri); - } -} diff --git a/ring-android/libringclient/src/main/java/net/jami/contactrequests/ContactRequestsPresenter.kt b/ring-android/libringclient/src/main/java/net/jami/contactrequests/ContactRequestsPresenter.kt new file mode 100644 index 0000000000000000000000000000000000000000..9bc2d51375c604463438fbff4bf464ff6607ad2f --- /dev/null +++ b/ring-android/libringclient/src/main/java/net/jami/contactrequests/ContactRequestsPresenter.kt @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2004-2021 Savoir-faire Linux Inc. + * + * Author: Aline Bonnet <aline.bonnet@savoirfairelinux.com> + * Author: Adrien Béraud <adrien.beraud@savoirfairelinux.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 net.jami.contactrequests + +import io.reactivex.rxjava3.core.Observable +import io.reactivex.rxjava3.core.Scheduler +import io.reactivex.rxjava3.subjects.BehaviorSubject +import net.jami.model.Account +import net.jami.model.Uri +import net.jami.mvp.RootPresenter +import net.jami.services.AccountService +import net.jami.services.ConversationFacade +import net.jami.smartlist.SmartListViewModel +import net.jami.utils.Log +import java.util.* +import javax.inject.Inject +import javax.inject.Named + +class ContactRequestsPresenter @Inject internal constructor( + private val mConversationFacade: ConversationFacade, + private val mAccountService: AccountService, + @param:Named("UiScheduler") private val mUiScheduler: Scheduler +) : RootPresenter<ContactRequestsView>() { + private val mAccount = BehaviorSubject.create<Account>() + override fun bindView(view: ContactRequestsView) { + super.bindView(view) + mCompositeDisposable.add(mConversationFacade.getPendingList(mAccount) + .switchMap { viewModels: List<Observable<SmartListViewModel>> -> + if (viewModels.isEmpty()) SmartListViewModel.EMPTY_RESULTS + else Observable.combineLatest(viewModels) { obs: Array<Any> -> obs.mapTo(ArrayList(obs.size)) + { ob -> ob as SmartListViewModel } } + } + .observeOn(mUiScheduler) + .subscribe({ viewModels -> getView()?.updateView(viewModels, mCompositeDisposable) }) + { e: Throwable -> Log.d(TAG, "updateList subscribe onError", e) }) + } + + override fun onDestroy() { + mAccount.onComplete() + super.onDestroy() + } + + fun updateAccount(accountId: String?) { + mAccountService.getAccount(accountId).let { account -> + if (account == null) { + mAccountService.currentAccountSubject.subscribe(mAccount) + } else { + mAccount.onNext(account) + } + } + } + + fun contactRequestClicked(accountId: String?, uri: Uri?) { + view?.goToConversation(accountId, uri) + } + + companion object { + private val TAG = ContactRequestsPresenter::class.simpleName!! + } +} \ No newline at end of file diff --git a/ring-android/libringclient/src/main/java/net/jami/services/AccountService.kt b/ring-android/libringclient/src/main/java/net/jami/services/AccountService.kt index f6363963d5386a3218d99e3011746f2100208a11..297df6be47aa6fd01e0888a6a993ef35d073dd41 100644 --- a/ring-android/libringclient/src/main/java/net/jami/services/AccountService.kt +++ b/ring-android/libringclient/src/main/java/net/jami/services/AccountService.kt @@ -422,7 +422,7 @@ class AccountService( /** * @return the Account from the local cache that matches the accountId */ - fun getAccount(accountId: String): Account? { + fun getAccount(accountId: String?): Account? { if (!StringUtils.isEmpty(accountId)) { synchronized(mAccountList) { for (account in mAccountList) if (accountId == account.accountID) return account } } diff --git a/ring-android/libringclient/src/main/java/net/jami/smartlist/SmartListViewModel.kt b/ring-android/libringclient/src/main/java/net/jami/smartlist/SmartListViewModel.kt index ded69f43b1ace8197c9d70558313ffd283e9b97f..9e6ab56e8683c8ae52da7e3b70823ef4daef1515 100644 --- a/ring-android/libringclient/src/main/java/net/jami/smartlist/SmartListViewModel.kt +++ b/ring-android/libringclient/src/main/java/net/jami/smartlist/SmartListViewModel.kt @@ -120,7 +120,7 @@ class SmartListViewModel { * Used to get contact for one to one or legacy conversations */ fun getContact(): Contact? { - if (contacts!!.size == 1) return contacts[0] + if (contacts.size == 1) return contacts[0] for (c in contacts) { if (!c.isUser) return c } @@ -166,6 +166,7 @@ class SmartListViewModel { val TITLE_CONVERSATIONS: Observable<SmartListViewModel> = Observable.just(SmartListViewModel(Title.Conversations)) val TITLE_PUBLIC_DIR: Observable<SmartListViewModel> = Observable.just(SmartListViewModel(Title.PublicDirectory)) val EMPTY_LIST: Single<List<Observable<SmartListViewModel>>> = Single.just(emptyList()) + @JvmStatic val EMPTY_RESULTS: Observable<List<SmartListViewModel>> = Observable.just(emptyList()) } } \ No newline at end of file