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
Binary file added .idea/caches/build_file_checksums.ser
Binary file not shown.
Binary file added .idea/caches/gradle_models.ser
Binary file not shown.
4 changes: 4 additions & 0 deletions .idea/encodings.xml

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

3 changes: 3 additions & 0 deletions .idea/gradle.xml

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

17 changes: 14 additions & 3 deletions .idea/misc.xml

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

1 change: 1 addition & 0 deletions .idea/modules.xml

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

57 changes: 32 additions & 25 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,52 +1,59 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 26
compileSdkVersion 29
defaultConfig {
applicationId "info.androidhive.rxjavasearch"
minSdkVersion 16
targetSdkVersion 26
minSdkVersion 26
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

implementation 'com.android.support:recyclerview-v7:26.1.0'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'

implementation 'io.reactivex.rxjava2:rxjava:2.1.9'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'androidx.recyclerview:recyclerview:1.0.0'

compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.7'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'

// butter knife
implementation "com.jakewharton:butterknife:8.8.1"
annotationProcessor "com.jakewharton:butterknife-compiler:8.8.1"
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.5.0'
//implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
implementation 'com.jakewharton.rxbinding3:rxbinding-material:3.0.0-alpha2'
implementation 'com.jakewharton.rxbinding3:rxbinding:3.0.0-alpha2'
implementation "com.jakewharton:butterknife:10.1.0"
annotationProcessor "com.jakewharton:butterknife-compiler:10.1.0"

implementation "com.squareup.retrofit2:retrofit:2.0.0"
implementation "com.squareup.retrofit2:converter-gson:2.0.0"
implementation "com.squareup.retrofit2:retrofit:2.5.0"
implementation "com.squareup.retrofit2:converter-gson:2.5.0"
implementation "com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0"
implementation "com.squareup.okhttp3:okhttp:3.0.1"
implementation "com.squareup.okhttp3:okhttp-urlconnection:3.0.1"
implementation "com.squareup.okhttp3:logging-interceptor:3.4.1"
implementation 'com.squareup.okhttp3:okhttp:4.0.0-alpha02'
implementation 'com.squareup.okhttp3:okhttp-urlconnection:4.0.0-alpha02'
implementation 'com.squareup.okhttp3:logging-interceptor:4.0.0-alpha02'

// glide image library
implementation "com.github.bumptech.glide:glide:4.3.1"
implementation "com.github.bumptech.glide:glide:4.9.0"

implementation "com.jakewharton.rxbinding2:rxbinding:2.0.0"
testImplementation 'junit:junit:4.13-beta-3'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package info.androidhive.rxjavasearch;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -19,10 +19,11 @@

import info.androidhive.rxjavasearch.R;
import info.androidhive.rxjavasearch.network.model.Contact;
import info.androidhive.rxjavasearch.network.model.Person;

public class ContactsAdapter extends RecyclerView.Adapter<ContactsAdapter.MyViewHolder> {
private Context context;
private List<Contact> contactList;
private List<Person> personList;
private ContactsAdapterListener listener;

public class MyViewHolder extends RecyclerView.ViewHolder {
Expand All @@ -39,17 +40,17 @@ public MyViewHolder(View view) {
@Override
public void onClick(View view) {
// send selected contact in callback
listener.onContactSelected(contactList.get(getAdapterPosition()));
listener.onContactSelected(personList.get(getAdapterPosition()));
}
});
}
}


public ContactsAdapter(Context context, List<Contact> contactList, ContactsAdapterListener listener) {
public ContactsAdapter(Context context, List<Person> personList, ContactsAdapterListener listener) {
this.context = context;
this.listener = listener;
this.contactList = contactList;
this.personList = personList;
}

@Override
Expand All @@ -62,22 +63,22 @@ public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

@Override
public void onBindViewHolder(MyViewHolder holder, final int position) {
final Contact contact = contactList.get(position);
holder.name.setText(contact.getName());
holder.phone.setText(contact.getPhone());
final Person person = personList.get(position);
holder.name.setText(person.getFirstName());
holder.phone.setText(person.getLastName());

Glide.with(context)
.load(contact.getProfileImage())
/* Glide.with(context)
.load(person.getProfileImage())
.apply(RequestOptions.circleCropTransform())
.into(holder.thumbnail);
.into(holder.thumbnail);*/
}

@Override
public int getItemCount() {
return contactList.size();
return personList.size();
}

public interface ContactsAdapterListener {
void onContactSelected(Contact contact);
void onContactSelected(Person person);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@

public class Const {
public static final String BASE_URL = "https://api.androidhive.info/json/";
public static final String LOCALHOST_URL = "http://192.168.0.5/~gmiklay/rest_api_demo/";
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static Retrofit getClient() {

if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl(Const.BASE_URL)
.baseUrl(Const.LOCALHOST_URL)
.client(okHttpClient)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Created by ravi on 31/01/18.
*/

public interface ApiService {
public interface ContactApi {

@GET("contacts.php")
Single<List<Contact>> getContacts(@Query("source") String source, @Query("search") String query);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package info.androidhive.rxjavasearch.network;

import java.util.List;

import info.androidhive.rxjavasearch.network.model.Person;
import io.reactivex.Single;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.POST;
import retrofit2.http.Path;
import retrofit2.http.Query;

public interface PersonsApi {

@Headers("Content-Type: application/json")
@GET("persons")
Single<List<Person>> getPersons(
@Query("uid[]") Integer[] uid,
@Query("limit") Integer limit,
@Query("like") String like
);

@GET("persons/{uid}")
Call<List<Person>> getPersonById(@Path("uid") int uid);

@GET("persons/generate/{no_of_persons}")
Call<List<Person>> generatePersons(
@Path("no_of_persons") int no_of_persons,
@Query("with_confirm") boolean with_confirm
);

@Headers("Content-Type: application/json")
@POST("persons")
Call<List<Person>> getPersonsUnlimited(
@Body String body,
@Query("limit") Integer limit
);

@Headers("Content-Type: application/json")
@POST("persons/insert")
Call<List<Person>> insertPersons(
@Body String body
);
}
Loading