Open hrayr09amiraghyan opened 4 years ago
Hi! Please provide some code from your project where the issue happens, or share the entire project. We'll see what can be done)
i cant' send you the whole project but i can send some code from my activity and presenter MainTabsActivty
public class MainTabsActivity extends BaseActivity implements MainTabsView { @SuppressLint("ClickableViewAccessibility") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_tabs); ComponentManager.getInstance().getMainTabsComponent().inject(this); removeAllFragments();
if (!presenter.init()) {
return;
}
}
@Override public void openChat(ChatItem chatItem) { //this method open chat we need ChatActivity.showChat(this, chatItem); } }
package com.bluip.behive.ui.maintabs;
import com.bluip.behive.common.base.MvpBaseView; import com.bluip.behive.data.model.clean.badges.Badges; import com.bluip.behive.data.model.clean.chat.ChatItem; import com.bluip.behive.data.model.clean.company.Company; import com.bluip.behive.data.model.clean.favorite.Favorite; import com.bluip.behive.data.model.clean.request.Request; import com.bluip.behive.data.model.clean.task.Task; import com.bluip.behive.data.model.clean.user.User; import com.bluip.behive.data.model.clean.workspace.Workspace;
import java.util.List; import java.util.Set;
import moxy.viewstate.strategy.OneExecutionStateStrategy; import moxy.viewstate.strategy.SkipStrategy; import moxy.viewstate.strategy.StateStrategyType;
@StateStrategyType(OneExecutionStateStrategy.class) public interface MainTabsView extends MvpBaseView {
void selectMessagesTab();
void selectWorkspacesTab();
void selectJoinRequestsTab();
@StateStrategyType(SkipStrategy.class)
void openCreateWorkspacesScreen();
void openFilterScreen();
void openChooseContactScreen();
void openSendInvitationScreen();
@StateStrategyType(SkipStrategy.class)
void openAboutCompanyScreen(Company company)
void openEditTaskScreen(Task task);
void openRequestDetailScreen(Request request);
void openChat(ChatItem chatItem);
void openChat(Workspace workspace);
}
MainTabsPresenter
package com.bluip.behive.ui.maintabs;
import android.Manifest; import android.annotation.SuppressLint; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.support.v4.content.ContextCompat; import android.support.v4.content.LocalBroadcastManager; import android.util.Log;
import com.bluip.behive.AppService; import com.bluip.behive.common.account.AccountSettingsManager; import com.bluip.behive.common.badges.BadgesManager; import com.bluip.behive.common.base.MvpBasePresenter; import com.bluip.behive.common.call.CallManager; import com.bluip.behive.common.paging.PagingManager; import com.bluip.behive.common.paging.PagingService; import com.bluip.behive.common.paging.PagingSessionInfo; import com.bluip.behive.common.paging.PagingSessionType; import com.bluip.behive.common.rxbus.RxBus; import com.bluip.behive.common.rxbus.message.DeleteWorkspaceMessage; import com.bluip.behive.common.rxbus.message.DeletedUserWorkspaceRoleMessage; import com.bluip.behive.common.rxbus.message.ExternalPagingStartedMessage; import com.bluip.behive.common.rxbus.message.InternalPagingStartedMessage; import com.bluip.behive.common.rxbus.message.PagingConnectionStateChangeMessage; import com.bluip.behive.common.rxbus.message.SignalRConnectionStateChangeMessage; import com.bluip.behive.common.signalr.RealTimeUpdateManager; import com.bluip.behive.common.task.TaskLocationListManager; import com.bluip.behive.data.model.clean.company.Company; import com.bluip.behive.data.model.clean.favorite.Favorite; import com.bluip.behive.data.model.clean.user.User; import com.bluip.behive.data.model.clean.user.UserType; import com.bluip.behive.data.model.clean.workspace.Workspace; import com.bluip.behive.data.model.dto.AddFavoriteMessage; import com.bluip.behive.data.model.dto.JoinRequestStatusUpdateMessage; import com.bluip.behive.data.model.dto.MembersListDto; import com.bluip.behive.data.model.dto.NewCompMessage; import com.bluip.behive.data.model.dto.NotifyRoutConfig; import com.bluip.behive.data.model.dto.RemoveFavoriteMessage; import com.bluip.behive.data.model.dto.WorkspaceListDto; import com.bluip.behive.data.repository.NotificationRepo; import com.bluip.behive.data.storage.CompanyListStorage; import com.bluip.behive.data.storage.FavoriteStorage; import com.bluip.behive.domain.ChatInteractor; import com.bluip.behive.domain.CompanyInteractor; import com.bluip.behive.domain.RequestInteractor; import com.bluip.behive.domain.TaskInteractor; import com.bluip.behive.domain.UserInteractor; import com.bluip.behive.ui.authorization.AuthActivity; import com.bluip.behive.ui.company.editcompany.EditCompanyPresenter; import com.bluip.behive.ui.maintabs.creatorjoincompany.createcompany.CreateCompPresenter; import com.bluip.behive.ui.maintabs.creatorjoincompany.joincompany.JoinCompPresenter; import com.bluip.behive.ui.managemembers.sendinvitation.SendInvitationActivity; import com.bluip.behive.ui.splash.SplashActivity; import com.bluip.behive.util.CollectionUtils; import com.bluip.behive.util.Const; import com.bluip.behive.util.HmacSha256Util; import com.bluip.behive.util.StringUtil;
import java.util.ArrayList; import java.util.List;
import javax.inject.Inject;
import io.intercom.android.sdk.Intercom; import io.intercom.android.sdk.identity.Registration; import io.reactivex.Completable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; import moxy.InjectViewState;
@InjectViewState
public class MainTabsPresenter extends MvpBasePresenter
private static final String TAG = "MainTabsPresenter";
private RxBus bus;
private Context context;
private UserInteractor userInteractor;
private CompanyInteractor compInteractor;
private RequestInteractor requestInteractor;
private ChatInteractor chatInteractor;
private TaskInteractor taskInteractor;
private NotificationRepo notificationRepo;
private Integer lastClichedIndex;
private FavoriteStorage favoriteStorage;
private CompanyListStorage companyListStorage;
private RealTimeUpdateManager usersStatusManager;
private PagingManager pagingManager;
private BadgesManager badgesManager;
private AccountSettingsManager accountSettingsManager;
private TaskLocationListManager taskLocationListManager;
private CallManager callManager;
private Disposable pagingConnectionStateChangeMessageDisposable;
private Disposable signalRConnectionStateChangeMessageDisposable;
private Disposable joinRequestStatusUpdateObservable;
public static int CONTACTS_ADD_REQUEST_CODE_PRIMARY = 42;
public static int CONTACTS_ADD_REQUEST_CODE = 4242;
public static int WORKSPACE_ADD_REQUEST_CODE_PRIMARY = 47;
public static int WORKSPACE_ADD_REQUEST_CODE = 4747;
private BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (PagingService.ACTION_PAGING_SERVICE_DESTROYED.equals(intent.getAction())) {
pagingManager.start();
}
}
};
@Inject
MainTabsPresenter(RxBus bus,
Context context,
ChatInteractor chatInteractor,
TaskInteractor taskInteractor,
UserInteractor userInteractor,
CompanyInteractor compInteractor,
FavoriteStorage favoriteStorage,
NotificationRepo notificationRepo,
CompanyListStorage companyListStorage,
RequestInteractor requestInteractor,
PagingManager pagingManager,
BadgesManager badgesManager,
TaskLocationListManager taskLocationListManager,
CallManager callManager,
AccountSettingsManager accountSettingsManager,
RealTimeUpdateManager usersStatusManager) {
this.bus = bus;
this.callManager = callManager;
this.context = context;
this.userInteractor = userInteractor;
this.compInteractor = compInteractor;
this.favoriteStorage = favoriteStorage;
this.requestInteractor = requestInteractor;
this.notificationRepo = notificationRepo;
this.companyListStorage = companyListStorage;
this.usersStatusManager = usersStatusManager;
this.pagingManager = pagingManager;
this.chatInteractor = chatInteractor;
this.badgesManager = badgesManager;
this.accountSettingsManager = accountSettingsManager;
this.taskLocationListManager = taskLocationListManager;
this.taskInteractor = taskInteractor;
}
@Override
protected void onFirstViewAttach() {
super.onFirstViewAttach();
usersStatusManager.start();
callManager.updateAccessToken();
joinRequestStatusUpdateObservable = bus.getJoinRequestStatusUpdateObservable()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::handleJoinRequestStatusUpdate, this::handleError);
Disposable getExternalPagingEvent = bus.getExternalPagingStartedMessageObservable()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::disableCallsDuringExternalPaging, this::handleError);
compositeDisposable.add(getExternalPagingEvent);
context.startService(new Intent(context, AppService.class));
}
@SuppressLint("CheckResult")
@Override
public void attachView(MainTabsView view) {
super.attachView(view);
if (compositeDisposable.isDisposed()) {
compositeDisposable = new CompositeDisposable();
}
Disposable disposable = bus.getAddMembersListObservable()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::handleMembersList,
this::handleError);
compositeDisposable.add(disposable);
Disposable disposable1 = bus.getAddWorkspaceListObservable()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::handleWorkspaceList,
this::handleError);
compositeDisposable.add(disposable1);
Disposable disposable3 = bus.getAddFavoriteObservable()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::handleFavoriteAdd,
this::handleError);
compositeDisposable.add(disposable3);
Disposable disposable4 = bus.getRemoveFavoriteObservable()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::handleFavoriteRemove,
this::handleError);
compositeDisposable.add(disposable4);
Disposable updateWorkspaceDisposable = bus.getUpdateWorkspaceMessageObservable()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(updateWorkspaceMessage -> {
favoriteStorage.updateFavourite(updateWorkspaceMessage.getWorkspace());
if (updateWorkspaceMessage.getWorkspace().isFavorite()) {
getViewState().addFavoriteInPttMenu(new Favorite(updateWorkspaceMessage.getWorkspace().getChatId()));
} else {
getViewState().removeFavoriteInPttMenu(new Favorite(updateWorkspaceMessage.getWorkspace().getChatId()));
}
}, this::handleError);
compositeDisposable.add(updateWorkspaceDisposable);
Disposable disposable5 = bus.getUserUpdateObservable()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(aBoolean -> {
getViewState().setHeaderData(getCurrentUser());
},
this::handleError);
compositeDisposable.add(disposable5);
Disposable disposable6 = bus.getNewCompanyMessageObservable()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::handleCompanyData,
this::handleError);
compositeDisposable.add(disposable6);
Disposable disposable8 = badgesManager.getBadgesObservable()
.subscribe(badges -> {
Company currentCompany = compInteractor.getCurrentCompany();
if (currentCompany != null && currentCompany.isPending()) {
return;
}
getViewState().updateBadges(badges);
}, this::handleError);
compositeDisposable.add(disposable8);
Disposable disposable9 = badgesManager.getBranchBadgesObservable()
.subscribe(badges -> {
Company currentCompany = compInteractor.getCurrentCompany();
if (currentCompany != null && currentCompany.isPending()) {
return;
}
getViewState().updateBranchBadges(badges);
}, this::handleError);
compositeDisposable.add(disposable9);
disableCallDuringPaging();
disableCallsDuringExternalPaging();
pagingManager.start();
badgesManager.update();
taskLocationListManager.update();
accountSettingsManager.getAccountSettings()
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe((accountSettings) -> {
if (accountSettings.getDndType() == 0) {
pagingManager.unmute();
syncFirebaseToken();
} else {
pagingManager.mute();
}
if (accountSettings.getIntercomOptimization() == 1) {
if (userInteractor != null && userInteractor.getCurrentUser() != null) {
registerIntercom(userInteractor.getCurrentUser());
}
}
}, this::handleError);
compositeDisposable.add(inAppMessageDisposable);
getFavorites();
LocalBroadcastManager.getInstance(context).
registerReceiver(receiver, new IntentFilter(PagingService.ACTION_PAGING_SERVICE_DESTROYED));
checkPermissions();
}
public void getUserData() {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
int updatedBranchId = sharedPreferences.getInt(Const.UPDATED_BRANCH_ID, -1);
if (sharedPreferences.getInt(Const.UPDATE_TYPE, -1) == Const.UpdateTypes.ROLE_CHANGED) {
if (compInteractor.getCurrentCompany() == null) {
globalRouter.navigateTo(AuthActivity.TAG);
return;
}
int branchId = compInteractor.getCurrentCompany().getBranchId();
compositeDisposable.add(
userInteractor.getUser(getCurrentUser().getId(), branchId)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(user -> {
if (user.getRoleId() != getCurrentUser().getRoleId()) {
if (compInteractor.getCurrentCompany().getBranchId() == branchId && !compInteractor.getCurrentCompany().isPending()) {
bus.sendReplaceBranchRoleMessage(user.getId(), compInteractor.getCurrentCompany().getBranchId(), user.getRoleId());
}
}
}, throwable -> {
}));
}
// else if (sharedPreferences.getInt(Const.UPDATE_TYPE, -1) == Const.UpdateTypes.REMOVED_FROM_BRANCH) { // subscribeRedirectConfig(); // } else if (sharedPreferences.getInt(Const.UPDATE_TYPE, -1) == Const.UpdateTypes.JOIN_REQUEST_DECLNED) { handleJoinRequestDeclineStatus(compInteractor.getCurrentCompany()); } else if (sharedPreferences.getInt(Const.UPDATE_TYPE, -1) == Const.UpdateTypes.JOIN_REQUEST_ACCEPTED) { handleJoinRequestAcceptedStatus(compInteractor.getCurrentCompany()); } sharedPreferences.edit().putInt(Const.UPDATE_TYPE, -1).apply(); }
@Override
public void detachView(MainTabsView view) {
super.detachView(view);
compositeDisposable.dispose();
}
@Override
public void onDestroy() {
// bus.unsubscribeRedirectConfig(); pagingConnectionStateChangeMessageDisposable.dispose(); signalRConnectionStateChangeMessageDisposable.dispose(); joinRequestStatusUpdateObservable.dispose();
usersStatusManager.stop();
pagingManager.stop();
context.stopService(new Intent(context, PagingService.class));
LocalBroadcastManager.getInstance(context).unregisterReceiver(receiver);
}
@NonNull
private void subscribeRedirectConfig() {
Log.e("NotfyRoutConfig", " : 1");
bus.subscribeOnNotifyRoutConfigObservable(this::handleRedirectConfig);
}
private void handleRedirectConfig(NotifyRoutConfig config) {
switch (config.getNotificationType()) {
case 4:
case 12:
case 14:
case 15:
redirectChat(config); //this redirects to chat page from push notification
break;
}
@SuppressLint("CheckResult")
private void redirectChat(NotifyRoutConfig config) {
if (config.getBranchId() == -1) {
return;
}
Company currentCompany = compInteractor.getCurrentCompany();
if (currentCompany != null && currentCompany.getBranchId() != config.getBranchId()) {
handleSwitchCompany(config.getBranchId());
getViewState().reload();
bus.sendNotifyRoutConfig(config);
return;
}
getViewState().showProgressDialog();
Log.e("NotfyRoutConfig", "handleRedirectConfig: 2 " + config.getChatType() + " " + config.getChatId());
if (config.getChatType() == 2) {
chatInteractor.getChatItemById(config.getChatId())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doAfterTerminate(() -> getViewState().hideProgressDialog())
.subscribe(chatItem -> {
getViewState().openChat(chatItem); //when i debug,debugger comes here an not entering to activity's method to implement it,because we have no viewstate here...
getViewState().selectMessagesTab();
}, this::handleError);
} else if (config.getChatType() == 1) {
userInteractor.getWorkspaceByChatId(config.getChatId())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doAfterTerminate(() -> getViewState().hideProgressDialog())
.subscribe(workspace -> {
getViewState().openChat(workspace);
getViewState().selectWorkspacesTab();
}, this::handleError);
}
}
public boolean init() {
User currentUser = userInteractor.getCurrentUser();
if (currentUser == null) {
globalRouter.navigateTo(SplashActivity.TAG);
return false;
}
getCurrentUserRoles();
List<Company> companyList = new ArrayList<>();
for (Company company : compInteractor.getCompanyList()) {
if (!company.isCurrent()) {
companyList.add(company);
} else {
companyList.add(0, company);
}
}
getViewState().showCompanyList(companyList);
return true;
}
@SuppressLint("CheckResult")
private void getCurrentUserRoles() {
getViewState().showProgressDialog();
Company currentJoinCompany = compInteractor.getCurrentCompany();
if (currentJoinCompany != null) {
if (currentJoinCompany.isPending()) {
getViewState().showPendingMode();
}
}
compInteractor.getCurrentUserRoles()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doAfterTerminate(() -> getViewState().hideProgressDialog())
.subscribe(roleId -> {
User currentUser = userInteractor.getCurrentUser();
if (currentUser != null) {
currentUser.setType(UserType.getTypeById(roleId));
}
Company currentCompany = compInteractor.getCurrentCompany();
if (currentCompany != null) {
if (currentCompany.isPending()) {
getViewState().showPendingMode();
} else {
getViewState().openTasksScreen();
}
}
subscribeRedirectConfig();
},
this::handleError);
}
}
In my project i use Moxy Library to inject View State.When my app is killed and i got a message as a push notification and want to click and redirect to senders page, Viewstate is null and cant implement my Activity's method(which opens the chat)),Can you give me solution to this problem? Thanks