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 all 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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
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
Loading