bring scan button to StartConversationActivity

This commit is contained in:
Daniel Gultsch 2018-02-26 21:18:36 +01:00
parent 3bd42230f2
commit 12031515d1
3 changed files with 1076 additions and 1059 deletions

View File

@ -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) {

View File

@ -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) {
@ -245,9 +264,21 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
new EmojiService(this).init(); new EmojiService(this).init();
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();
@ -337,7 +368,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
Bookmark bookmark = (Bookmark) conferences.get(position); Bookmark bookmark = (Bookmark) conferences.get(position);
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().toBareJid().toString()+"?join"); shareIntent.putExtra(Intent.EXTRA_TEXT, "xmpp:" + bookmark.getJid().toBareJid().toString() + "?join");
shareIntent.setType("text/plain"); shareIntent.setType("text/plain");
try { try {
startActivity(Intent.createChooser(shareIntent, getText(R.string.share_uri_with))); startActivity(Intent.createChooser(shareIntent, getText(R.string.share_uri_with)));
@ -438,14 +469,14 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
contact.setServerName(invite.getName()); contact.setServerName(invite.getName());
} }
if (contact.isSelf()) { if (contact.isSelf()) {
switchToConversation(contact,null); switchToConversation(contact, null);
return true; return true;
} else if (contact.showInRoster()) { } else if (contact.showInRoster()) {
throw new EnterJidDialog.JidError(getString(R.string.contact_already_exists)); throw new EnterJidDialog.JidError(getString(R.string.contact_already_exists));
} else { } else {
xmppConnectionService.createContact(contact); xmppConnectionService.createContact(contact);
if (invite != null && invite.hasFingerprints()) { if (invite != null && invite.hasFingerprints()) {
xmppConnectionService.verifyFingerprints(contact,invite.getFingerprints()); xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints());
} }
switchToConversation(contact, invite == null ? null : invite.getBody()); switchToConversation(contact, invite == null ? null : invite.getBody());
return true; return true;
@ -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;
} }
@ -519,12 +546,11 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} }
} else { } else {
final Conversation conversation = xmppConnectionService final Conversation conversation = xmppConnectionService
.findOrCreateConversation(account,conferenceJid, true, true, true); .findOrCreateConversation(account, conferenceJid, true, true, true);
dialog.dismiss(); dialog.dismiss();
mCurrentDialog = null; mCurrentDialog = null;
switchToConversation(conversation); switchToConversation(conversation);
} }
}
}); });
} }
@ -580,30 +606,17 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
protected void switchToConversation(Contact contact, String body) { protected void switchToConversation(Contact contact, String body) {
Conversation conversation = xmppConnectionService Conversation conversation = xmppConnectionService
.findOrCreateConversation(contact.getAccount(), .findOrCreateConversation(contact.getAccount(),
contact.getJid(),false,true); contact.getJid(), false, true);
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);
@ -737,7 +750,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} }
@Override @Override
public void onRequestPermissionsResult(int requestCode,@NonNull String permissions[],@NonNull int[] grantResults) { public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
if (grantResults.length > 0) if (grantResults.length > 0)
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (requestCode == REQUEST_SYNC_CONTACTS && xmppConnectionServiceBound) { if (requestCode == REQUEST_SYNC_CONTACTS && xmppConnectionServiceBound) {
@ -808,7 +821,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
case Intent.ACTION_VIEW: case Intent.ACTION_VIEW:
Uri uri = intent.getData(); Uri uri = intent.getData();
if (uri != null) { if (uri != null) {
Invite invite = new Invite(intent.getData(),false); Invite invite = new Invite(intent.getData(), false);
invite.account = intent.getStringExtra("account"); invite.account = intent.getStringExtra("account");
return invite.invite(); return invite.invite();
} else { } else {
@ -819,11 +832,11 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} }
private boolean handleJid(Invite invite) { private boolean handleJid(Invite invite) {
List<Contact> contacts = xmppConnectionService.findContacts(invite.getJid(),invite.account); List<Contact> contacts = xmppConnectionService.findContacts(invite.getJid(), invite.account);
if (invite.isAction(XmppUri.ACTION_JOIN)) { if (invite.isAction(XmppUri.ACTION_JOIN)) {
Conversation muc = xmppConnectionService.findFirstMuc(invite.getJid()); Conversation muc = xmppConnectionService.findFirstMuc(invite.getJid());
if (muc != null) { if (muc != null) {
switchToConversation(muc,invite.getBody(),false); switchToConversation(muc, invite.getBody(), false);
return true; return true;
} else { } else {
showJoinConferenceDialog(invite.getJid().toBareJid().toString()); showJoinConferenceDialog(invite.getJid().toBareJid().toString());
@ -835,11 +848,11 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} else if (contacts.size() == 1) { } else if (contacts.size() == 1) {
Contact contact = contacts.get(0); Contact contact = contacts.get(0);
if (!invite.isSafeSource() && invite.hasFingerprints()) { if (!invite.isSafeSource() && invite.hasFingerprints()) {
displayVerificationWarningDialog(contact,invite); displayVerificationWarningDialog(contact, invite);
} else { } else {
if (invite.hasFingerprints()) { if (invite.hasFingerprints()) {
if(xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints())) { if (xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints())) {
Toast.makeText(this,R.string.verified_fingerprints,Toast.LENGTH_SHORT).show(); Toast.makeText(this, R.string.verified_fingerprints, Toast.LENGTH_SHORT).show();
} }
} }
if (invite.account != null) { if (invite.account != null) {
@ -868,10 +881,10 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
final CheckBox isTrustedSource = (CheckBox) view.findViewById(R.id.trusted_source); final CheckBox isTrustedSource = (CheckBox) view.findViewById(R.id.trusted_source);
TextView warning = (TextView) view.findViewById(R.id.warning); TextView warning = (TextView) view.findViewById(R.id.warning);
String jid = contact.getJid().toBareJid().toString(); String jid = contact.getJid().toBareJid().toString();
SpannableString spannable = new SpannableString(getString(R.string.verifying_omemo_keys_trusted_source,jid,contact.getDisplayName())); SpannableString spannable = new SpannableString(getString(R.string.verifying_omemo_keys_trusted_source, jid, contact.getDisplayName()));
int start = spannable.toString().indexOf(jid); int start = spannable.toString().indexOf(jid);
if (start >= 0) { if (start >= 0) {
spannable.setSpan(new TypefaceSpan("monospace"),start,start + jid.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.setSpan(new TypefaceSpan("monospace"), start, start + jid.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} }
warning.setText(spannable); warning.setText(spannable);
builder.setView(view); builder.setView(view);
@ -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);
} }
@ -1124,14 +1134,12 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} }
public Invite(Uri uri, boolean safeSource) { public Invite(Uri uri, boolean safeSource) {
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();
return false; return false;
} }
if (getJid() != null) { if (getJid() != null) {

View File

@ -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"