mirror of
				https://github.com/nerzhul/ownCloud-SMS-App.git
				synced 2025-10-31 02:17:53 +00:00 
			
		
		
		
	Use spinner instead of big listview when selecting contacts
This commit is contained in:
		
							parent
							
								
									8e96526e3c
								
							
						
					
					
						commit
						1a6feec7ee
					
				| @ -2,9 +2,7 @@ | |||||||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|     package="fr.unix_experience.owncloud_sms" |     package="fr.unix_experience.owncloud_sms" | ||||||
|     android:versionCode="27" |     android:versionCode="27" | ||||||
|     android:versionName="0.18.5" > |     android:versionName="0.18.5" > <!-- From Android 4.0 to 5.1 --> | ||||||
| 
 |  | ||||||
|     <!-- From Android 4.0 to 5.1 --> |  | ||||||
|     <uses-sdk |     <uses-sdk | ||||||
|         android:maxSdkVersion="22" |         android:maxSdkVersion="22" | ||||||
|         android:minSdkVersion="14" |         android:minSdkVersion="14" | ||||||
| @ -110,7 +108,7 @@ | |||||||
|             android:label="@string/title_activity_login" > |             android:label="@string/title_activity_login" > | ||||||
|         </activity> |         </activity> | ||||||
|         <activity |         <activity | ||||||
|             android:name="fr.unix_experience.owncloud_sms.activities.remote_account.AccountListActivity" |             android:name=".activities.remote_account.AccountListActivity" | ||||||
|             android:label="@string/title_activity_select_account" > |             android:label="@string/title_activity_select_account" > | ||||||
|         </activity> |         </activity> | ||||||
|         <activity |         <activity | ||||||
| @ -133,7 +131,7 @@ | |||||||
|         </activity> |         </activity> | ||||||
|         --> |         --> | ||||||
|         <activity |         <activity | ||||||
|             android:name="fr.unix_experience.owncloud_sms.activities.remote_account.ContactListActivity" |             android:name=".activities.remote_account.ContactListActivity" | ||||||
|             android:label="@string/title_activity_select_contact" > |             android:label="@string/title_activity_select_contact" > | ||||||
|         </activity> |         </activity> | ||||||
|     </application> |     </application> | ||||||
|  | |||||||
| @ -5,17 +5,22 @@ import java.util.ArrayList; | |||||||
| 
 | 
 | ||||||
| import android.accounts.Account; | import android.accounts.Account; | ||||||
| import android.accounts.AccountManager; | import android.accounts.AccountManager; | ||||||
|  | import android.app.Activity; | ||||||
| import android.app.ListActivity; | import android.app.ListActivity; | ||||||
| import android.os.Bundle; | import android.os.Bundle; | ||||||
| import android.os.Handler; | import android.os.Handler; | ||||||
| import android.support.v4.widget.SwipeRefreshLayout; | import android.support.v4.widget.SwipeRefreshLayout; | ||||||
|  | import android.view.View; | ||||||
|  | import android.widget.ProgressBar; | ||||||
|  | import android.widget.SeekBar; | ||||||
|  | import android.widget.Spinner; | ||||||
| 
 | 
 | ||||||
| import fr.nrz.androidlib.adapters.AndroidAccountAdapter; | import fr.nrz.androidlib.adapters.AndroidAccountAdapter; | ||||||
| import fr.unix_experience.owncloud_sms.R; | import fr.unix_experience.owncloud_sms.R; | ||||||
| import fr.unix_experience.owncloud_sms.adapters.ContactListAdapter; | import fr.unix_experience.owncloud_sms.adapters.ContactListAdapter; | ||||||
| import fr.unix_experience.owncloud_sms.engine.ASyncContactLoad; | import fr.unix_experience.owncloud_sms.engine.ASyncContactLoad; | ||||||
| 
 | 
 | ||||||
| public class ContactListActivity extends ListActivity implements ASyncContactLoad { | public class ContactListActivity extends Activity implements ASyncContactLoad { | ||||||
| 
 | 
 | ||||||
| 	static AccountManager _accountMgr; | 	static AccountManager _accountMgr; | ||||||
| 	ContactListAdapter adapter; | 	ContactListAdapter adapter; | ||||||
| @ -49,30 +54,37 @@ public class ContactListActivity extends ListActivity implements ASyncContactLoa | |||||||
| 				android.R.color.holo_red_light); | 				android.R.color.holo_red_light); | ||||||
| 		 | 		 | ||||||
| 		adapter = new ContactListAdapter(getBaseContext(), | 		adapter = new ContactListAdapter(getBaseContext(), | ||||||
| 				android.R.layout.simple_list_item_1, | 				android.R.layout.simple_spinner_item, | ||||||
| 				objects, | 				objects, | ||||||
| 				R.layout.contact_list_item, | 				R.layout.contact_list_item, | ||||||
| 				R.id.contactname); | 				R.id.contactname, this); | ||||||
| 		 | 		 | ||||||
| 		setListAdapter(adapter); | 		final Spinner sp = (Spinner) findViewById(R.id.contact_spinner); | ||||||
|  | 		sp.setVisibility(View.INVISIBLE); | ||||||
|  | 		sp.setAdapter(adapter); | ||||||
|  | 
 | ||||||
