Skip to content
Snippets Groups Projects
Commit 7f843142 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

more Kotlin migration

Change-Id: Iffcb9ba2b1cae7c6bd550ccdf9da6f4b49763480
parent 9c961bd9
Branches
Tags
No related merge requests found
Showing
with 291 additions and 254 deletions
...@@ -81,7 +81,7 @@ class ConversationSelectionActivity : AppCompatActivity() { ...@@ -81,7 +81,7 @@ class ConversationSelectionActivity : AppCompatActivity() {
if (conference == null) return@map vm if (conference == null) return@map vm
val filteredVms: MutableList<SmartListViewModel> = ArrayList(vm.size) val filteredVms: MutableList<SmartListViewModel> = ArrayList(vm.size)
models@ for (v in vm) { 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) { for (call in conference.participants) {
if (call.contact === contact) { if (call.contact === contact) {
continue@models continue@models
......
...@@ -65,12 +65,9 @@ class BlockListFragment : BaseSupportFragment<BlockListPresenter, BlockListView> ...@@ -65,12 +65,9 @@ class BlockListFragment : BaseSupportFragment<BlockListPresenter, BlockListView>
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
if (arguments == null || requireArguments().getString(AccountEditionFragment.ACCOUNT_ID_KEY) == null) { val accountId = arguments?.getString(AccountEditionFragment.ACCOUNT_ID_KEY) ?: return
return
}
val mAccountId = requireArguments().getString(AccountEditionFragment.ACCOUNT_ID_KEY)
mOnBackPressedCallback.isEnabled = true mOnBackPressedCallback.isEnabled = true
presenter.setAccountId(mAccountId) presenter.setAccountId(accountId)
} }
override fun onAttach(context: Context) { override fun onAttach(context: Context) {
...@@ -102,12 +99,11 @@ class BlockListFragment : BaseSupportFragment<BlockListPresenter, BlockListView> ...@@ -102,12 +99,11 @@ class BlockListFragment : BaseSupportFragment<BlockListPresenter, BlockListView>
binding!!.placeholder.visibility = if (display) View.VISIBLE else View.GONE binding!!.placeholder.visibility = if (display) View.VISIBLE else View.GONE
} }
fun setAccount(accountId: String?) { fun setAccount(accountId: String) {
presenter.setAccountId(accountId) presenter.setAccountId(accountId)
} }
companion object { companion object {
@JvmStatic
val TAG: String = BlockListFragment::class.simpleName!! val TAG: String = BlockListFragment::class.simpleName!!
} }
......
...@@ -51,7 +51,7 @@ class TVContactPresenter @Inject constructor( ...@@ -51,7 +51,7 @@ class TVContactPresenter @Inject constructor(
mCompositeDisposable.clear() mCompositeDisposable.clear()
mCompositeDisposable.add(mConversationService mCompositeDisposable.add(mConversationService
.getAccountSubject(path.accountId) .getAccountSubject(path.accountId)
.map { a: Account -> SmartListViewModel(a.getByUri(mUri), true) } .map { a: Account -> SmartListViewModel(a.getByUri(mUri)!!, true) }
.observeOn(mUiScheduler) .observeOn(mUiScheduler)
.subscribe { c: SmartListViewModel -> view!!.showContact(c) }) .subscribe { c: SmartListViewModel -> view!!.showContact(c) })
} }
......
/*
* 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
/*
* 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
...@@ -82,8 +82,7 @@ class SmartListViewHolder : RecyclerView.ViewHolder { ...@@ -82,8 +82,7 @@ class SmartListViewHolder : RecyclerView.ViewHolder {
binding.convLastItem.text = itemView.context.getString(R.string.ongoing_call) binding.convLastItem.text = itemView.context.getString(R.string.ongoing_call)
} else if (smartListViewModel.lastEvent != null) { } else if (smartListViewModel.lastEvent != null) {
binding.convLastItem.visibility = View.VISIBLE binding.convLastItem.visibility = View.VISIBLE
binding.convLastItem.text = binding.convLastItem.text = getLastEventSummary(smartListViewModel.lastEvent!!, itemView.context)
getLastEventSummary(smartListViewModel.lastEvent, itemView.context)
} else { } else {
binding.convLastItem.visibility = View.GONE binding.convLastItem.visibility = View.GONE
} }
...@@ -96,12 +95,10 @@ class SmartListViewHolder : RecyclerView.ViewHolder { ...@@ -96,12 +95,10 @@ class SmartListViewHolder : RecyclerView.ViewHolder {
binding.convLastTime.setTypeface(null, Typeface.NORMAL) binding.convLastTime.setTypeface(null, Typeface.NORMAL)
binding.convLastItem.setTypeface(null, Typeface.NORMAL) binding.convLastItem.setTypeface(null, Typeface.NORMAL)
} }
binding.photo.setImageDrawable( binding.photo.setImageDrawable(AvatarDrawable.Builder()
AvatarDrawable.Builder()
.withViewModel(smartListViewModel) .withViewModel(smartListViewModel)
.withCircleCrop(true) .withCircleCrop(true)
.build(binding.photo.context) .build(binding.photo.context))
)
} else headerBinding?.headerTitle?.setText( } else headerBinding?.headerTitle?.setText(
if (smartListViewModel.headerTitle == SmartListViewModel.Title.Conversations) R.string.navigation_item_conversation else R.string.search_results_public_directory if (smartListViewModel.headerTitle == SmartListViewModel.Title.Conversations) R.string.navigation_item_conversation else R.string.search_results_public_directory
) )
......
...@@ -78,9 +78,9 @@ class JamiAccountCreationPresenter @Inject constructor( ...@@ -78,9 +78,9 @@ class JamiAccountCreationPresenter @Inject constructor(
} }
fun registerUsernameChanged(isChecked: Boolean) { fun registerUsernameChanged(isChecked: Boolean) {
if (mAccountCreationModel != null) { mAccountCreationModel?.let { model ->
if (!isChecked) { if (!isChecked) {
mAccountCreationModel!!.username = "" model.username = ""
} }
checkForms() checkForms()
} }
...@@ -90,8 +90,8 @@ class JamiAccountCreationPresenter @Inject constructor( ...@@ -90,8 +90,8 @@ class JamiAccountCreationPresenter @Inject constructor(
if (mAccountCreationModel != null) mAccountCreationModel!!.password = null if (mAccountCreationModel != null) mAccountCreationModel!!.password = null
isPasswordCorrect = true isPasswordCorrect = true
isConfirmCorrect = true isConfirmCorrect = true
view!!.showInvalidPasswordError(false) view?.showInvalidPasswordError(false)
view!!.enableNextButton(true) view?.enableNextButton(true)
} }
fun passwordChanged(password: String, repeat: CharSequence) { fun passwordChanged(password: String, repeat: CharSequence) {
......
...@@ -17,78 +17,69 @@ ...@@ -17,78 +17,69 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.jami.contactrequests
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
import java.util.Collection; class BlockListPresenter @Inject constructor(
private val mAccountService: AccountService,
@param:Named("UiScheduler") private val mUiScheduler: Scheduler
) : RootPresenter<BlockListView>() {
private var mAccountID: String? = null
import javax.inject.Inject; override fun bindView(view: BlockListView) {
import javax.inject.Named; super.bindView(view)
/*if (mAccountID != null) {
import net.jami.model.Account; setAccountId(mAccountID)
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 private fun updateList(list: Collection<Contact>) {
public void bindView(BlockListView view) { if (view == null) {
super.bindView(view); return
if (mAccountID != null) {
setAccountId(mAccountID);
}
}
@Override
public void unbindView() {
super.unbindView();
}
private void updateList(Collection<Contact> list) {
if (getView() == null) {
return;
} }
if (list.isEmpty()) { if (list.isEmpty()) {
getView().hideListView(); view!!.hideListView()
getView().displayEmptyListMessage(true); view!!.displayEmptyListMessage(true)
} else { } else {
getView().updateView(list); view!!.updateView(list)
getView().displayEmptyListMessage(false); view!!.displayEmptyListMessage(false)
} }
} }
public void setAccountId(String accountID) { fun setAccountId(accountID: String) {
if (getView() == null) { if (view == null) {
return; return
} }
mCompositeDisposable.clear(); mCompositeDisposable.clear()
mCompositeDisposable.add(mAccountService mCompositeDisposable.add(mAccountService
.getAccountSingle(accountID) .getAccountSingle(accountID)
.flatMapObservable(Account::getBannedContactsUpdates) .flatMapObservable(Account::bannedContactsUpdates)
.observeOn(mUiScheduler) .observeOn(mUiScheduler)
.subscribe(this::updateList, e -> Log.e(TAG, "Error showing blacklist", e))); .subscribe({ list: Collection<Contact> -> updateList(list) }) { e: Throwable ->
mAccountID = accountID; Log.e(
TAG,
"Error showing blacklist",
e
)
})
mAccountID = accountID
}
fun unblockClicked(contact: Contact) {
val contactId = contact.uri.rawRingId
mAccountService.addContact(mAccountID!!, contactId)
} }
public void unblockClicked(Contact contact) { companion object {
String contactId = contact.getUri().getRawRingId(); private val TAG = BlockListPresenter::class.simpleName!!
mAccountService.addContact(mAccountID, contactId);
} }
} }
\ No newline at end of file
...@@ -16,18 +16,12 @@ ...@@ -16,18 +16,12 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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; interface BlockListView {
fun updateView(list: Collection<Contact>)
import java.util.Collection; fun hideListView()
fun displayEmptyListMessage(display: Boolean)
public interface BlockListView {
void updateView(Collection<Contact> list);
void hideListView();
void displayEmptyListMessage(boolean display);
} }
\ No newline at end of file
/*
* 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);
}
}
/*
* 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
...@@ -422,7 +422,7 @@ class AccountService( ...@@ -422,7 +422,7 @@ class AccountService(
/** /**
* @return the Account from the local cache that matches the accountId * @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)) { if (!StringUtils.isEmpty(accountId)) {
synchronized(mAccountList) { for (account in mAccountList) if (accountId == account.accountID) return account } synchronized(mAccountList) { for (account in mAccountList) if (accountId == account.accountID) return account }
} }
......
...@@ -120,7 +120,7 @@ class SmartListViewModel { ...@@ -120,7 +120,7 @@ class SmartListViewModel {
* Used to get contact for one to one or legacy conversations * Used to get contact for one to one or legacy conversations
*/ */
fun getContact(): Contact? { fun getContact(): Contact? {
if (contacts!!.size == 1) return contacts[0] if (contacts.size == 1) return contacts[0]
for (c in contacts) { for (c in contacts) {
if (!c.isUser) return c if (!c.isUser) return c
} }
...@@ -166,6 +166,7 @@ class SmartListViewModel { ...@@ -166,6 +166,7 @@ class SmartListViewModel {
val TITLE_CONVERSATIONS: Observable<SmartListViewModel> = Observable.just(SmartListViewModel(Title.Conversations)) val TITLE_CONVERSATIONS: Observable<SmartListViewModel> = Observable.just(SmartListViewModel(Title.Conversations))
val TITLE_PUBLIC_DIR: Observable<SmartListViewModel> = Observable.just(SmartListViewModel(Title.PublicDirectory)) val TITLE_PUBLIC_DIR: Observable<SmartListViewModel> = Observable.just(SmartListViewModel(Title.PublicDirectory))
val EMPTY_LIST: Single<List<Observable<SmartListViewModel>>> = Single.just(emptyList()) val EMPTY_LIST: Single<List<Observable<SmartListViewModel>>> = Single.just(emptyList())
@JvmStatic
val EMPTY_RESULTS: Observable<List<SmartListViewModel>> = Observable.just(emptyList()) val EMPTY_RESULTS: Observable<List<SmartListViewModel>> = Observable.just(emptyList())
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment