Guest User

Untitled

a guest
Mar 26th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.69 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent">
  5.  
  6. <ListView
  7. android:layout_width="match_parent"
  8. android:layout_height="wrap_content"
  9. android:id="@+id/contacts_listview"/>
  10.  
  11. </RelativeLayout>
  12.  
  13. <?xml version="1.0" encoding="utf-8"?>
  14. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  15. android:layout_width="match_parent"
  16. android:layout_height="wrap_content"
  17. android:gravity="center_vertical"
  18. android:orientation="horizontal"
  19. android:minHeight="?android:attr/listPreferredItemHeight"
  20. android:padding="16dp">
  21.  
  22. <ImageView
  23. android:id="@+id/contact_item_icon"
  24. android:layout_width="50dp"
  25. android:layout_height="50dp"/>
  26.  
  27. <LinearLayout
  28. android:layout_width="0dp"
  29. android:layout_height="wrap_content"
  30. android:layout_weight="1"
  31. android:orientation="vertical"
  32. android:paddingLeft="16dp">
  33.  
  34. <TextView
  35. android:id="@+id/contact_item_name"
  36. android:layout_width="wrap_content"
  37. android:layout_height="wrap_content"
  38. android:text="Feel The Light" />
  39.  
  40.  
  41. <TextView
  42. android:id="@+id/contact_item_number"
  43. android:layout_width="wrap_content"
  44. android:layout_height="wrap_content"
  45. android:text="Home" />
  46.  
  47.  
  48.  
  49. </LinearLayout>
  50.  
  51. <ImageButton
  52. android:layout_width="wrap_content"
  53. android:layout_height="wrap_content"
  54. android:src="@drawable/ic_user_audio_call_dark"/>
  55.  
  56. <ImageButton
  57. android:layout_width="wrap_content"
  58. android:layout_height="wrap_content"
  59. android:src="@drawable/ic_user_video_call_dark"/>
  60.  
  61. <Button
  62. android:layout_width="wrap_content"
  63. android:layout_height="30dp"
  64. android:text="Invite"
  65. android:background="@drawable/selector_button_green_oval"
  66. android:textColor="@color/white"/>
  67.  
  68. </LinearLayout>
  69.  
  70. public class ContactsAdapter extends ArrayAdapter<ContactItem> {
  71. private static final String LOG_TAG = ContactsAdapter.class.getSimpleName();
  72.  
  73. public ContactsAdapter(Activity context, List<ContactItem> contactItems) {
  74. super(context, 0, contactItems);
  75. }
  76.  
  77. @Override
  78. public View getView(int position, View convertView, ViewGroup parent) {
  79.  
  80. ContactItem contactItem = getItem(position);
  81.  
  82. if (convertView == null) {
  83. convertView = LayoutInflater.from(getContext()).inflate(R.layout.contact_list_item, parent, false);
  84. }
  85.  
  86. ImageView contactImage = (ImageView) convertView.findViewById(R.id.contact_item_icon);
  87. contactImage.setImageResource(contactItem.contactImage);
  88.  
  89. TextView contactName = (TextView) convertView.findViewById(R.id.contact_item_name);
  90. contactName.setText(contactItem.contactName);
  91.  
  92. TextView contactNumber = (TextView) convertView.findViewById(R.id.contact_item_number);
  93. contactNumber.setText(contactItem.contactNumber);
  94.  
  95. return convertView;
  96. }
  97. }
  98.  
  99. public class ContactsListFragment extends Fragment {
  100.  
  101. private ContactsAdapter contactsAdapter;
  102.  
  103. public static ContactsListFragment newInstance() {
  104. return new ContactsListFragment();
  105. }
  106.  
  107. public ContactsListFragment() {
  108.  
  109. }
  110.  
  111. ArrayList<String> contactName = new ArrayList<>();
  112. ArrayList<String> contactNumber = new ArrayList<>();
  113.  
  114. ArrayList<ContactItem> contactsAvailable = new ArrayList<>();
  115. ArrayList<ContactItem> contactsInvite = new ArrayList<>();
  116.  
  117. @Override
  118. public void onCreate(@Nullable Bundle savedInstanceState) {
  119. super.onCreate(savedInstanceState);
  120.  
  121.  
  122.  
  123. Cursor cursor = getActivity().getContentResolver().query(
  124. ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null
  125. );
  126.  
  127. String currentNumber = "";
  128.  
  129. while (cursor.moveToNext()) {
  130.  
  131. String name = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
  132. String number = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
  133. number = number.replaceAll(" ", "");
  134.  
  135. char c = number.charAt(0);
  136. char c1 = number.charAt(1);
  137. String s = Character.toString(c)+Character.toString(c1);
  138.  
  139. if (s.equals("00")) {
  140. number = number.replaceAll("00", "+");
  141. }
  142.  
  143. if (number.length() == 12) {
  144. number = "+" + number;
  145. }
  146.  
  147. if (number.length() == 13) {
  148. if (!currentNumber.equals(number)) {
  149. contactName.add(name);
  150. contactNumber.add(number);
  151. }
  152.  
  153. }
  154.  
  155. currentNumber = number;
  156.  
  157. }
  158.  
  159. }
  160.  
  161. @Nullable
  162. @Override
  163. public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  164.  
  165. final View rootView = inflater.inflate(R.layout.fragment_contacts_list, container, false);
  166.  
  167. QBPagedRequestBuilder pagedRequestBuilder = new QBPagedRequestBuilder();
  168. pagedRequestBuilder.setPage(1);
  169. pagedRequestBuilder.setPerPage(50);
  170.  
  171. QBUsers.getUsersByLogins(contactNumber, pagedRequestBuilder, new QBEntityCallback<ArrayList<QBUser>>() {
  172. @Override
  173. public void onSuccess(ArrayList<QBUser> qbUsers, Bundle bundle) {
  174. for (int i = 0; i < qbUsers.size(); i++) {
  175. ContactItem contactItem = new ContactItem(qbUsers.get(i).getFullName(), qbUsers.get(i).getLogin(), R.drawable.ic_launcher);
  176. contactsAvailable.add(contactItem);
  177.  
  178. }
  179.  
  180. contactsAdapter = new ContactsAdapter(getActivity(), contactsAvailable);
  181.  
  182. ListView listView = (ListView) rootView.findViewById(R.id.contacts_listview_available);
  183. listView.setAdapter(contactsAdapter);
  184.  
  185. }
  186.  
  187. @Override
  188. public void onError(QBResponseException e) {
  189. Toast.makeText(getActivity(), e.toString(), Toast.LENGTH_LONG).show();
  190. }
  191. });
  192.  
  193.  
  194.  
  195. return rootView;
  196.  
  197. }
  198. }
Add Comment
Please, Sign In to add comment