|  | 		final ProgressBar contactProgressBar = (ProgressBar) findViewById(R.id.contactlist_pgbar); | ||||||
| 
 | 
 | ||||||
| 		for (final Account element : myAccountList) { | 		for (final Account element : myAccountList) { | ||||||
| 			if (element.name.equals(accountName)) { | 			if (element.name.equals(accountName)) { | ||||||
| 				// Load "contacts" | 				// Load "contacts" | ||||||
| 				new ContactLoadTask(element, getBaseContext(), adapter, objects).execute(); | 				contactProgressBar.setVisibility(View.VISIBLE); | ||||||
|  | 				sp.setVisibility(View.INVISIBLE); | ||||||
|  | 				new ContactLoadTask(element, getBaseContext(), adapter, objects, _layout, contactProgressBar, sp).execute(); | ||||||
| 
 | 
 | ||||||
| 				// Add refresh handler | 				// Add refresh handler | ||||||
| 				_layout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { | 				_layout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { | ||||||
| 					@Override | 					@Override | ||||||
| 					public void onRefresh() { | 					public void onRefresh() { | ||||||
| 						_layout.setRefreshing(true); | 						_layout.setRefreshing(true); | ||||||
|  | 						sp.setVisibility(View.INVISIBLE); | ||||||
|  | 						contactProgressBar.setVisibility(View.VISIBLE); | ||||||
| 						(new Handler()).post(new Runnable() { | 						(new Handler()).post(new Runnable() { | ||||||
| 							@Override | 							@Override | ||||||
| 							public void run() { | 							public void run() { | ||||||
| 								objects.clear(); | 								objects.clear(); | ||||||
| 								adapter.notifyDataSetChanged(); | 								adapter.notifyDataSetChanged(); | ||||||
| 								new ContactLoadTask(element, getBaseContext(), adapter, objects).execute(); | 								new ContactLoadTask(element, getBaseContext(), adapter, objects, _layout, contactProgressBar, sp).execute(); | ||||||
| 								_layout.setRefreshing(false); |  | ||||||
| 							} | 							} | ||||||
| 						}); | 						}); | ||||||
| 					} | 					} | ||||||
|  | |||||||
| @ -1,7 +1,10 @@ | |||||||
| package fr.unix_experience.owncloud_sms.adapters; | package fr.unix_experience.owncloud_sms.adapters; | ||||||
| 
 | 
 | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
|  | 
 | ||||||
|  | import android.app.Activity; | ||||||
| import android.content.Context; | import android.content.Context; | ||||||
|  | import android.content.Intent; | ||||||
| import android.view.LayoutInflater; | import android.view.LayoutInflater; | ||||||
| import android.view.View; | import android.view.View; | ||||||
| import android.view.ViewGroup; | import android.view.ViewGroup; | ||||||
| @ -13,14 +16,16 @@ public class ContactListAdapter extends ArrayAdapter<String> { | |||||||
| 	private final ArrayList<String> _objects; | 	private final ArrayList<String> _objects; | ||||||
| 	private static int _itemLayout; | 	private static int _itemLayout; | ||||||
| 	private static int _fieldId; | 	private static int _fieldId; | ||||||
|  | 	private Activity _activity; | ||||||
| 	 | 	 | ||||||
| 	public ContactListAdapter(final Context context, final int resource, | 	public ContactListAdapter(final Context context, final int resource, | ||||||
| 				final ArrayList<String> objects, final int itemLayout, | 				final ArrayList<String> objects, final int itemLayout, | ||||||
| 				final int fieldId) { | 				final int fieldId, final Activity activity) { | ||||||
| 		super(context, resource, resource, objects); | 		super(context, resource, objects); | ||||||
| 		_objects = objects; | 		_objects = objects; | ||||||
| 		_itemLayout = itemLayout; | 		_itemLayout = itemLayout; | ||||||
| 		_fieldId = fieldId; | 		_fieldId = fieldId; | ||||||
|  | 		_activity = activity; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| @ -42,15 +47,11 @@ public class ContactListAdapter extends ArrayAdapter<String> { | |||||||
| 			final TextView label = (TextView) v.findViewById(_fieldId); | 			final TextView label = (TextView) v.findViewById(_fieldId); | ||||||
| 			if (label != null) { | 			if (label != null) { | ||||||
| 				label.setText(element); | 				label.setText(element); | ||||||
| 				label.setOnClickListener(new OnClickListener() { |  | ||||||
| 					@Override |  | ||||||
| 					public void onClick(final View v) { |  | ||||||
| 						// @TODO |  | ||||||
| 					} |  | ||||||
| 				}); |  | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		return v; | 		return v; | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
|  | 	private static final String TAG = ContactListAdapter.class.getSimpleName(); | ||||||
| } | } | ||||||
|  | |||||||
| @ -8,6 +8,10 @@ import android.database.Cursor; | |||||||
| import android.net.Uri; | import android.net.Uri; | ||||||
| import android.os.AsyncTask; | import android.os.AsyncTask; | ||||||
| import android.provider.ContactsContract; | import android.provider.ContactsContract; | ||||||
|  | import android.support.v4.widget.SwipeRefreshLayout; | ||||||
|  | import android.view.View; | ||||||
|  | import android.widget.ProgressBar; | ||||||
|  | import android.widget.Spinner; | ||||||
| 
 | 
 | ||||||
| import org.json.JSONArray; | import org.json.JSONArray; | ||||||
| import org.json.JSONException; | import org.json.JSONException; | ||||||
| @ -26,9 +30,13 @@ public interface ASyncContactLoad { | |||||||
| 		private final Context _context; | 		private final Context _context; | ||||||
| 		private ContactListAdapter _adapter; | 		private ContactListAdapter _adapter; | ||||||
| 		private ArrayList<String> _objects; | 		private ArrayList<String> _objects; | ||||||
|  | 		private SwipeRefreshLayout _layout; | ||||||
|  | 		private ProgressBar _pg; | ||||||
|  | 		private Spinner _contactSpinner; | ||||||
| 
 | 
 | ||||||
| 		public ContactLoadTask(final Account account, final Context context, | 		public ContactLoadTask(final Account account, final Context context, | ||||||
| 				ContactListAdapter adapter, ArrayList<String> objects) { | 				ContactListAdapter adapter, ArrayList<String> objects, SwipeRefreshLayout layout, | ||||||
|  | 				ProgressBar pg, Spinner sp) { | ||||||
| 			if (_accountMgr == null) { | 			if (_accountMgr == null) { | ||||||
| 				_accountMgr = AccountManager.get(context); | 				_accountMgr = AccountManager.get(context); | ||||||
| 			} | 			} | ||||||
| @ -37,6 +45,9 @@ public interface ASyncContactLoad { | |||||||
| 			_context = context; | 			_context = context; | ||||||
| 			_adapter = adapter; | 			_adapter = adapter; | ||||||
| 			_objects = objects; | 			_objects = objects; | ||||||
|  | 			_layout = layout; | ||||||
|  | 			_pg = pg; | ||||||
|  | 			_contactSpinner = sp; | ||||||
| 		} | 		} | ||||||
| 		@Override | 		@Override | ||||||
| 		protected Boolean doInBackground(final Void... params) { | 		protected Boolean doInBackground(final Void... params) { | ||||||
| @ -72,37 +83,37 @@ public interface ASyncContactLoad { | |||||||
| 				// Read all contacts | 				// Read all contacts | ||||||
| 				ContentResolver cr = _context.getContentResolver(); | 				ContentResolver cr = _context.getContentResolver(); | ||||||
| 				Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, | 				Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, | ||||||
| 				null, null, null, null); | 						null, null, null, null); | ||||||
| 				if (cur.getCount() > 0) { | 				if (cur.getCount() > 0) { | ||||||
| 					while (cur.moveToNext()) { | 					while (cur.moveToNext()) { | ||||||
| 						String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID)); | 						String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID)); | ||||||
| 						String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); | 						String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); | ||||||
| 						if (Integer.parseInt(cur.getString( | 						if (Integer.parseInt(cur.getString( | ||||||
| 							cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) { | 								cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) { | ||||||
| 
 | 
 | ||||||
| 							// Fetch all phone numbers | 							// Fetch all phone numbers | ||||||
| 							Cursor pCur = cr.query( | 							Cursor pCur = cr.query( | ||||||
| 							ContactsContract.CommonDataKinds.Phone.CONTENT_URI, | 									ContactsContract.CommonDataKinds.Phone.CONTENT_URI, | ||||||
| 							null, | 									null, | ||||||
| 							ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?", | 									ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", | ||||||
| 							new String[]{id}, null); | 									new String[]{id}, null); | ||||||
| 							while (pCur.moveToNext()) { | 							while (pCur.moveToNext()) { | ||||||
| 							String phoneNo = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); | 								String phoneNo = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); | ||||||
| 							phoneNo = phoneNo.replaceAll(" ", ""); | 								phoneNo = phoneNo.replaceAll(" ", ""); | ||||||
| 							if (serverPhoneList.contains(phoneNo)) { | 								if (serverPhoneList.contains(phoneNo)) { | ||||||
| 								if (!_objects.contains(name)) { | 									if (!_objects.contains(name)) { | ||||||
| 									_objects.add(name); | 										_objects.add(name); | ||||||
|  | 									} | ||||||
|  | 									serverPhoneList.remove(phoneNo); | ||||||
| 								} | 								} | ||||||
| 								serverPhoneList.remove(phoneNo); |  | ||||||
| 							} | 							} | ||||||
| 						} | 							pCur.close(); | ||||||
| 						pCur.close(); |  | ||||||
| 						} | 						} | ||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| 				cur.close(); | 				cur.close(); | ||||||
| 
 | 
 | ||||||
| 				for (String phone: serverPhoneList) { | 				for (String phone : serverPhoneList) { | ||||||
| 					_objects.add(phone); | 					_objects.add(phone); | ||||||
| 				} | 				} | ||||||
| 
 | 
 | ||||||
| @ -116,11 +127,18 @@ public interface ASyncContactLoad { | |||||||
| 				return false; | 				return false; | ||||||
| 			} | 			} | ||||||
| 			return true; | 			return true; | ||||||
| 
 |  | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		protected void onPostExecute(final Boolean success) { | 		protected void onPostExecute(final Boolean success) { | ||||||
| 			_adapter.notifyDataSetChanged(); | 			_adapter.notifyDataSetChanged(); | ||||||
|  | 			_layout.setRefreshing(false); | ||||||
|  | 			if (_pg != null) { | ||||||
|  | 				_pg.setVisibility(View.INVISIBLE); | ||||||
|  | 			} | ||||||
|  | 
 | ||||||
|  | 			if (_contactSpinner != null) { | ||||||
|  | 				_contactSpinner.setVisibility(View.VISIBLE); | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -33,14 +33,24 @@ | |||||||
| 	<LinearLayout | 	<LinearLayout | ||||||
| 		xmlns:android="http://schemas.android.com/apk/res/android" | 		xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
| 		android:orientation="vertical" | 		android:orientation="vertical" | ||||||
| 		android:layout_width="fill_parent" | 		android:layout_width="match_parent" | ||||||
| 		android:layout_height="fill_parent" > | 		android:layout_height="match_parent" > | ||||||
|  | 
 | ||||||
|  | 		<Spinner | ||||||
|  | 			android:layout_width="match_parent" | ||||||
|  | 			android:layout_height="wrap_content" | ||||||
|  | 			android:id="@+id/contact_spinner" | ||||||
|  | 			/> | ||||||
|  | 
 | ||||||
|  | 		<ProgressBar | ||||||
|  | 			style="?android:attr/progressBarStyleLarge" | ||||||
|  | 			android:layout_width="match_parent" | ||||||
|  | 			android:id="@+id/contactlist_pgbar" | ||||||
|  | 			android:layout_gravity="center_horizontal" | ||||||
|  | 			android:indeterminateOnly="true" | ||||||
|  | 			android:indeterminate="true" | ||||||
|  | 			android:layout_height="wrap_content"/> | ||||||
| 
 | 
 | ||||||
| 		<ListView |  | ||||||
| 			android:id="@android:id/list" |  | ||||||
| 			android:layout_width="fill_parent" |  | ||||||
| 			android:layout_height="fill_parent" |  | ||||||
| 			android:drawSelectorOnTop="false" /> |  | ||||||
| 
 | 
 | ||||||
| 	</LinearLayout> | 	</LinearLayout> | ||||||
| </android.support.v4.widget.SwipeRefreshLayout> | </android.support.v4.widget.SwipeRefreshLayout> | ||||||
| @ -170,9 +170,4 @@ Contributors and issue\'s reporters</string> | |||||||
|     <string name="err_sync_ocsms_not_installed_or_oc_upgrade_required">Error #18: OcSMS app is not installed or ownCloud awaiting for an upgrade</string> |     <string name="err_sync_ocsms_not_installed_or_oc_upgrade_required">Error #18: OcSMS app is not installed or ownCloud awaiting for an upgrade</string> | ||||||
|     <string name="err_fetch_phonelist">Invalid phonelist received from server.</string> |     <string name="err_fetch_phonelist">Invalid phonelist received from server.</string> | ||||||
|     <string name="err_proto_v2">Server doesn\'t support this feature. Ensure server version is at least 1.6.</string> |     <string name="err_proto_v2">Server doesn\'t support this feature. Ensure server version is at least 1.6.</string> | ||||||
|      |  | ||||||
|     <string name="title_activity_main">MainActivity</string> |  | ||||||
|     <string name="title_section1">Section 1</string> |  | ||||||
|     <string name="title_section2">Section 2</string> |  | ||||||
|     <string name="title_section3">Section 3</string> |  | ||||||
| </resources> | </resources> | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user