aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main/java/de/pixart/messenger/ui/ChannelDiscoveryActivity.java15
-rw-r--r--src/main/java/de/pixart/messenger/ui/StartConversationActivity.java36
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/ChannelSearchResultAdapter.java39
3 files changed, 65 insertions, 25 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ChannelDiscoveryActivity.java b/src/main/java/de/pixart/messenger/ui/ChannelDiscoveryActivity.java
index 7696bd4eb..7e0d97ea2 100644
--- a/src/main/java/de/pixart/messenger/ui/ChannelDiscoveryActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ChannelDiscoveryActivity.java
@@ -35,8 +35,8 @@ import rocks.xmpp.addr.Jid;
public class ChannelDiscoveryActivity extends XmppActivity implements MenuItem.OnActionExpandListener, TextView.OnEditorActionListener, ChannelDiscoveryService.OnChannelSearchResultsFound, ChannelSearchResultAdapter.OnChannelSearchResultSelected {
private static final String CHANNEL_DISCOVERY_OPT_IN = "channel_discovery_opt_in";
private final ChannelSearchResultAdapter adapter = new ChannelSearchResultAdapter();
- private ActivityChannelDiscoveryBinding binding;
private final PendingItem<String> mInitialSearchValue = new PendingItem<>();
+ private ActivityChannelDiscoveryBinding binding;
private MenuItem mMenuSearchView;
private EditText mSearchEditText;
private boolean optedIn = false;
@@ -189,6 +189,19 @@ public class ChannelDiscoveryActivity extends XmppActivity implements MenuItem.O
}
}
+ @Override
+ public boolean onContextItemSelected(MenuItem item) {
+ final MuclumbusService.Room room = adapter.getCurrent();
+ if (room != null) {
+ switch (item.getItemId()) {
+ case R.id.share_with:
+ StartConversationActivity.shareAsChannel(this, room.address);
+ return true;
+ }
+ }
+ return false;
+ }
+
public void joinChannelSearchResult(String accountJid, MuclumbusService.Room result) {
final boolean syncAutojoin = getBooleanPreference("autojoin", R.bool.autojoin);
Account account = xmppConnectionService.findAccountByJid(Jid.of(accountJid));
diff --git a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
index 0bfd93cf1..56d071e68 100644
--- a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
@@ -9,21 +9,9 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
-import androidx.databinding.DataBindingUtil;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.fragment.app.Fragment;
-import androidx.fragment.app.FragmentManager;
-import androidx.fragment.app.FragmentTransaction;
-import androidx.fragment.app.ListFragment;
-import androidx.viewpager.widget.PagerAdapter;
-import androidx.viewpager.widget.ViewPager;
-import androidx.appcompat.app.ActionBar;
-import androidx.appcompat.app.AlertDialog;
-import androidx.appcompat.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
@@ -47,6 +35,19 @@ import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.appcompat.app.ActionBar;
+import androidx.appcompat.app.AlertDialog;
+import androidx.appcompat.widget.Toolbar;
+import androidx.databinding.DataBindingUtil;
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentManager;
+import androidx.fragment.app.FragmentTransaction;
+import androidx.fragment.app.ListFragment;
+import androidx.viewpager.widget.PagerAdapter;
+import androidx.viewpager.widget.ViewPager;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -396,15 +397,18 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
protected void shareBookmarkUri(int position) {
Bookmark bookmark = (Bookmark) conferences.get(position);
+ shareAsChannel(this, bookmark.getJid().asBareJid().toEscapedString());
+ }
+
+ public static void shareAsChannel(final Context context, final String address) {
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
- shareIntent.putExtra(Intent.EXTRA_TEXT, "xmpp:" + bookmark.getJid().asBareJid().toEscapedString() + "?join");
+ shareIntent.putExtra(Intent.EXTRA_TEXT, "xmpp:" + address + "?join");
shareIntent.setType("text/plain");
try {
- startActivity(Intent.createChooser(shareIntent, getText(R.string.share_uri_with)));
- overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
+ context.startActivity(Intent.createChooser(shareIntent, context.getText(R.string.share_uri_with)));
} catch (ActivityNotFoundException e) {
- Toast.makeText(this, R.string.no_application_to_share_uri, Toast.LENGTH_SHORT).show();
+ Toast.makeText(context, R.string.no_application_to_share_uri, Toast.LENGTH_SHORT).show();
}
}
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/ChannelSearchResultAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/ChannelSearchResultAdapter.java
index cf5986738..7e5fd4b3e 100644
--- a/src/main/java/de/pixart/messenger/ui/adapter/ChannelSearchResultAdapter.java
+++ b/src/main/java/de/pixart/messenger/ui/adapter/ChannelSearchResultAdapter.java
@@ -1,27 +1,30 @@
package de.pixart.messenger.ui.adapter;
-import androidx.databinding.DataBindingUtil;
-import androidx.annotation.NonNull;
-import androidx.recyclerview.widget.ListAdapter;
-import androidx.recyclerview.widget.DiffUtil;
-import androidx.recyclerview.widget.RecyclerView;
+import android.app.Activity;
import android.text.TextUtils;
+import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import androidx.annotation.NonNull;
+import androidx.databinding.DataBindingUtil;
+import androidx.recyclerview.widget.DiffUtil;
+import androidx.recyclerview.widget.ListAdapter;
+import androidx.recyclerview.widget.RecyclerView;
+
import java.util.Locale;
import de.pixart.messenger.R;
import de.pixart.messenger.databinding.SearchResultItemBinding;
import de.pixart.messenger.http.services.MuclumbusService;
+import de.pixart.messenger.ui.XmppActivity;
import de.pixart.messenger.ui.util.AvatarWorkerTask;
import rocks.xmpp.addr.Jid;
-public class ChannelSearchResultAdapter extends ListAdapter<MuclumbusService.Room, ChannelSearchResultAdapter.ViewHolder> {
+public class ChannelSearchResultAdapter extends ListAdapter<MuclumbusService.Room, ChannelSearchResultAdapter.ViewHolder> implements View.OnCreateContextMenuListener {
- private OnChannelSearchResultSelected listener;
private static final DiffUtil.ItemCallback<MuclumbusService.Room> DIFF = new DiffUtil.ItemCallback<MuclumbusService.Room>() {
@Override
@@ -35,6 +38,9 @@ public class ChannelSearchResultAdapter extends ListAdapter<MuclumbusService.Roo
}
};
+ private OnChannelSearchResultSelected listener;
+ private MuclumbusService.Room current;
+
public ChannelSearchResultAdapter() {
super(DIFF);
}
@@ -66,13 +72,30 @@ public class ChannelSearchResultAdapter extends ListAdapter<MuclumbusService.Roo
final Jid room = searchResult.getRoom();
viewHolder.binding.room.setText(room != null ? room.asBareJid().toString() : "");
AvatarWorkerTask.loadAvatar(searchResult, viewHolder.binding.avatar, R.dimen.avatar);
- viewHolder.binding.getRoot().setOnClickListener(v -> listener.onChannelSearchResult(searchResult));
+ final View root = viewHolder.binding.getRoot();
+ root.setTag(searchResult);
+ root.setOnClickListener(v -> listener.onChannelSearchResult(searchResult));
+ root.setOnCreateContextMenuListener(this);
}
public void setOnChannelSearchResultSelectedListener(OnChannelSearchResultSelected listener) {
this.listener = listener;
}
+ public MuclumbusService.Room getCurrent() {
+ return this.current;
+ }
+
+ @Override
+ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
+ final Activity activity = XmppActivity.find(v);
+ final Object tag = v.getTag();
+ if (activity != null && tag instanceof MuclumbusService.Room) {
+ activity.getMenuInflater().inflate(R.menu.channel_item_context, menu);
+ this.current = (MuclumbusService.Room) tag;
+ }
+ }
+
public static class ViewHolder extends RecyclerView.ViewHolder {
private final SearchResultItemBinding binding;