|
|
|
@@ -61,6 +61,7 @@ import org.thoughtcrime.securesms.util.Util;
|
|
|
|
|
public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcEventDelegate {
|
|
|
|
|
private static final String TAG = "WebxdcActivity";
|
|
|
|
|
private static final String EXTRA_ACCOUNT_ID = "accountId";
|
|
|
|
|
private static final String EXTRA_CHAT_ID = "chatId";
|
|
|
|
|
private static final String EXTRA_APP_MSG_ID = "appMessageId";
|
|
|
|
|
private static final String EXTRA_HIDE_ACTION_BAR = "hideActionBar";
|
|
|
|
|
private static final String EXTRA_HREF = "href";
|
|
|
|
@@ -71,6 +72,7 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE
|
|
|
|
|
private DcContext dcContext;
|
|
|
|
|
private int accountId;
|
|
|
|
|
private Rpc rpc;
|
|
|
|
|
private int chatId;
|
|
|
|
|
private DcMsg dcAppMsg;
|
|
|
|
|
private String baseURL;
|
|
|
|
|
private String sourceCodeUrl = "";
|
|
|
|
@@ -112,7 +114,7 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE
|
|
|
|
|
}
|
|
|
|
|
dcContext.setConfigInt("ui.maps_version", mapsVersion);
|
|
|
|
|
}
|
|
|
|
|
openWebxdcActivity(context, msgId, true, href);
|
|
|
|
|
openWebxdcActivity(context, msgId, chatId, true, href);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void openWebxdcActivity(Context context, DcMsg instance) {
|
|
|
|
@@ -120,18 +122,18 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void openWebxdcActivity(Context context, @NonNull DcMsg instance, String href) {
|
|
|
|
|
openWebxdcActivity(context, instance.getId(), false, href);
|
|
|
|
|
openWebxdcActivity(context, instance.getId(), instance.getChatId(), false, href);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void openWebxdcActivity(
|
|
|
|
|
Context context, int msgId, boolean hideActionBar, String href) {
|
|
|
|
|
Context context, int msgId, int chatId, boolean hideActionBar, String href) {
|
|
|
|
|
if (!Util.isClickedRecently()) {
|
|
|
|
|
context.startActivity(getWebxdcIntent(context, msgId, hideActionBar, href));
|
|
|
|
|
context.startActivity(getWebxdcIntent(context, msgId, chatId, hideActionBar, href));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Intent getWebxdcIntent(
|
|
|
|
|
Context context, int msgId, boolean hideActionBar, String href) {
|
|
|
|
|
Context context, int msgId, int chatId, boolean hideActionBar, String href) {
|
|
|
|
|
DcContext dcContext = DcHelper.getContext(context);
|
|
|
|
|
int accountId = dcContext.getAccountId();
|
|
|
|
|
Intent intent = new Intent(context, WebxdcActivity.class);
|
|
|
|
@@ -139,6 +141,7 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE
|
|
|
|
|
// Unique URI per webxdc instance so FLAG_ACTIVITY_NEW_DOCUMENT can identify the document:
|
|
|
|
|
intent.setData(Uri.parse("webxdc://" + accountId + "/" + msgId));
|
|
|
|
|
intent.putExtra(EXTRA_ACCOUNT_ID, accountId);
|
|
|
|
|
intent.putExtra(EXTRA_CHAT_ID, chatId);
|
|
|
|
|
intent.putExtra(EXTRA_APP_MSG_ID, msgId);
|
|
|
|
|
intent.putExtra(EXTRA_HIDE_ACTION_BAR, hideActionBar);
|
|
|
|
|
intent.putExtra(EXTRA_HREF, href);
|
|
|
|
@@ -149,12 +152,13 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE
|
|
|
|
|
private static Intent[] getWebxdcIntentWithParentStack(Context context, int msgId) {
|
|
|
|
|
DcContext dcContext = DcHelper.getContext(context);
|
|
|
|
|
|
|
|
|
|
int chatId = dcContext.getMsg(msgId).getChatId();
|
|
|
|
|
final Intent chatIntent =
|
|
|
|
|
new Intent(context, ConversationActivity.class)
|
|
|
|
|
.putExtra(ConversationActivity.CHAT_ID_EXTRA, dcContext.getMsg(msgId).getChatId())
|
|
|
|
|
.putExtra(ConversationActivity.CHAT_ID_EXTRA, chatId)
|
|
|
|
|
.setAction(Intent.ACTION_VIEW);
|
|
|
|
|
|
|
|
|
|
final Intent webxdcIntent = getWebxdcIntent(context, msgId, false, "");
|
|
|
|
|
final Intent webxdcIntent = getWebxdcIntent(context, msgId, chatId, false, "");
|
|
|
|
|
|
|
|
|
|
return TaskStackBuilder.create(context)
|
|
|
|
|
.addNextIntentWithParentStack(chatIntent)
|
|
|
|
@@ -200,12 +204,6 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
DcEventCenter eventCenter =
|
|
|
|
|
DcHelper.getEventCenter(WebxdcActivity.this.getApplicationContext());
|
|
|
|
|
eventCenter.addMultiAccountObserver(DcContext.DC_EVENT_WEBXDC_STATUS_UPDATE, this);
|
|
|
|
|
eventCenter.addMultiAccountObserver(DcContext.DC_EVENT_MSGS_CHANGED, this);
|
|
|
|
|
eventCenter.addMultiAccountObserver(DcContext.DC_EVENT_WEBXDC_REALTIME_DATA, this);
|
|
|
|
|
|
|
|
|
|
int appMessageId = b.getInt(EXTRA_APP_MSG_ID);
|
|
|
|
|
accountId = b.getInt(EXTRA_ACCOUNT_ID);
|
|
|
|
|
this.dcContext = DcHelper.getContext(getApplicationContext());
|
|
|
|
@@ -219,6 +217,15 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE
|
|
|
|
|
finish();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
chatId = b.getInt(EXTRA_CHAT_ID, dcAppMsg.getChatId());
|
|
|
|
|
|
|
|
|
|
DcEventCenter eventCenter =
|
|
|
|
|
DcHelper.getEventCenter(WebxdcActivity.this.getApplicationContext());
|
|
|
|
|
eventCenter.addObserver(DcContext.DC_EVENT_WEBXDC_STATUS_UPDATE, this);
|
|
|
|
|
eventCenter.addObserver(DcContext.DC_EVENT_MSGS_CHANGED, this);
|
|
|
|
|
eventCenter.addObserver(DcContext.DC_EVENT_MSG_DELETED, this);
|
|
|
|
|
eventCenter.addObserver(DcContext.DC_EVENT_CHAT_DELETED, this);
|
|
|
|
|
eventCenter.addObserver(DcContext.DC_EVENT_WEBXDC_REALTIME_DATA, this);
|
|
|
|
|
|
|
|
|
|
// `msg_id` in the subdomain makes sure, different apps using same files do not share the same
|
|
|
|
|
// cache entry
|
|
|
|
@@ -515,6 +522,10 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE
|
|
|
|
|
Log.e(TAG, "RPC Error", e);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else if ((eventId == DcContext.DC_EVENT_MSG_DELETED
|
|
|
|
|
&& event.getData2Int() == dcAppMsg.getId())
|
|
|
|
|
|| (eventId == DcContext.DC_EVENT_CHAT_DELETED && event.getData1Int() == chatId)) {
|
|
|
|
|
finish();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -563,7 +574,7 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE
|
|
|
|
|
IconCompat.createWithBitmap(
|
|
|
|
|
bitmap)) // createWithAdaptiveBitmap() removes decorations but cuts out a too
|
|
|
|
|
// small circle and defamiliarize the icon too much
|
|
|
|
|
.setIntent(getWebxdcIntent(context, msgId, false, ""))
|
|
|
|
|
.setIntent(getWebxdcIntent(context, msgId, msg.getChatId(), false, ""))
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
Toast.makeText(context, R.string.one_moment, Toast.LENGTH_SHORT).show();
|
|
|
|
|