diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..30aa626
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 93713f5..13c4629 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -24,7 +24,7 @@
-
+
diff --git a/.idea/modules.xml b/.idea/modules.xml
index 3ab1544..c46a5ff 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -2,7 +2,7 @@
-
+
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 9db5366..8303ecd 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -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"
@@ -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'
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index fb35e95..fdfc229 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -1,5 +1,6 @@
@@ -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">
-
diff --git a/app/src/main/java/androidbuffer/com/readcontactdemo/ContactAdapter.java b/app/src/main/java/androidbuffer/com/readcontactdemo/ContactAdapter.java
index ba37e8c..6627f41 100644
--- a/app/src/main/java/androidbuffer/com/readcontactdemo/ContactAdapter.java
+++ b/app/src/main/java/androidbuffer/com/readcontactdemo/ContactAdapter.java
@@ -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;
@@ -16,18 +17,19 @@ public class ContactAdapter extends RecyclerView.Adapter contactModelList;
- public ContactAdapter(List contactModelList) {
+ ContactAdapter(List 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){
@@ -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);
diff --git a/app/src/main/java/androidbuffer/com/readcontactdemo/MainActivity.java b/app/src/main/java/androidbuffer/com/readcontactdemo/MainActivity.java
index 7acccf4..9531c41 100644
--- a/app/src/main/java/androidbuffer/com/readcontactdemo/MainActivity.java
+++ b/app/src/main/java/androidbuffer/com/readcontactdemo/MainActivity.java
@@ -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 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();
}
@@ -84,6 +85,7 @@ private void getContactInfo(){
}
}
contactAdapter.notifyDataSetChanged();
+ cursor.close();
}
}
diff --git a/build.gradle b/build.gradle
index e6b32bc..077cb2f 100644
--- a/build.gradle
+++ b/build.gradle
@@ -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
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 8db4dbb..35acf19 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -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