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) {
@ -248,6 +267,18 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
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();
@ -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;
}
@ -524,7 +551,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
mCurrentDialog = null;
switchToConversation(conversation);
}
}
});
}
@ -584,26 +610,13 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
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);
@ -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);
}
@ -1127,8 +1137,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
super(uri, safeSource);
}
public String account;
boolean invite() {
if (!isJidValid()) {
Toast.makeText(StartConversationActivity.this, R.string.invalid_jid, Toast.LENGTH_SHORT).show();

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"