Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 26
compileSdkVersion 28
defaultConfig {
applicationId "androidbuffer.com.readcontactdemo"
minSdkVersion 15
targetSdkVersion 26
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -20,9 +20,8 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
compile 'com.android.support:recyclerview-v7:26.1.0+'
compile 'com.android.support:design:26.1.0+'
implementation 'com.android.support:design:28.0.0-rc01'
}
6 changes: 4 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="androidbuffer.com.readcontactdemo">

<uses-permission android:name="android.permission.INTERNET"/>
Expand All @@ -12,11 +13,12 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
android:fullBackupContent="true"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package androidbuffer.com.readcontactdemo;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -16,18 +17,19 @@ public class ContactAdapter extends RecyclerView.Adapter<ContactAdapter.MyViewHo

private List<ContactModel> contactModelList;

public ContactAdapter(List<ContactModel> contactModelList) {
ContactAdapter(List<ContactModel> contactModelList) {
this.contactModelList = contactModelList;
}

@NonNull
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_contact, parent, false);
return new MyViewHolder(view);
}

@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
ContactModel model = contactModelList.get(position);
if (model != null){
if (model.getName() != null){
Expand All @@ -49,11 +51,10 @@ public int getItemCount() {
return contactModelList.size();
}

public class MyViewHolder extends RecyclerView.ViewHolder {

class MyViewHolder extends RecyclerView.ViewHolder {
TextView name, number;

public MyViewHolder(View itemView) {
MyViewHolder(View itemView) {
super(itemView);

name = itemView.findViewById(R.id.tvName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,22 @@ private void getContactInfo(){
ContentResolver contentResolver = getContentResolver();
Cursor cursor = contentResolver.query(CONTENT_URI,null,null,null,DISPLAY_NAME);

if (cursor.getCount() > 0){
while (cursor.moveToNext()){
if (cursor != null && cursor.getCount() > 0) {
while (cursor.moveToNext()) {
String CONTACT_ID = cursor.getString(cursor.getColumnIndex(ID));
String name = cursor.getString(cursor.getColumnIndex(DISPLAY_NAME));

int hasPhoneNumber = cursor.getInt(cursor.getColumnIndex(HAS_PHONE_NUMBER));
ContactModel contactModel = new ContactModel();
if (hasPhoneNumber > 0){
if (hasPhoneNumber > 0) {
contactModel.setName(name);

Cursor phoneCursor = contentResolver.query(PHONE_URI, new String[]{NUMBER},PHONE_ID+" = ?",new String[]{CONTACT_ID},null);
Cursor phoneCursor = contentResolver.query(PHONE_URI, new String[]{NUMBER}, PHONE_ID + " = ?", new String[]{CONTACT_ID}, null);
List<String> contactList = new ArrayList<>();
assert phoneCursor != null;
phoneCursor.moveToFirst();
while (!phoneCursor.isAfterLast()){
String phoneNumber = phoneCursor.getString(phoneCursor.getColumnIndex(NUMBER)).replace(" ","");
while (!phoneCursor.isAfterLast()) {
String phoneNumber = phoneCursor.getString(phoneCursor.getColumnIndex(NUMBER)).replace(" ", "");
contactList.add(phoneNumber);
phoneCursor.moveToNext();
}
Expand All @@ -84,6 +85,7 @@ private void getContactInfo(){
}
}
contactAdapter.notifyDataSetChanged();
cursor.close();
}
}

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.1.4'


// 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 @@
#Fri Jul 06 11:41:45 IST 2018
#Mon Sep 10 14:01:04 IST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip