Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

make Widget/Integration mgr optional (#3224) #3235

Merged
merged 4 commits into from
Aug 1, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ MatrixSdk:
- Changelog: https://github.com/matrix-org/matrix-android-sdk/releases/tag/v0.XX

Features:
-
- Make Widget/Integration Manager optional (#3224)

Improvements:
-
Expand Down
7 changes: 6 additions & 1 deletion vector/src/main/java/im/vector/Matrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright 2016 OpenMarket Ltd
* Copyright 2017 Vector Creations Ltd
* Copyright 2018 New Vector Ltd
* Copyright 2019 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -74,6 +75,7 @@
import im.vector.tools.VectorUncaughtExceptionHandler;
import im.vector.ui.badge.BadgeProxy;
import im.vector.util.PreferencesManager;
import im.vector.widgets.WidgetManagerProvider;
import im.vector.widgets.WidgetsManager;

/**
Expand Down Expand Up @@ -131,7 +133,10 @@ public void onLiveEvent(Event event, RoomState roomState) {
mRefreshUnreadCounter |= Event.EVENT_TYPE_MESSAGE.equals(event.getType()) || Event.EVENT_TYPE_RECEIPT.equals(event.getType());

// TODO update to manage multisessions
WidgetsManager.getSharedInstance().onLiveEvent(instance.getDefaultSession(), event);
WidgetsManager wm = WidgetManagerProvider.INSTANCE.getWidgetManager(VectorApp.getInstance().getApplicationContext());
if (wm != null) {
wm.onLiveEvent(instance.getDefaultSession(), event);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import im.vector.types.JsonDict
import im.vector.types.WidgetEventData
import im.vector.util.AssetReader
import im.vector.util.toJsonMap
import im.vector.widgets.WidgetManagerProvider
import im.vector.widgets.WidgetsManager
import org.matrix.androidsdk.MXSession
import org.matrix.androidsdk.core.JsonUtils
Expand Down Expand Up @@ -76,6 +77,7 @@ abstract class AbstractWidgetActivity : VectorAppCompatActivity() {
private var mHistoryAlreadyCleared = false


lateinit var widgetManager : WidgetsManager
/* ==========================================================================================
* LIFE CYCLE
* ========================================================================================== */
Expand All @@ -94,14 +96,19 @@ abstract class AbstractWidgetActivity : VectorAppCompatActivity() {

mRoom = mSession!!.dataHandler.getRoom(intent.getStringExtra(EXTRA_ROOM_ID))

widgetManager = WidgetManagerProvider.getWidgetManager(this) ?: run {
finish()
return
}

getScalarTokenAndLoadUrl()
}

private fun getScalarTokenAndLoadUrl() {
if (canScalarTokenBeProvided()) {
showWaitingView()

WidgetsManager.getScalarToken(this, mSession!!, object : ApiCallback<String> {
widgetManager.getScalarToken(this, mSession!!, object : ApiCallback<String> {
override fun onSuccess(scalarToken: String) {
mIsRefreshingToken = false
hideWaitingView()
Expand Down Expand Up @@ -205,7 +212,7 @@ abstract class AbstractWidgetActivity : VectorAppCompatActivity() {
&& !mTokenAlreadyRefreshed) {
mTokenAlreadyRefreshed = true
mIsRefreshingToken = true
WidgetsManager.clearScalarToken(this@AbstractWidgetActivity, mSession)
widgetManager.clearScalarToken(this@AbstractWidgetActivity, mSession)

// Hide the webview because it's displaying an error message we try to fix by refreshing the token
mWebView.isVisible = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class IntegrationManagerActivity : AbstractWidgetActivity() {
*/
override fun buildInterfaceUrl(scalarToken: String?): String? {
try {
return StringBuilder(getString(R.string.integrations_ui_url))
return StringBuilder(widgetManager.uiUrl)
.apply {
scalarToken?.let {
appendParamToUrl("scalar_token", it)
Expand Down Expand Up @@ -259,7 +259,7 @@ class IntegrationManagerActivity : AbstractWidgetActivity() {

Log.d(LOG_TAG, "Received request to get widget in room " + mRoom!!.roomId)

val widgets = WidgetsManager.getSharedInstance().getActiveWidgets(mSession, mRoom)
val widgets = widgetManager.getActiveWidgets(mSession, mRoom)
val responseData = ArrayList<JsonDict<Any>>()

for (widget in widgets) {
Expand Down
15 changes: 13 additions & 2 deletions vector/src/main/java/im/vector/activity/JitsiCallActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import im.vector.Matrix;
import im.vector.R;
import im.vector.widgets.Widget;
import im.vector.widgets.WidgetManagerProvider;
import im.vector.widgets.WidgetsManager;

/**
Expand Down Expand Up @@ -108,6 +109,10 @@ public int getLayoutRes() {
@Override
@SuppressLint("NewApi")
public void initUiAndData() {
if (WidgetManagerProvider.INSTANCE.getWidgetManager(this) == null) {
finish();
return;
}
// Waiting View
setWaitingView(findViewById(R.id.jitsi_progress_layout));

Expand Down Expand Up @@ -232,7 +237,10 @@ public void onNewIntent(Intent intent) {
protected void onStop() {
super.onStop();
JitsiMeetActivityDelegate.onHostPause(this);
WidgetsManager.removeListener(mWidgetListener);
WidgetsManager wm = WidgetManagerProvider.INSTANCE.getWidgetManager(this);
if (wm != null) {
wm.removeListener(mWidgetListener);
}
}

@Override
Expand All @@ -245,7 +253,10 @@ protected void onResume() {
super.onResume();

JitsiMeetActivityDelegate.onHostResume(this);
WidgetsManager.addListener(mWidgetListener);
WidgetsManager wm = WidgetManagerProvider.INSTANCE.getWidgetManager(this);
if (wm != null) {
wm.addListener(mWidgetListener);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class StickerPickerActivity : AbstractWidgetActivity() {
}

override fun canScalarTokenBeProvided(): Boolean {
return WidgetsManager.isScalarUrl(this, mWidgetUrl)
return widgetManager.isScalarUrl(this, mWidgetUrl)
}

/**
Expand Down
168 changes: 95 additions & 73 deletions vector/src/main/java/im/vector/activity/VectorRoomActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright 2015 OpenMarket Ltd
* Copyright 2017 Vector Creations Ltd
* Copyright 2018 New Vector Ltd
* Copyright 2019 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -134,6 +135,7 @@
import im.vector.view.VectorOngoingConferenceCallView;
import im.vector.view.VectorPendingCallView;
import im.vector.widgets.Widget;
import im.vector.widgets.WidgetManagerProvider;
import im.vector.widgets.WidgetsManager;

/**
Expand Down Expand Up @@ -860,34 +862,37 @@ public void onCloseWidgetClick(final Widget widget) {
.setPositiveButton(R.string.remove, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
showWaitingView();
WidgetsManager wm = WidgetManagerProvider.INSTANCE.getWidgetManager(VectorRoomActivity.this);
if (wm != null) {
showWaitingView();

WidgetsManager.getSharedInstance().closeWidget(mSession, mRoom, widget.getWidgetId(), new ApiCallback<Void>() {
@Override
public void onSuccess(Void info) {
hideWaitingView();
}
wm.closeWidget(mSession, mRoom, widget.getWidgetId(), new ApiCallback<Void>() {
@Override
public void onSuccess(Void info) {
hideWaitingView();
}

private void onError(String errorMessage) {
hideWaitingView();
Toast.makeText(VectorRoomActivity.this, errorMessage, Toast.LENGTH_SHORT).show();
}
private void onError(String errorMessage) {
hideWaitingView();
Toast.makeText(VectorRoomActivity.this, errorMessage, Toast.LENGTH_SHORT).show();
}

@Override
public void onNetworkError(Exception e) {
onError(e.getLocalizedMessage());
}
@Override
public void onNetworkError(Exception e) {
onError(e.getLocalizedMessage());
}

@Override
public void onMatrixError(MatrixError e) {
onError(e.getLocalizedMessage());
}
@Override
public void onMatrixError(MatrixError e) {
onError(e.getLocalizedMessage());
}

@Override
public void onUnexpectedError(Exception e) {
onError(e.getLocalizedMessage());
}
});
@Override
public void onUnexpectedError(Exception e) {
onError(e.getLocalizedMessage());
}
});
}
}
})
.setNegativeButton(R.string.cancel, null)
Expand Down Expand Up @@ -962,34 +967,37 @@ public void onVideoCallClick(Widget widget) {

@Override
public void onCloseWidgetClick(Widget widget) {
showWaitingView();
WidgetsManager wm = WidgetManagerProvider.INSTANCE.getWidgetManager(VectorRoomActivity.this);
if (wm != null) {
showWaitingView();

WidgetsManager.getSharedInstance().closeWidget(mSession, mRoom, widget.getWidgetId(), new ApiCallback<Void>() {
@Override
public void onSuccess(Void info) {
hideWaitingView();
}
wm.closeWidget(mSession, mRoom, widget.getWidgetId(), new ApiCallback<Void>() {
@Override
public void onSuccess(Void info) {
hideWaitingView();
}

private void onError(String errorMessage) {
hideWaitingView();
Toast.makeText(VectorRoomActivity.this, errorMessage, Toast.LENGTH_SHORT).show();
}
private void onError(String errorMessage) {
hideWaitingView();
Toast.makeText(VectorRoomActivity.this, errorMessage, Toast.LENGTH_SHORT).show();
}

@Override
public void onNetworkError(Exception e) {
onError(e.getLocalizedMessage());
}
@Override
public void onNetworkError(Exception e) {
onError(e.getLocalizedMessage());
}

@Override
public void onMatrixError(MatrixError e) {
onError(e.getLocalizedMessage());
}
@Override
public void onMatrixError(MatrixError e) {
onError(e.getLocalizedMessage());
}

@Override
public void onUnexpectedError(Exception e) {
onError(e.getLocalizedMessage());
}
});
@Override
public void onUnexpectedError(Exception e) {
onError(e.getLocalizedMessage());
}
});
}
}

@Override
Expand Down Expand Up @@ -1483,6 +1491,8 @@ public boolean onPrepareOptionsMenu(Menu menu) {
return true;
}

boolean hasIntegrationManager = WidgetManagerProvider.INSTANCE.getWidgetManager(this) != null;

// the menu is only displayed when the current activity does not display a timeline search
if (TextUtils.isEmpty(mEventId) && (null == sRoomPreviewData)) {
RoomMember member = mRoom.getMember(mSession.getMyUserId());
Expand All @@ -1492,7 +1502,7 @@ public boolean onPrepareOptionsMenu(Menu menu) {
searchInRoomMenuItem.setVisible(!mRoom.isEncrypted());
}
if (useMatrixAppsMenuItem != null) {
useMatrixAppsMenuItem.setVisible(TextUtils.isEmpty(mEventId) && null == sRoomPreviewData);
useMatrixAppsMenuItem.setVisible(hasIntegrationManager && TextUtils.isEmpty(mEventId) && null == sRoomPreviewData);
}
if (resendUnsentMenuItem != null) {
resendUnsentMenuItem.setVisible(mHasUnsentEvents);
Expand Down Expand Up @@ -1761,37 +1771,40 @@ private void launchJitsiActivity(Widget widget, boolean aIsVideoCall) {
* @param aIsVideoCall true if the call is a video one
*/
private void startJitsiCall(final boolean aIsVideoCall) {
enableActionBarHeader(HIDE_ACTION_BAR_HEADER);
showWaitingView();
WidgetsManager wm = WidgetManagerProvider.INSTANCE.getWidgetManager(this);
if (wm != null) {
enableActionBarHeader(HIDE_ACTION_BAR_HEADER);
showWaitingView();

WidgetsManager.getSharedInstance().createJitsiWidget(mSession, mRoom, aIsVideoCall, new ApiCallback<Widget>() {
@Override
public void onSuccess(Widget widget) {
hideWaitingView();
wm.createJitsiWidget(mSession, mRoom, aIsVideoCall, new ApiCallback<Widget>() {
@Override
public void onSuccess(Widget widget) {
hideWaitingView();

launchJitsiActivity(widget, aIsVideoCall);
}
launchJitsiActivity(widget, aIsVideoCall);
}

private void onError(String errorMessage) {
hideWaitingView();
Toast.makeText(VectorRoomActivity.this, errorMessage, Toast.LENGTH_SHORT).show();
}
private void onError(String errorMessage) {
hideWaitingView();
Toast.makeText(VectorRoomActivity.this, errorMessage, Toast.LENGTH_SHORT).show();
}

@Override
public void onNetworkError(Exception e) {
onError(e.getLocalizedMessage());
}
@Override
public void onNetworkError(Exception e) {
onError(e.getLocalizedMessage());
}

@Override
public void onMatrixError(MatrixError e) {
onError(e.getLocalizedMessage());
}
@Override
public void onMatrixError(MatrixError e) {
onError(e.getLocalizedMessage());
}

@Override
public void onUnexpectedError(Exception e) {
onError(e.getLocalizedMessage());
}
});
@Override
public void onUnexpectedError(Exception e) {
onError(e.getLocalizedMessage());
}
});
}
}

/**
Expand Down Expand Up @@ -3842,7 +3855,9 @@ private void chooseMediaSource(boolean useNativeCamera, boolean isVoiceFeatureEn
}

// Send sticker
items.add(DialogListItem.SendSticker.INSTANCE);
if (WidgetManagerProvider.INSTANCE.getWidgetManager(this) != null) {
items.add(DialogListItem.SendSticker.INSTANCE);
}

// Camera
if (useNativeCamera) {
Expand Down Expand Up @@ -3978,6 +3993,13 @@ void onStartCallClick() {
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(R.string.ok, null)
.show();
} else if (WidgetManagerProvider.INSTANCE.getWidgetManager(this) == null) {
// display the dialog with the info text
new AlertDialog.Builder(this)
.setMessage(R.string.widget_integration_no_server)
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(R.string.ok, null)
.show();
} else if (isUserAllowedToStartConfCall()) {
if (mRoom.getNumberOfMembers() > 2) {
new AlertDialog.Builder(this)
Expand Down
Loading