Move WebXDC "store" to attachment menu

This commit is contained in:
Arne 2024-08-24 20:58:58 +02:00
parent a8a5145e5d
commit fedca23a4a
15 changed files with 129 additions and 271 deletions

View file

@ -364,10 +364,10 @@
</activity>
<activity
android:name="de.monocles.chat.WebXDCStore"
android:name="de.monocles.chat.WebxdcStore"
android:label="@string/webxdcs"
android:launchMode="singleTask"
android:exported="true" />
android:launchMode="standard"
android:exported="false" />
<activity
android:name="de.monocles.chat.RegisterMonoclesActivity"

View file

@ -1,202 +0,0 @@
package de.monocles.chat;
import static android.view.View.VISIBLE;
import static eu.siacs.conversations.ui.ActionBarActivity.configureActionBar;
import static eu.siacs.conversations.ui.SettingsActivity.HIDE_DONATION_SNACKBAR;
import static eu.siacs.conversations.ui.SettingsActivity.HIDE_WEBXDC_STORE_HINT;
import static eu.siacs.conversations.ui.SettingsActivity.REQUEST_DOWNLOAD_STICKERS;
import static eu.siacs.conversations.utils.AccountUtils.MANAGE_ACCOUNT_ACTIVITY;
import static eu.siacs.conversations.utils.Compatibility.hasStoragePermission;
import android.app.DownloadManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.view.MenuItem;
import android.webkit.DownloadListener;
import android.webkit.URLUtil;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import eu.siacs.conversations.R;
import eu.siacs.conversations.ui.ConversationsActivity;
import eu.siacs.conversations.ui.ShareWithActivity;
import eu.siacs.conversations.ui.StartConversationActivity;
import eu.siacs.conversations.ui.XmppActivity;
import eu.siacs.conversations.utils.MimeUtils;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import android.annotation.SuppressLint;
import android.widget.Toast;
import com.google.android.material.bottomnavigation.BottomNavigationView;
public class WebXDCStore extends XmppActivity {
private static final int REQUEST_DOWNLOAD_WEBXDC = 0xbf8000;
private long mFileDownloadedId = -1;
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webxdc_store);
setSupportActionBar(findViewById(R.id.toolbar));
final ActionBar actionBar = getSupportActionBar();
if (actionBar == null) {
return;
}
configureActionBar(actionBar);
getSupportActionBar().setDisplayShowHomeEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
WebView webView = findViewById(R.id.web);
String URL = "https://webxdc.org/apps/";
if (isNetworkAvailable(this)) {
webView.loadUrl(URL);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
webView.setForceDarkAllowed(true);
}
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
if (hasStoragePermission(REQUEST_DOWNLOAD_WEBXDC)) {
webView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType, long contentLength) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setMimeType(mimeType);
request.allowScanningByMediaScanner();
String extension = MimeUtils.guessMimeTypeFromUri(getApplicationContext(), Uri.parse(url));
String filename = URLUtil.guessFileName(url, contentDisposition, extension);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
mFileDownloadedId = dm.enqueue(request);
Toast.makeText(getApplicationContext(), R.string.download_started, Toast.LENGTH_LONG).show();
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
long downloadedID = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
if (downloadedID == mFileDownloadedId) {
String action = intent.getAction();
if (action != null && action.equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) {
Uri uri = dm.getUriForDownloadedFile(mFileDownloadedId);
intent = new Intent(context, ShareWithActivity.class);
intent.setAction(Intent.ACTION_SEND);
// Intent intent = new Intent(getApplicationContext(), ConversationsActivity.class);
// intent.setAction(ConversationsActivity.ACTION_VIEW_CONVERSATION);
intent.setType("application/xdc+zip");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Share WebXDC"));
}
}
}
};
if (Build.VERSION.SDK_INT >= 34 && xmppConnectionService.getApplicationInfo().targetSdkVersion >= 34) {
xmppConnectionService.registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE), Context.RECEIVER_EXPORTED);
} else {
xmppConnectionService.registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}
}
});
} else {
Toast.makeText(this, R.string.no_storage_permission, Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(this, R.string.account_status_no_internet, Toast.LENGTH_LONG).show();
}
}
@Override
protected void refreshUiReal() {
}
protected void onStart() {
super.onStart();
final int theme = findTheme();
if (this.mTheme != theme) {
recreate();
}
// Initialize and assign variable
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation);
// Set Home selected
bottomNavigationView.setSelectedItemId(R.id.webxdc);
// Perform item selected listener
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.chats -> {
startActivity(new Intent(getApplicationContext(), ConversationsActivity.class));
overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
return true;
}
case R.id.webxdc -> {
return true;
}
case R.id.manageaccounts -> {
startActivity(new Intent(getApplicationContext(), MANAGE_ACCOUNT_ACTIVITY));
overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
return true;
}
/* TODO:
case R.id.calls:
startActivity(new Intent(getApplicationContext(), CallsActivity.class));
overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
return true;
case R.id.stories:
startActivity(new Intent(getApplicationContext(),MediaBrowserActivity.class));
overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
return true;
*/
default ->
throw new IllegalStateException("Unexpected value: " + item.getItemId());
}
}
});
bottomNavigationView.setVisibility(VISIBLE);
}
@Override
protected void onBackendConnected() {
}
//check for internet connection
private boolean isNetworkAvailable(Context context) {
ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null) {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (NetworkInfo anInfo : info) {
if (anInfo.getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
}
return false;
}
}

