Skip to content

Commit

Permalink
1.8.4 release, see changelog.
Browse files Browse the repository at this point in the history
  • Loading branch information
broakenmedia committed Oct 2, 2018
1 parent 17c34ee commit b82c41a
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 25 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
compileSdkVersion 28
buildToolsVersion '28.0.2'
defaultConfig {
applicationId "com.wafflecopter.multicontactpickerexample"
minSdkVersion 16
targetSdkVersion 27
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
Expand All @@ -21,5 +21,5 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':multicontactpicker')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:appcompat-v7:28.0.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public void onClick(View view) {
.setSelectedContacts(results) //Optional - will pre-select contacts of your choice. String... or List<ContactResult>
.setLoadingType(MultiContactPicker.LOAD_ASYNC) //Optional - default LOAD_ASYNC (wait till all loaded vs stream results)
.limitToColumn(LimitColumn.NONE) //Optional - default NONE (Include phone + email, limiting to one can improve loading time)
.setActivityAnimations(android.R.anim.fade_in, android.R.anim.fade_out,
android.R.anim.fade_in,
android.R.anim.fade_out) //Optional - default: No animation overrides
.showPickerForResult(CONTACT_PICKER_REQUEST);
}else{
Toast.makeText(MainActivity.this, "Remember to go into settings and enable the contacts permission.", Toast.LENGTH_LONG).show();
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'

// NOTE: Do not place your application dependencies here; they belong
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Sep 04 11:57:37 BST 2018
#Sun Sep 30 17:56:50 BST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
12 changes: 8 additions & 4 deletions multicontactpicker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
group='com.github.xbroak'
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
compileSdkVersion 28
buildToolsVersion '28.0.2'

defaultConfig {
minSdkVersion 16
targetSdkVersion 27
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
configurations.all {
resolutionStrategy.force 'com.android.support:appcompat-v7:28.0.0'
resolutionStrategy.force 'com.android.support:design:28.0.0'
}
buildTypes {
release {
minifyEnabled false
Expand All @@ -21,7 +25,7 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.l4digital.fastscroll:fastscroll:1.1.2'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'io.reactivex.rxjava2:rxjava:2.1.6'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.os.Parcelable;

import com.wafflecopter.multicontactpicker.RxContacts.Contact;
import com.wafflecopter.multicontactpicker.RxContacts.PhoneNumber;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -18,7 +19,7 @@ public class ContactResult implements Parcelable {
private Uri mPhoto;
private Uri mThumbnail;
private List<String> mEmails = new ArrayList<>();
private List<String> mPhoneNumbers = new ArrayList<>();
private List<PhoneNumber> mPhoneNumbers = new ArrayList<>();

public String getContactID() {
return mContactID;
Expand Down Expand Up @@ -48,7 +49,7 @@ public List<String> getEmails() {
return mEmails;
}

public List<String> getPhoneNumbers() {
public List<PhoneNumber> getPhoneNumbers() {
return mPhoneNumbers;
}

Expand All @@ -69,7 +70,7 @@ protected ContactResult(Parcel in) {
this.mPhoto = in.readParcelable(Uri.class.getClassLoader());
this.mThumbnail = in.readParcelable(Uri.class.getClassLoader());
this.mEmails = in.createStringArrayList();
this.mPhoneNumbers = in.createStringArrayList();
in.readTypedList(this.mPhoneNumbers, PhoneNumber.CREATOR);
}

@Override
Expand All @@ -85,7 +86,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeParcelable(this.mPhoto, flags);
dest.writeParcelable(this.mThumbnail, flags);
dest.writeStringList(this.mEmails);
dest.writeStringList(this.mPhoneNumbers);
dest.writeTypedList(this.mPhoneNumbers);
}

@SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.Activity;
import android.content.Intent;
import android.support.annotation.AnimRes;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.annotation.StyleRes;
Expand Down Expand Up @@ -31,6 +32,7 @@ public static class Builder implements Serializable {
protected int bubbleTextColor;
protected int handleColor;
protected int trackColor;
protected Integer animationOpenEnter, animationOpenExit, animationCloseEnter, animationCloseExit;
protected LimitColumn columnLimit = LimitColumn.NONE;
protected Integer searchIconColor;
protected boolean hideScrollbar;
Expand Down Expand Up @@ -124,21 +126,36 @@ public Builder setSelectedContacts(ArrayList<ContactResult> selectedContacts){
return this;
}


public Builder setActivityAnimations(@AnimRes Integer animationOpenEnter, @AnimRes Integer animationOpenExit, @AnimRes Integer animationCloseEnter, @AnimRes Integer
animationCloseExit){
this.animationOpenEnter = animationOpenEnter;
this.animationOpenExit = animationOpenExit;
this.animationCloseEnter = animationCloseEnter;
this.animationCloseExit = animationCloseExit;
return this;
}

public void showPickerForResult(int requestCode) {
if (acc != null) {
Intent intent = new Intent(acc, MultiContactPickerActivity.class);
intent.putExtra("builder", this);
acc.startActivityForResult(intent, requestCode);
if(animationOpenEnter != null && animationOpenExit != null){
acc.overridePendingTransition(animationOpenEnter, animationOpenExit);
}
}else if(frag != null){
if(frag.getActivity() != null) {
Intent intent = new Intent(frag.getActivity(), MultiContactPickerActivity.class);
intent.putExtra("builder", this);
frag.startActivityForResult(intent, requestCode);
if(animationOpenEnter != null && animationOpenExit != null){
frag.getActivity().overridePendingTransition(animationOpenEnter, animationOpenExit);
}
}
}else{
throw new RuntimeException("Unable to find a context for intent. Is there a valid activity or fragment passed in the builder?");
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class MultiContactPickerActivity extends AppCompatActivity implements Mat
private MultiContactPicker.Builder builder;
private boolean allSelected = false;
private CompositeDisposable disposables;
private Integer animationCloseEnter, animationCloseExit;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -124,6 +125,13 @@ private void finishPicking(){
result.putExtra(EXTRA_RESULT_SELECTION, MultiContactPicker.buildResult(adapter.getSelectedContacts()));
setResult(RESULT_OK, result);
finish();
overrideAnimation();
}

private void overrideAnimation(){
if(animationCloseEnter != null && animationCloseExit != null){
overridePendingTransition(animationCloseEnter, animationCloseExit);
}
}

private void updateSelectBarContents(int totalSelectedContacts){
Expand All @@ -138,6 +146,10 @@ private void updateSelectBarContents(int totalSelectedContacts){
private void initialiseUI(MultiContactPicker.Builder builder){
setSupportActionBar(toolbar);
searchView.setOnQueryTextListener(this);

this.animationCloseEnter = builder.animationCloseEnter;
this.animationCloseExit = builder.animationCloseExit;

if(builder.bubbleColor != 0)
recyclerView.setBubbleColor(builder.bubbleColor);
if(builder.handleColor != 0)
Expand All @@ -164,12 +176,15 @@ private void initialiseUI(MultiContactPicker.Builder builder){

}



@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case android.R.id.home:
setResult(RESULT_CANCELED);
finish();
overrideAnimation();
break;
}
return super.onOptionsItemSelected(item);
Expand Down Expand Up @@ -284,6 +299,7 @@ public void onBackPressed() {
searchView.closeSearch();
} else {
super.onBackPressed();
overrideAnimation();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, final int i) {
contactViewHolder.vRoundLetterView.setBackgroundColor(contactItem.getBackgroundColor());

if (contactItem.getPhoneNumbers().size() > 0) {
String phoneNumber = contactItem.getPhoneNumbers().get(0).replaceAll("\\s+", "");
String phoneNumber = contactItem.getPhoneNumbers().get(0).getNumber().replaceAll("\\s+", "");
String displayName = contactItem.getDisplayName().replaceAll("\\s+", "");
if (!phoneNumber.equals(displayName)) {
contactViewHolder.tvNumber.setVisibility(View.VISIBLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
* limitations under the License.
*/

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;

class ColumnMapper {

Expand All @@ -42,12 +44,15 @@ static void mapEmail (Cursor cursor, Contact contact, int columnIndex) {
}
}

static void mapPhoneNumber (Cursor cursor, Contact contact, int columnIndex) {
String phoneNumber = cursor.getString(columnIndex);
static void mapPhoneNumber (Context con, Cursor cursor, Contact contact, int noColumnIndex, int typeColIndex) {
String phoneNumber = cursor.getString(noColumnIndex);
int phonetype = cursor.getInt(typeColIndex);
String customLabel = cursor.getString(typeColIndex);
String phoneLabel = (String) ContactsContract.CommonDataKinds.Phone.getTypeLabel(con.getResources(), phonetype, customLabel);
if (phoneNumber != null && !phoneNumber.isEmpty()) {
// Remove all whitespaces
phoneNumber = phoneNumber.replaceAll("\\s+","");
contact.getPhoneNumbers().add(phoneNumber.trim());
contact.getPhoneNumbers().add(new PhoneNumber(phoneLabel, phoneNumber.trim()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Contact implements Comparable<Contact> {
private Uri mPhoto;
private Uri mThumbnail;
private List<String> mEmails = new ArrayList<>();
private List<String> mPhoneNumbers = new ArrayList<>();
private List<PhoneNumber> mPhoneNumbers = new ArrayList<>();
private boolean isSelected;
private int backgroundColor = Color.BLUE;

Expand Down Expand Up @@ -77,11 +77,11 @@ public void setEmails(List<String> emails) {
mEmails = emails;
}

public List<String> getPhoneNumbers() {
public List<PhoneNumber> getPhoneNumbers() {
return mPhoneNumbers;
}

public void setPhoneNumbers(List<String> phoneNumbers) {
public void setPhoneNumbers(List<PhoneNumber> phoneNumbers) {
mPhoneNumbers = phoneNumbers;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.wafflecopter.multicontactpicker.RxContacts;

import android.os.Parcel;
import android.os.Parcelable;

public class PhoneNumber implements Parcelable {

private String typeLabel;
private String number;

PhoneNumber(String typeLabel, String number) {
this.typeLabel = typeLabel;
this.number = number;
}

private PhoneNumber(Parcel in) {
this.typeLabel = in.readString();
this.number = in.readString();
}

public String getTypeLabel() {
return typeLabel;
}

public void setTypeLabel(String typeLabel) {
this.typeLabel = typeLabel;
}

public String getNumber() {
return number;
}

public void setNumber(String number) {
this.number = number;
}

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.typeLabel);
dest.writeString(this.number);
}

public static final Creator<PhoneNumber> CREATOR = new Creator<PhoneNumber>() {
@Override
public PhoneNumber createFromParcel(Parcel in) {
return new PhoneNumber(in);
}

@Override
public PhoneNumber[] newArray(int size) {
return new PhoneNumber[size];
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ public class RxContacts {

private static final String[] NUMBER_PROJECTION = {
ContactsContract.CommonDataKinds.Phone.CONTACT_ID,
ContactsContract.CommonDataKinds.Phone.NUMBER
ContactsContract.CommonDataKinds.Phone.NUMBER,
ContactsContract.CommonDataKinds.Phone.TYPE
};




private ContentResolver mResolver;
private Context mContext;

public static Observable<Contact> fetch (@NonNull final LimitColumn columnLimitChoice, @NonNull final Context context) {
return Observable.create(new ObservableOnSubscribe<Contact>() {
Expand All @@ -75,6 +77,7 @@ public void subscribe(@NonNull ObservableEmitter<Contact> e) throws Exception {
}

private RxContacts(@NonNull Context context) {
mContext = context;
mResolver = context.getContentResolver();
}

Expand Down Expand Up @@ -154,8 +157,9 @@ private void getPhoneNumber(long id, Cursor cursor, Contact contact, int hasPhon
if (phoneCursor != null) {
phoneCursor.moveToFirst();
int phoneNumberColumnIndex = phoneCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
int phoneNumberTypeIndex = phoneCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE);
while (!phoneCursor.isAfterLast()) {
ColumnMapper.mapPhoneNumber(phoneCursor, contact, phoneNumberColumnIndex);
ColumnMapper.mapPhoneNumber(mContext, phoneCursor, contact, phoneNumberColumnIndex, phoneNumberTypeIndex);
phoneCursor.moveToNext();
}
phoneCursor.close();
Expand Down

0 comments on commit b82c41a

Please sign in to comment.