bring scan button to StartConversationActivity
This commit is contained in:
parent
3bd42230f2
commit
12031515d1
|
@ -1746,8 +1746,16 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean scrolledToBottom() {
|
private boolean scrolledToBottom() {
|
||||||
final ListView l = this.binding.messagesView;
|
if (this.binding == null) {
|
||||||
return l.getLastVisiblePosition() == l.getAdapter().getCount() -1 && l.getChildAt(l.getChildCount() - 1).getBottom() <= l.getHeight();
|
return false;
|
||||||
|
}
|
||||||
|
final ListView listView = this.binding.messagesView;
|
||||||
|
if (listView.getLastVisiblePosition() == listView.getAdapter().getCount() -1) {
|
||||||
|
final View lastChild = listView.getChildAt(listView.getChildCount() -1);
|
||||||
|
return lastChild != null && lastChild.getBottom() <= listView.getHeight();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processExtras(Bundle extras) {
|
private void processExtras(Bundle extras) {
|
||||||
|
|
|
@ -84,6 +84,8 @@ import eu.siacs.conversations.xmpp.jid.Jid;
|
||||||
|
|
||||||
public class StartConversationActivity extends XmppActivity implements OnRosterUpdate, OnUpdateBlocklist {
|
public class StartConversationActivity extends XmppActivity implements OnRosterUpdate, OnUpdateBlocklist {
|
||||||
|
|
||||||
|
private final int REQUEST_SYNC_CONTACTS = 0x28cf;
|
||||||
|
private final int REQUEST_CREATE_CONFERENCE = 0x39da;
|
||||||
public int conference_context_id;
|
public int conference_context_id;
|
||||||
public int contact_context_id;
|
public int contact_context_id;
|
||||||
private ListPagerAdapter mListPagerAdapter;
|
private ListPagerAdapter mListPagerAdapter;
|
||||||
|
@ -97,10 +99,8 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
||||||
private Invite mPendingInvite = null;
|
private Invite mPendingInvite = null;
|
||||||
private EditText mSearchEditText;
|
private EditText mSearchEditText;
|
||||||
private AtomicBoolean mRequestedContactsPermission = new AtomicBoolean(false);
|
private AtomicBoolean mRequestedContactsPermission = new AtomicBoolean(false);
|
||||||
private final int REQUEST_SYNC_CONTACTS = 0x28cf;
|
|
||||||
private final int REQUEST_CREATE_CONFERENCE = 0x39da;
|
|
||||||
private Dialog mCurrentDialog = null;
|
private Dialog mCurrentDialog = null;
|
||||||
|
private boolean mHideOfflineContacts = false;
|
||||||
private MenuItem.OnActionExpandListener mOnActionExpandListener = new MenuItem.OnActionExpandListener() {
|
private MenuItem.OnActionExpandListener mOnActionExpandListener = new MenuItem.OnActionExpandListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -122,35 +122,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private boolean mHideOfflineContacts = false;
|
|
||||||
private ActionBar.TabListener mTabListener = new ActionBar.TabListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
|
|
||||||
binding.startConversationViewPager.setCurrentItem(tab.getPosition());
|
|
||||||
onTabChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
private ViewPager.SimpleOnPageChangeListener mOnPageChangeListener = new ViewPager.SimpleOnPageChangeListener() {
|
|
||||||
@Override
|
|
||||||
public void onPageSelected(int position) {
|
|
||||||
ActionBar actionBar = getSupportActionBar();
|
|
||||||
if (actionBar != null) {
|
|
||||||
actionBar.setSelectedNavigationItem(position);
|
|
||||||
}
|
|
||||||
onTabChanged();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
private TextWatcher mSearchTextWatcher = new TextWatcher() {
|
private TextWatcher mSearchTextWatcher = new TextWatcher() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -167,7 +138,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private TextView.OnEditorActionListener mSearchDone = new TextView.OnEditorActionListener() {
|
private TextView.OnEditorActionListener mSearchDone = new TextView.OnEditorActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||||
|
@ -202,6 +172,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
||||||
};
|
};
|
||||||
private String mInitialJid;
|
private String mInitialJid;
|
||||||
private Pair<Integer, Intent> mPostponedActivityResult;
|
private Pair<Integer, Intent> mPostponedActivityResult;
|
||||||
|
private Toast mToast;
|
||||||
private UiCallback<Conversation> mAdhocConferenceCallback = new UiCallback<Conversation>() {
|
private UiCallback<Conversation> mAdhocConferenceCallback = new UiCallback<Conversation>() {
|
||||||
@Override
|
@Override
|
||||||
public void success(final Conversation conversation) {
|
public void success(final Conversation conversation) {
|
||||||
|
@ -221,8 +192,56 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private Toast mToast;
|
|
||||||
private ActivityStartConversationBinding binding;
|
private ActivityStartConversationBinding binding;
|
||||||
|
private ActionBar.TabListener mTabListener = new ActionBar.TabListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
|
||||||
|
binding.startConversationViewPager.setCurrentItem(tab.getPosition());
|
||||||
|
onTabChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
private ViewPager.SimpleOnPageChangeListener mOnPageChangeListener = new ViewPager.SimpleOnPageChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onPageSelected(int position) {
|
||||||
|
ActionBar actionBar = getSupportActionBar();
|
||||||
|
if (actionBar != null) {
|
||||||
|
actionBar.setSelectedNavigationItem(position);
|
||||||
|
}
|
||||||
|
onTabChanged();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static void populateAccountSpinner(Context context, List<String> accounts, Spinner spinner) {
|
||||||
|
if (accounts.size() > 0) {
|
||||||
|
ArrayAdapter<String> adapter = new ArrayAdapter<>(context, R.layout.simple_list_item, accounts);
|
||||||
|
adapter.setDropDownViewResource(R.layout.simple_list_item);
|
||||||
|
spinner.setAdapter(adapter);
|
||||||
|
spinner.setEnabled(true);
|
||||||
|
} else {
|
||||||
|
ArrayAdapter<String> adapter = new ArrayAdapter<>(context,
|
||||||
|
R.layout.simple_list_item,
|
||||||
|
Arrays.asList(context.getString(R.string.no_accounts)));
|
||||||
|
adapter.setDropDownViewResource(R.layout.simple_list_item);
|
||||||
|
spinner.setAdapter(adapter);
|
||||||
|
spinner.setEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void launch(Context context) {
|
||||||
|
final Intent intent = new Intent(context, StartConversationActivity.class);
|
||||||
|
context.startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
protected void hideToast() {
|
protected void hideToast() {
|
||||||
if (mToast != null) {
|
if (mToast != null) {
|
||||||
|
@ -248,6 +267,18 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
||||||
this.binding = DataBindingUtil.setContentView(this, R.layout.activity_start_conversation);
|
this.binding = DataBindingUtil.setContentView(this, R.layout.activity_start_conversation);
|
||||||
this.binding.fab.setOnClickListener((v) -> {
|
this.binding.fab.setOnClickListener((v) -> {
|
||||||
if (getSupportActionBar().getSelectedNavigationIndex() == 0) {
|
if (getSupportActionBar().getSelectedNavigationIndex() == 0) {
|
||||||
|
String searchString = mSearchEditText != null ? mSearchEditText.getText().toString() : null;
|
||||||
|
if (searchString != null && !searchString.trim().isEmpty()) {
|
||||||
|
try {
|
||||||
|
Jid jid = Jid.fromString(searchString);
|
||||||
|
if (!jid.isDomainJid() && jid.isBareJid() && jid.getDomainpart().contains(".")) {
|
||||||
|
showCreateContactDialog(jid.toString(),null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (InvalidJidException ignored) {
|
||||||
|
//ignore and fall through
|
||||||
|
}
|
||||||
|
}
|
||||||
showCreateContactDialog(null, null);
|
showCreateContactDialog(null, null);
|
||||||
} else {
|
} else {
|
||||||
showCreateConferenceDialog();
|
showCreateConferenceDialog();
|
||||||
|
@ -478,11 +509,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
||||||
final AlertDialog dialog = builder.create();
|
final AlertDialog dialog = builder.create();
|
||||||
dialog.show();
|
dialog.show();
|
||||||
mCurrentDialog = dialog;
|
mCurrentDialog = dialog;
|
||||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(
|
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(v -> {
|
||||||
new View.OnClickListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(final View v) {
|
|
||||||
if (!xmppConnectionServiceBound) {
|
if (!xmppConnectionServiceBound) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -524,7 +551,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
||||||
mCurrentDialog = null;
|
mCurrentDialog = null;
|
||||||
switchToConversation(conversation);
|
switchToConversation(conversation);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -584,26 +610,13 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
||||||
switchToConversation(conversation, body, false);
|
switchToConversation(conversation, body, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void populateAccountSpinner(Context context, List<String> accounts, Spinner spinner) {
|
|
||||||
if (accounts.size() > 0) {
|
|
||||||
ArrayAdapter<String> adapter = new ArrayAdapter<>(context, R.layout.simple_list_item, accounts);
|
|
||||||
adapter.setDropDownViewResource(R.layout.simple_list_item);
|
|
||||||
spinner.setAdapter(adapter);
|
|
||||||
spinner.setEnabled(true);
|
|
||||||
} else {
|
|
||||||
ArrayAdapter<String> adapter = new ArrayAdapter<>(context,
|
|
||||||
R.layout.simple_list_item,
|
|
||||||
Arrays.asList(context.getString(R.string.no_accounts)));
|
|
||||||
adapter.setDropDownViewResource(R.layout.simple_list_item);
|
|
||||||
spinner.setAdapter(adapter);
|
|
||||||
spinner.setEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
getMenuInflater().inflate(R.menu.start_conversation, menu);
|
getMenuInflater().inflate(R.menu.start_conversation, menu);
|
||||||
MenuItem menuHideOffline = menu.findItem(R.id.action_hide_offline);
|
MenuItem menuHideOffline = menu.findItem(R.id.action_hide_offline);
|
||||||
|
MenuItem joinGroupChat = menu.findItem(R.id.action_join_conference);
|
||||||
|
ActionBar bar = getSupportActionBar();
|
||||||
|
joinGroupChat.setVisible(bar != null && bar.getSelectedNavigationIndex() == 1);
|
||||||
menuHideOffline.setChecked(this.mHideOfflineContacts);
|
menuHideOffline.setChecked(this.mHideOfflineContacts);
|
||||||
mMenuSearchView = menu.findItem(R.id.action_search);
|
mMenuSearchView = menu.findItem(R.id.action_search);
|
||||||
mMenuSearchView.setOnActionExpandListener(mOnActionExpandListener);
|
mMenuSearchView.setOnActionExpandListener(mOnActionExpandListener);
|
||||||
|
@ -940,11 +953,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
||||||
invalidateOptionsMenu();
|
invalidateOptionsMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void launch(Context context) {
|
|
||||||
final Intent intent = new Intent(context,StartConversationActivity.class);
|
|
||||||
context.startActivity(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void OnUpdateBlocklist(final Status status) {
|
public void OnUpdateBlocklist(final Status status) {
|
||||||
refreshUi();
|
refreshUi();
|
||||||
|
@ -957,69 +965,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ListPagerAdapter extends PagerAdapter {
|
|
||||||
FragmentManager fragmentManager;
|
|
||||||
MyListFragment[] fragments;
|
|
||||||
|
|
||||||
public ListPagerAdapter(FragmentManager fm) {
|
|
||||||
fragmentManager = fm;
|
|
||||||
fragments = new MyListFragment[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
public void requestFocus(int pos) {
|
|
||||||
if (fragments.length > pos) {
|
|
||||||
fragments[pos].getListView().requestFocus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void destroyItem(@NonNull ViewGroup container, int position,@NonNull Object object) {
|
|
||||||
assert (0 <= position && position < fragments.length);
|
|
||||||
FragmentTransaction trans = fragmentManager.beginTransaction();
|
|
||||||
trans.remove(fragments[position]);
|
|
||||||
trans.commit();
|
|
||||||
fragments[position] = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Fragment instantiateItem(@NonNull ViewGroup container, int position) {
|
|
||||||
Fragment fragment = getItem(position);
|
|
||||||
FragmentTransaction trans = fragmentManager.beginTransaction();
|
|
||||||
trans.add(container.getId(), fragment, "fragment:" + position);
|
|
||||||
trans.commit();
|
|
||||||
return fragment;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getCount() {
|
|
||||||
return fragments.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isViewFromObject(@NonNull View view,@NonNull Object fragment) {
|
|
||||||
return ((Fragment) fragment).getView() == view;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Fragment getItem(int position) {
|
|
||||||
assert (0 <= position && position < fragments.length);
|
|
||||||
if (fragments[position] == null) {
|
|
||||||
final MyListFragment listFragment = new MyListFragment();
|
|
||||||
if (position == 1) {
|
|
||||||
listFragment.setListAdapter(mConferenceAdapter);
|
|
||||||
listFragment.setContextMenu(R.menu.conference_context);
|
|
||||||
listFragment.setOnListItemClickListener((arg0, arg1, p, arg3) -> openConversationForBookmark(p));
|
|
||||||
} else {
|
|
||||||
|
|
||||||
listFragment.setListAdapter(mContactsAdapter);
|
|
||||||
listFragment.setContextMenu(R.menu.contact_context);
|
|
||||||
listFragment.setOnListItemClickListener((arg0, arg1, p, arg3) -> openConversationForContact(p));
|
|
||||||
}
|
|
||||||
fragments[position] = listFragment;
|
|
||||||
}
|
|
||||||
return fragments[position];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class MyListFragment extends ListFragment {
|
public static class MyListFragment extends ListFragment {
|
||||||
private AdapterView.OnItemClickListener mOnItemClickListener;
|
private AdapterView.OnItemClickListener mOnItemClickListener;
|
||||||
private int mResContextMenu;
|
private int mResContextMenu;
|
||||||
|
@ -1113,8 +1058,73 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ListPagerAdapter extends PagerAdapter {
|
||||||
|
FragmentManager fragmentManager;
|
||||||
|
MyListFragment[] fragments;
|
||||||
|
|
||||||
|
public ListPagerAdapter(FragmentManager fm) {
|
||||||
|
fragmentManager = fm;
|
||||||
|
fragments = new MyListFragment[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void requestFocus(int pos) {
|
||||||
|
if (fragments.length > pos) {
|
||||||
|
fragments[pos].getListView().requestFocus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
|
||||||
|
assert (0 <= position && position < fragments.length);
|
||||||
|
FragmentTransaction trans = fragmentManager.beginTransaction();
|
||||||
|
trans.remove(fragments[position]);
|
||||||
|
trans.commit();
|
||||||
|
fragments[position] = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Fragment instantiateItem(@NonNull ViewGroup container, int position) {
|
||||||
|
Fragment fragment = getItem(position);
|
||||||
|
FragmentTransaction trans = fragmentManager.beginTransaction();
|
||||||
|
trans.add(container.getId(), fragment, "fragment:" + position);
|
||||||
|
trans.commit();
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
return fragments.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isViewFromObject(@NonNull View view, @NonNull Object fragment) {
|
||||||
|
return ((Fragment) fragment).getView() == view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Fragment getItem(int position) {
|
||||||
|
assert (0 <= position && position < fragments.length);
|
||||||
|
if (fragments[position] == null) {
|
||||||
|
final MyListFragment listFragment = new MyListFragment();
|
||||||
|
if (position == 1) {
|
||||||
|
listFragment.setListAdapter(mConferenceAdapter);
|
||||||
|
listFragment.setContextMenu(R.menu.conference_context);
|
||||||
|
listFragment.setOnListItemClickListener((arg0, arg1, p, arg3) -> openConversationForBookmark(p));
|
||||||
|
} else {
|
||||||
|
|
||||||
|
listFragment.setListAdapter(mContactsAdapter);
|
||||||
|
listFragment.setContextMenu(R.menu.contact_context);
|
||||||
|
listFragment.setOnListItemClickListener((arg0, arg1, p, arg3) -> openConversationForContact(p));
|
||||||
|
}
|
||||||
|
fragments[position] = listFragment;
|
||||||
|
}
|
||||||
|
return fragments[position];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class Invite extends XmppUri {
|
private class Invite extends XmppUri {
|
||||||
|
|
||||||
|
public String account;
|
||||||
|
|
||||||
public Invite(final Uri uri) {
|
public Invite(final Uri uri) {
|
||||||
super(uri);
|
super(uri);
|
||||||
}
|
}
|
||||||
|
@ -1127,8 +1137,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
||||||
super(uri, safeSource);
|
super(uri, safeSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String account;
|
|
||||||
|
|
||||||
boolean invite() {
|
boolean invite() {
|
||||||
if (!isJidValid()) {
|
if (!isJidValid()) {
|
||||||
Toast.makeText(StartConversationActivity.this, R.string.invalid_jid, Toast.LENGTH_SHORT).show();
|
Toast.makeText(StartConversationActivity.this, R.string.invalid_jid, Toast.LENGTH_SHORT).show();
|
||||||
|
|
|
@ -15,7 +15,8 @@
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_scan_qr_code"
|
android:id="@+id/action_scan_qr_code"
|
||||||
android:title="@string/scan_qr_code"
|
android:title="@string/scan_qr_code"
|
||||||
app:showAsAction="never"/>
|
android:icon="?attr/icon_scan_qr_code"
|
||||||
|
app:showAsAction="always"/>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_hide_offline"
|
android:id="@+id/action_hide_offline"
|
||||||
|
|
Loading…
Reference in a new issue