View file

@ -0,0 +1,94 @@
package de.monocles.chat;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.webkit.DownloadListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import eu.siacs.conversations.R;
import eu.siacs.conversations.ui.XmppActivity;
import androidx.appcompat.app.ActionBar;
import android.annotation.SuppressLint;
import android.widget.Toast;
public class WebxdcStore extends XmppActivity {
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webxdc_store);
setSupportActionBar(findViewById(R.id.toolbar));
final ActionBar actionBar = getSupportActionBar();
if (actionBar == null) {
return;
}
configureActionBar(actionBar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
WebView webView = findViewById(R.id.web);
String URL = "https://webxdc.org/apps/";
if (isNetworkAvailable(this)) {
webView.loadUrl(URL);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
webView.setForceDarkAllowed(true);
}
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
webView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType, long contentLength) {
final var intent = new Intent();
intent.setData(Uri.parse(url));
setResult(Activity.RESULT_OK, intent);
finish();
}
});
} else {
Toast.makeText(this, R.string.account_status_no_internet, Toast.LENGTH_LONG).show();
}
}
@Override
protected void refreshUiReal() {
}
@Override
protected void onBackendConnected() {
}
//check for internet connection
private boolean isNetworkAvailable(Context context) {
ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null) {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (NetworkInfo anInfo : info) {
if (anInfo.getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
}
return false;
}
}

View file

@ -157,8 +157,8 @@ import de.monocles.chat.BobTransfer;
import de.monocles.chat.EmojiSearch;
import de.monocles.chat.GifsAdapter;
import de.monocles.chat.KeyboardHeightProvider;
import de.monocles.chat.StickerAdapter;
import de.monocles.chat.WebxdcPage;
import de.monocles.chat.WebxdcStore;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.axolotl.AxolotlService;
@ -275,6 +275,7 @@ public class ConversationFragment extends XmppFragment
public static final int REQUEST_START_VIDEO_CALL = 0x214;
public static final int REQUEST_SAVE_STICKER = 0x215;
public static final int REQUEST_SAVE_GIF = 0x216;
public static final int REQUEST_WEBXDC_STORE = 0x217;
public static final int ATTACHMENT_CHOICE_CHOOSE_IMAGE = 0x0301;
public static final int ATTACHMENT_CHOICE_TAKE_PHOTO = 0x0302;
public static final int ATTACHMENT_CHOICE_CHOOSE_FILE = 0x0303;
@ -1173,7 +1174,7 @@ public class ConversationFragment extends XmppFragment
ConversationMenuConfigurator.configureQuickShareAttachmentMenu(conversation, menu, hideVoiceAndTakePicture);
popup.setOnMenuItemClickListener(attachmentItem -> {
int itemId = attachmentItem.getItemId();
if (itemId == R.id.attach_choose_picture || itemId == R.id.attach_choose_video || itemId == R.id.attach_take_picture || itemId == R.id.attach_record_video || itemId == R.id.attach_choose_file || itemId == R.id.attach_record_voice || itemId == R.id.attach_subject || itemId == R.id.attach_location) {
if (itemId == R.id.attach_choose_picture || itemId == R.id.attach_choose_video || itemId == R.id.attach_take_picture || itemId == R.id.attach_record_video || itemId == R.id.attach_choose_file || itemId == R.id.attach_record_voice || itemId == R.id.attach_subject || itemId == R.id.attach_webxdc || itemId == R.id.attach_location) {
handleAttachmentSelection(attachmentItem);
}
return false;
@ -1575,7 +1576,10 @@ public class ConversationFragment extends XmppFragment
}
private void handlePositiveActivityResult(int requestCode, final Intent data) {
if (requestCode == REQUEST_SAVE_STICKER) {
if (requestCode == REQUEST_WEBXDC_STORE) {
mediaPreviewAdapter.addMediaPreviews(Attachment.of(activity, data.getData(), Attachment.Type.FILE));
toggleInputMethod();
} else if (requestCode == REQUEST_SAVE_STICKER) {
final DocumentFile df = DocumentFile.fromSingleUri(activity, data.getData());
final File f = savingAsSticker;
savingAsSticker = null;
@ -2638,7 +2642,11 @@ public class ConversationFragment extends XmppFragment
int itemId = item.getItemId();
if (itemId == R.id.encryption_choice_axolotl || itemId == R.id.encryption_choice_otr || itemId == R.id.encryption_choice_pgp || itemId == R.id.encryption_choice_none) {
handleEncryptionSelection(item);
} else if (itemId == R.id.attach_choose_picture || itemId == R.id.attach_choose_video || itemId == R.id.attach_take_picture || itemId == R.id.attach_record_video || itemId == R.id.attach_choose_file || itemId == R.id.attach_record_voice || itemId == R.id.attach_location || itemId == R.id.attach_subject) {
} else if (itemId == R.id.attach_choose_picture || itemId == R.id.attach_choose_video || itemId == R.id.attach_take_picture || itemId == R.id.attach_record_video || itemId == R.id.attach_choose_file || itemId == R.id.attach_record_voice || itemId == R.id.attach_location) {
handleAttachmentSelection(item);
} else if (itemId == R.id.attach_webxdc) {
handleAttachmentSelection(item);
} else if (itemId == R.id.attach_subject) {
handleAttachmentSelection(item);
} else if (itemId == R.id.action_search) {
startSearch();
@ -2879,6 +2887,10 @@ public class ConversationFragment extends XmppFragment
attachFile(ATTACHMENT_CHOICE_CHOOSE_FILE);
} else if (itemId == R.id.attach_record_voice) {
attachFile(ATTACHMENT_CHOICE_RECORD_VOICE);
} else if (itemId == R.id.attach_webxdc) {
final Intent intent2 = new Intent(getActivity(), WebxdcStore.class);
startActivityForResult(intent2, REQUEST_WEBXDC_STORE);
activity.overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
} else if (itemId == R.id.attach_location) {
attachFile(ATTACHMENT_CHOICE_LOCATION);
} else if (itemId == R.id.attach_subject) {

View file

@ -86,7 +86,6 @@ import androidx.databinding.DataBindingUtil;
import org.openintents.openpgp.util.OpenPgpApi;
import de.monocles.chat.WebXDCStore;
import eu.siacs.conversations.ui.util.AvatarWorkerTask;
import eu.siacs.conversations.utils.Compatibility;
import io.michaelrocks.libphonenumber.android.NumberParseException;
@ -1007,11 +1006,6 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
case R.id.chats -> {
return true;
}
case R.id.webxdc -> {
startActivity(new Intent(getApplicationContext(), WebXDCStore.class));
overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
return true;
}
case R.id.manageaccounts -> {
startActivity(new Intent(getApplicationContext(), MANAGE_ACCOUNT_ACTIVITY));
overridePendingTransition(R.animator.fade_in, R.animator.fade_out);

View file

@ -37,7 +37,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import de.monocles.chat.WebXDCStore;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Contact;
@ -175,11 +174,6 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
return true;
}
case R.id.webxdc -> {
startActivity(new Intent(getApplicationContext(), WebXDCStore.class));
overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
return true;
}
case R.id.manageaccounts -> {
return true;
}

View file

@ -53,7 +53,6 @@ import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
import de.monocles.chat.WebXDCStore;
import eu.siacs.conversations.utils.UIHelper;
import androidx.annotation.MenuRes;

View file

@ -29,7 +29,7 @@
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.coordinatorlayout.widget.CoordinatorLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
@ -43,18 +43,5 @@
android:layout_height="match_parent"
android:id="@+id/web"/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_gravity="end|bottom"
android:background="?attr/color_background_secondary"
app:labelVisibilityMode="labeled"
app:itemActiveIndicatorStyle="@style/monocles.Active.Indicator"
app:menu="@menu/bottom_navigation_menu_webxdcs"
android:state_checked="true"
android:visibility="gone"
android:animateLayoutChanges="true" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</LinearLayout>
</layout>

View file

@ -4,10 +4,7 @@
android:id="@+id/chats"
android:icon="?attr/icon_chat"
android:title="@string/chats"/>
<item
android:id="@+id/webxdc"
android:icon="?attr/icon_webxdcs"
android:title="@string/webxdcs"/>
<item
android:id="@+id/manageaccounts"
android:icon="?attr/icon_account"

View file

@ -4,10 +4,7 @@
android:id="@+id/chats"
android:icon="?attr/icon_chat_unselected"
android:title="@string/chats"/>
<item
android:id="@+id/webxdc"
android:icon="?attr/icon_webxdcs"
android:title="@string/webxdcs"/>
<item
android:id="@+id/manageaccounts"
android:icon="?attr/icon_accounts_selected"

View file

@ -4,10 +4,7 @@
android:id="@+id/chats"
android:icon="?attr/icon_chat_selected"
android:title="@string/chats"/>
<item
android:id="@+id/webxdc"
android:icon="?attr/icon_webxdcs"
android:title="@string/webxdcs"/>
<item
android:id="@+id/manageaccounts"
android:icon="?attr/icon_account"

View file

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/chats"
android:icon="?attr/icon_chat_unselected"
android:title="@string/chats"/>
<item
android:id="@+id/webxdc"
android:icon="?attr/icon_webxdcs_selected"
android:title="@string/webxdcs"/>
<item
android:id="@+id/manageaccounts"
android:icon="?attr/icon_account"
android:title="@string/accounts"/>
<!-- TODO: Later -->
<item
android:id="@+id/stories"
android:icon="@drawable/ic_stories_black_24dp"
android:title="@string/stories"
android:visible="false" />
</menu>

View file

@ -35,6 +35,11 @@
android:icon="?attr/share_location"
android:title="@string/send_location" />
<item
android:id="@+id/attach_webxdc"
android:icon="?attr/icon_webxdcs"
android:title="@string/choose_webxdc" />
<item
android:id="@+id/attach_subject"
android:icon="?attr/add_subject"

View file

@ -95,6 +95,11 @@
android:icon="?attr/share_location"
android:title="@string/send_location" />
<item
android:id="@+id/attach_webxdc"
android:icon="?attr/icon_webxdcs"
android:title="@string/choose_webxdc" />
<item
android:id="@+id/attach_subject"
android:icon="?attr/add_subject"

View file

@ -1470,4 +1470,5 @@
<string name="webxdc_store_hint_title">WebXDC usage</string>
<string name="webxdc_store_hint_summary">To use WebXDC apps with status updates you need to disable encryption when sending the WebXDC. Please enable encryption afterwards again.</string>
<string name="send_encrypted">Send encrypted</string>
<string name="choose_webxdc">Choose WebXDC</string>
</resources>