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() {
final ListView l = this.binding.messagesView;
return l.getLastVisiblePosition() == l.getAdapter().getCount() -1 && l.getChildAt(l.getChildCount() - 1).getBottom() <= l.getHeight();
if (this.binding == null) {
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) {

View File

@ -84,6 +84,8 @@ import eu.siacs.conversations.xmpp.jid.Jid;
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 contact_context_id;
private ListPagerAdapter mListPagerAdapter;
@ -97,10 +99,8 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
private Invite mPendingInvite = null;
private EditText mSearchEditText;
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 boolean mHideOfflineContacts = false;
private MenuItem.OnActionExpandListener mOnActionExpandListener = new MenuItem.OnActionExpandListener() {
@Override
@ -122,35 +122,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
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() {
@Override
@ -167,7 +138,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
};
private TextView.OnEditorActionListener mSearchDone = new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
@ -202,6 +172,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
};
private String mInitialJid;
private Pair<Integer, Intent> mPostponedActivityResult;
private Toast mToast;
private UiCallback<Conversation> mAdhocConferenceCallback = new UiCallback<Conversation>() {
@Override
public void success(final Conversation conversation) {
@ -221,8 +192,56 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
}
};
private Toast mToast;
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() {
if (mToast != null) {
@ -245,9 +264,21 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
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) -> {
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);
} else {
showCreateConferenceDialog();
@ -337,7 +368,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
Bookmark bookmark = (Bookmark) conferences.get(position);
Intent shareIntent = new Intent();
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");
try {
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());
}
if (contact.isSelf()) {
switchToConversation(contact,null);
switchToConversation(contact, null);
return true;
} else if (contact.showInRoster()) {
throw new EnterJidDialog.JidError(getString(R.string.contact_already_exists));
} else {
xmppConnectionService.createContact(contact);
if (invite != null && invite.hasFingerprints()) {
xmppConnectionService.verifyFingerprints(contact,invite.getFingerprints());
xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints());
}
switchToConversation(contact, invite == null ? null : invite.getBody());
return true;
@ -478,11 +509,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
final AlertDialog dialog = builder.create();
dialog.show();
mCurrentDialog = dialog;
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(final View v) {
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(v -> {
if (!xmppConnectionServiceBound) {
return;
}
@ -519,12 +546,11 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
}
} else {
final Conversation conversation = xmppConnectionService
.findOrCreateConversation(account,conferenceJid, true, true, true);
.findOrCreateConversation(account, conferenceJid, true, true, true);
dialog.dismiss();
mCurrentDialog = null;
switchToConversation(conversation);
}
}
});
}
@ -580,30 +606,17 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
protected void switchToConversation(Contact contact, String body) {
Conversation conversation = xmppConnectionService
.findOrCreateConversation(contact.getAccount(),
contact.getJid(),false,true);
contact.getJid(), false, true);
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
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.start_conversation, menu);
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);
mMenuSearchView = menu.findItem(R.id.action_search);
mMenuSearchView.setOnActionExpandListener(mOnActionExpandListener);
@ -737,7 +750,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
}
@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[0] == PackageManager.PERMISSION_GRANTED) {
if (requestCode == REQUEST_SYNC_CONTACTS && xmppConnectionServiceBound) {
@ -808,7 +821,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
case Intent.ACTION_VIEW:
Uri uri = intent.getData();
if (uri != null) {
Invite invite = new Invite(intent.getData(),false);
Invite invite = new Invite(intent.getData(), false);
invite.account = intent.getStringExtra("account");
return invite.invite();
} else {
@ -819,11 +832,11 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
}
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)) {
Conversation muc = xmppConnectionService.findFirstMuc(invite.getJid());
if (muc != null) {
switchToConversation(muc,invite.getBody(),false);
switchToConversation(muc, invite.getBody(), false);
return true;
} else {
showJoinConferenceDialog(invite.getJid().toBareJid().toString());
@ -835,11 +848,11 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} else if (contacts.size() == 1) {
Contact contact = contacts.get(0);
if (!invite.isSafeSource() && invite.hasFingerprints()) {
displayVerificationWarningDialog(contact,invite);
displayVerificationWarningDialog(contact, invite);
} else {
if (invite.hasFingerprints()) {
if(xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints())) {
Toast.makeText(this,R.string.verified_fingerprints,Toast.LENGTH_SHORT).show();
if (xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints())) {
Toast.makeText(this, R.string.verified_fingerprints, Toast.LENGTH_SHORT).show();
}
}
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);
TextView warning = (TextView) view.findViewById(R.id.warning);
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);
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);
builder.setView(view);
@ -940,11 +953,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
invalidateOptionsMenu();
}
public static void launch(Context context) {
final Intent intent = new Intent(context,StartConversationActivity.class);
context.startActivity(intent);
}
@Override
public void OnUpdateBlocklist(final Status status) {
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 {
private AdapterView.OnItemClickListener mOnItemClickListener;
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 {
public String account;
public Invite(final Uri uri) {
super(uri);
}
@ -1124,14 +1134,12 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
}
public Invite(Uri uri, boolean safeSource) {
super(uri,safeSource);
super(uri, safeSource);
}
public String account;
boolean invite() {
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;
}
if (getJid() != null) {

View File

@ -15,7 +15,8 @@
<item
android:id="@+id/action_scan_qr_code"
android:title="@string/scan_qr_code"
app:showAsAction="never"/>
android:icon="?attr/icon_scan_qr_code"
app:showAsAction="always"/>
<item
android:id="@+id/action_hide_offline"