show context menu in channel search to share uri
This commit is contained in:
parent
ed46d12115
commit
3820950408
|
@ -37,11 +37,8 @@ public class ChannelDiscoveryActivity extends XmppActivity implements MenuItem.O
|
||||||
private static final String CHANNEL_DISCOVERY_OPT_IN = "channel_discovery_opt_in";
|
private static final String CHANNEL_DISCOVERY_OPT_IN = "channel_discovery_opt_in";
|
||||||
|
|
||||||
private final ChannelSearchResultAdapter adapter = new ChannelSearchResultAdapter();
|
private final ChannelSearchResultAdapter adapter = new ChannelSearchResultAdapter();
|
||||||
|
|
||||||
private ActivityChannelDiscoveryBinding binding;
|
|
||||||
|
|
||||||
private final PendingItem<String> mInitialSearchValue = new PendingItem<>();
|
private final PendingItem<String> mInitialSearchValue = new PendingItem<>();
|
||||||
|
private ActivityChannelDiscoveryBinding binding;
|
||||||
private MenuItem mMenuSearchView;
|
private MenuItem mMenuSearchView;
|
||||||
private EditText mSearchEditText;
|
private EditText mSearchEditText;
|
||||||
|
|
||||||
|
@ -198,6 +195,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) {
|
public void joinChannelSearchResult(String accountJid, MuclumbusService.Room result) {
|
||||||
final boolean syncAutojoin = getBooleanPreference("autojoin", R.bool.autojoin);
|
final boolean syncAutojoin = getBooleanPreference("autojoin", R.bool.autojoin);
|
||||||
Account account = xmppConnectionService.findAccountByJid(Jid.of(accountJid));
|
Account account = xmppConnectionService.findAccountByJid(Jid.of(accountJid));
|
||||||
|
|
|
@ -405,14 +405,18 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
|
||||||
|
|
||||||
protected void shareBookmarkUri(int position) {
|
protected void shareBookmarkUri(int position) {
|
||||||
Bookmark bookmark = (Bookmark) conferences.get(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();
|
Intent shareIntent = new Intent();
|
||||||
shareIntent.setAction(Intent.ACTION_SEND);
|
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");
|
shareIntent.setType("text/plain");
|
||||||
try {
|
try {
|
||||||
startActivity(Intent.createChooser(shareIntent, getText(R.string.share_uri_with)));
|
context.startActivity(Intent.createChooser(shareIntent, context.getText(R.string.share_uri_with)));
|
||||||
} catch (ActivityNotFoundException e) {
|
} 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
package eu.siacs.conversations.ui.adapter;
|
package eu.siacs.conversations.ui.adapter;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.databinding.DataBindingUtil;
|
import android.databinding.DataBindingUtil;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v7.recyclerview.extensions.ListAdapter;
|
import android.support.v7.recyclerview.extensions.ListAdapter;
|
||||||
import android.support.v7.util.DiffUtil;
|
import android.support.v7.util.DiffUtil;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.view.ContextMenu;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -15,12 +17,11 @@ import java.util.Locale;
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.databinding.SearchResultItemBinding;
|
import eu.siacs.conversations.databinding.SearchResultItemBinding;
|
||||||
import eu.siacs.conversations.http.services.MuclumbusService;
|
import eu.siacs.conversations.http.services.MuclumbusService;
|
||||||
|
import eu.siacs.conversations.ui.XmppActivity;
|
||||||
import eu.siacs.conversations.ui.util.AvatarWorkerTask;
|
import eu.siacs.conversations.ui.util.AvatarWorkerTask;
|
||||||
import rocks.xmpp.addr.Jid;
|
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>() {
|
private static final DiffUtil.ItemCallback<MuclumbusService.Room> DIFF = new DiffUtil.ItemCallback<MuclumbusService.Room>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -33,6 +34,8 @@ public class ChannelSearchResultAdapter extends ListAdapter<MuclumbusService.Roo
|
||||||
return a.equals(b);
|
return a.equals(b);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
private OnChannelSearchResultSelected listener;
|
||||||
|
private MuclumbusService.Room current;
|
||||||
|
|
||||||
public ChannelSearchResultAdapter() {
|
public ChannelSearchResultAdapter() {
|
||||||
super(DIFF);
|
super(DIFF);
|
||||||
|
@ -65,13 +68,34 @@ public class ChannelSearchResultAdapter extends ListAdapter<MuclumbusService.Roo
|
||||||
final Jid room = searchResult.getRoom();
|
final Jid room = searchResult.getRoom();
|
||||||
viewHolder.binding.room.setText(room != null ? room.asBareJid().toString() : "");
|
viewHolder.binding.room.setText(room != null ? room.asBareJid().toString() : "");
|
||||||
AvatarWorkerTask.loadAvatar(searchResult, viewHolder.binding.avatar, R.dimen.avatar);
|
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) {
|
public void setOnChannelSearchResultSelectedListener(OnChannelSearchResultSelected listener) {
|
||||||
this.listener = 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 interface OnChannelSearchResultSelected {
|
||||||
|
void onChannelSearchResult(MuclumbusService.Room result);
|
||||||
|
}
|
||||||
|
|
||||||
public static class ViewHolder extends RecyclerView.ViewHolder {
|
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
|
@ -82,8 +106,4 @@ public class ChannelSearchResultAdapter extends ListAdapter<MuclumbusService.Roo
|
||||||
this.binding = binding;
|
this.binding = binding;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface OnChannelSearchResultSelected {
|
|
||||||
void onChannelSearchResult(MuclumbusService.Room result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item
|
||||||
|
android:id="@+id/share_with"
|
||||||
|
android:title="@string/share_uri_with" />
|
||||||
|
</menu>
|
Loading…
Reference in New Issue