mirror of
https://github.com/nerzhul/ownCloud-SMS-App.git
synced 2025-06-10 17:36:16 +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"
|
||||
package="fr.unix_experience.owncloud_sms"
|
||||
android:versionCode="27"
|
||||
android:versionName="0.18.5" >
|
||||
|
||||
<!-- From Android 4.0 to 5.1 -->
|
||||
android:versionName="0.18.5" > <!-- From Android 4.0 to 5.1 -->
|
||||
<uses-sdk
|
||||
android:maxSdkVersion="22"
|
||||
android:minSdkVersion="14"
|
||||
@ -110,7 +108,7 @@
|
||||
android:label="@string/title_activity_login" >
|
||||
</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" >
|
||||
</activity>
|
||||
<activity
|
||||
@ -133,7 +131,7 @@
|
||||
</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" >
|
||||
</activity>
|
||||
</application>
|
||||
|
@ -5,17 +5,22 @@ import java.util.ArrayList;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.app.Activity;
|
||||
import android.app.ListActivity;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
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.unix_experience.owncloud_sms.R;
|
||||
import fr.unix_experience.owncloud_sms.adapters.ContactListAdapter;
|
||||
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;
|
||||
ContactListAdapter adapter;
|
||||
@ -49,30 +54,37 @@ public class ContactListActivity extends ListActivity implements ASyncContactLoa
|
||||
android.R.color.holo_red_light);
|
||||
|
||||
adapter = new ContactListAdapter(getBaseContext(),
|
||||
android.R.layout.simple_list_item_1,
|
||||
android.R.layout.simple_spinner_item,
|
||||
objects,
|
||||
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) {
|
||||
if (element.name.equals(accountName)) {
|
||||
// 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
|
||||
_layout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
_layout.setRefreshing(true);
|
||||
sp.setVisibility(View.INVISIBLE);
|
||||
contactProgressBar.setVisibility(View.VISIBLE);
|
||||
(new Handler()).post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
objects.clear();
|
||||
adapter.notifyDataSetChanged();
|
||||
new ContactLoadTask(element, getBaseContext(), adapter, objects).execute();
|
||||
_layout.setRefreshing(false);
|
||||
new ContactLoadTask(element, getBaseContext(), adapter, objects, _layout, contactProgressBar, sp).execute();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,7 +1,10 @@
|
||||
package fr.unix_experience.owncloud_sms.adapters;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -13,14 +16,16 @@ public class ContactListAdapter extends ArrayAdapter<String> {
|
||||
private final ArrayList<String> _objects;
|
||||
private static int _itemLayout;
|
||||
private static int _fieldId;
|
||||
private Activity _activity;
|
||||
|
||||
public ContactListAdapter(final Context context, final int resource,
|
||||
final ArrayList<String> objects, final int itemLayout,
|
||||
final int fieldId) {
|
||||
super(context, resource, resource, objects);
|
||||
final int fieldId, final Activity activity) {
|
||||
super(context, resource, objects);
|
||||
_objects = objects;
|
||||
_itemLayout = itemLayout;
|
||||
_fieldId = fieldId;
|
||||
_activity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -42,15 +47,11 @@ public class ContactListAdapter extends ArrayAdapter<String> {
|
||||
final TextView label = (TextView) v.findViewById(_fieldId);
|
||||
if (label != null) {
|
||||
label.setText(element);
|
||||
label.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(final View v) {
|
||||
// @TODO
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
private static final String TAG = ContactListAdapter.class.getSimpleName();
|
||||
}
|
||||
|
@ -8,6 +8,10 @@ import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
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.JSONException;
|
||||
@ -26,9 +30,13 @@ public interface ASyncContactLoad {
|
||||
private final Context _context;
|
||||
private ContactListAdapter _adapter;
|
||||
private ArrayList<String> _objects;
|
||||
private SwipeRefreshLayout _layout;
|
||||
private ProgressBar _pg;
|
||||
private Spinner _contactSpinner;
|
||||
|
||||
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) {
|
||||
_accountMgr = AccountManager.get(context);
|
||||
}
|
||||
@ -37,6 +45,9 @@ public interface ASyncContactLoad {
|
||||
_context = context;
|
||||
_adapter = adapter;
|
||||
_objects = objects;
|
||||
_layout = layout;
|
||||
_pg = pg;
|
||||
_contactSpinner = sp;
|
||||
}
|
||||
@Override
|
||||
protected Boolean doInBackground(final Void... params) {
|
||||
@ -72,37 +83,37 @@ public interface ASyncContactLoad {
|
||||
// Read all contacts
|
||||
ContentResolver cr = _context.getContentResolver();
|
||||
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
|
||||
null, null, null, null);
|
||||
null, null, null, null);
|
||||
if (cur.getCount() > 0) {
|
||||
while (cur.moveToNext()) {
|
||||
String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
|
||||
String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
|
||||
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
|
||||
Cursor pCur = cr.query(
|
||||
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
|
||||
null,
|
||||
ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",
|
||||
new String[]{id}, null);
|
||||
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
|
||||
null,
|
||||
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
|
||||
new String[]{id}, null);
|
||||
while (pCur.moveToNext()) {
|
||||
String phoneNo = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
|
||||
phoneNo = phoneNo.replaceAll(" ", "");
|
||||
if (serverPhoneList.contains(phoneNo)) {
|
||||
if (!_objects.contains(name)) {
|
||||
_objects.add(name);
|
||||
String phoneNo = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
|
||||
phoneNo = phoneNo.replaceAll(" ", "");
|
||||
if (serverPhoneList.contains(phoneNo)) {
|
||||
if (!_objects.contains(name)) {
|
||||
_objects.add(name);
|
||||
}
|
||||
serverPhoneList.remove(phoneNo);
|
||||
}
|
||||
serverPhoneList.remove(phoneNo);
|
||||
}
|
||||
}
|
||||
pCur.close();
|
||||
pCur.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
cur.close();
|
||||
|
||||
for (String phone: serverPhoneList) {
|
||||
for (String phone : serverPhoneList) {
|
||||
_objects.add(phone);
|
||||
}
|
||||
|
||||
@ -116,11 +127,18 @@ public interface ASyncContactLoad {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
protected void onPostExecute(final Boolean success) {
|
||||
_adapter.notifyDataSetChanged();
|
||||
_layout.setRefreshing(false);
|
||||
if (_pg != null) {
|
||||
_pg.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
if (_contactSpinner != null) {
|
||||
_contactSpinner.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,14 +33,24 @@
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" >
|
||||
android:layout_width="match_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>
|
||||
</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_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="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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user