diff --git a/.idea/misc.xml b/.idea/misc.xml
index 5d19981..fbb6828 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -37,7 +37,7 @@
-
+
diff --git a/.idea/modules.xml b/.idea/modules.xml
index 1b3ccab..3bc0ff9 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -2,6 +2,7 @@
+
diff --git a/app/build.gradle b/app/build.gradle
index b963ad0..f8d4e09 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -3,12 +3,12 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
- compileSdkVersion 26
- buildToolsVersion "25.0.2"
+ compileSdkVersion 25
+ buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.codingblocks.restapiretrofitjson"
minSdkVersion 16
- targetSdkVersion 26
+ targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -27,12 +27,13 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
- compile 'com.android.support:appcompat-v7:26.+'
- compile 'com.android.support:recyclerview-v7:26.+'
- compile 'com.android.support:cardview-v7:26.+'
- compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha8'
+ compile 'com.android.support:appcompat-v7:25.3.1'
+ compile 'com.android.support:recyclerview-v7:25.3.1'
+ compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
+ compile 'com.android.support.constraint:constraint-layout:1.0.2'
+ compile 'com.squareup.picasso:picasso:2.5.2'
testCompile 'junit:junit:4.12'
}
repositories {
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 363fe63..d15d6ff 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -21,7 +21,10 @@
-
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/codingblocks/restapiretrofitjson/MainActivity.kt b/app/src/main/java/com/codingblocks/restapiretrofitjson/MainActivity.kt
index f8ad985..d0d8950 100644
--- a/app/src/main/java/com/codingblocks/restapiretrofitjson/MainActivity.kt
+++ b/app/src/main/java/com/codingblocks/restapiretrofitjson/MainActivity.kt
@@ -3,6 +3,7 @@ package com.codingblocks.restapiretrofitjson
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
+import com.codingblocks.restapiretrofitjson.activities.AlbumActivity
import com.codingblocks.restapiretrofitjson.activities.PostsActivity
import com.codingblocks.restapiretrofitjson.activities.TodosActivity
import com.codingblocks.restapiretrofitjson.activities.UsersActivity
@@ -26,7 +27,7 @@ class MainActivity : AppCompatActivity() {
btnTodos.setOnClickListener({
startActivity(Intent(this@MainActivity, TodosActivity::class.java))
})
-
+ btnAlbums.setOnClickListener { startActivity(Intent(this@MainActivity , AlbumActivity::class.java)) }
}
}
diff --git a/app/src/main/java/com/codingblocks/restapiretrofitjson/activities/AlbumActivity.java b/app/src/main/java/com/codingblocks/restapiretrofitjson/activities/AlbumActivity.java
new file mode 100644
index 0000000..e44f3db
--- /dev/null
+++ b/app/src/main/java/com/codingblocks/restapiretrofitjson/activities/AlbumActivity.java
@@ -0,0 +1,59 @@
+package com.codingblocks.restapiretrofitjson.activities;
+
+import android.content.Intent;
+import android.support.v7.app.AppCompatActivity;
+import android.os.Bundle;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.view.View;
+
+import com.codingblocks.restapiretrofitjson.R;
+import com.codingblocks.restapiretrofitjson.adapters.AlbumAdapter;
+import com.codingblocks.restapiretrofitjson.api.API;
+import com.codingblocks.restapiretrofitjson.api.AlbumsAPI;
+import com.codingblocks.restapiretrofitjson.interfaces.OnItemClickListener;
+import com.codingblocks.restapiretrofitjson.models.Album;
+
+import java.util.ArrayList;
+
+import retrofit2.Call;
+import retrofit2.Callback;
+import retrofit2.Response;
+
+
+public class AlbumActivity extends AppCompatActivity {
+
+ RecyclerView rvAlbumList ;
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_album);
+ rvAlbumList = (RecyclerView)findViewById(R.id.rvAlbumList);
+ rvAlbumList.setLayoutManager(new LinearLayoutManager(this));
+ final AlbumAdapter adapter = new AlbumAdapter(new ArrayList() , this) ;
+ rvAlbumList.setAdapter(adapter);
+ adapter.setOnItemClickListener(new OnItemClickListener() {
+ @Override
+ public void onItemClick(int itemId, View view) {
+ Intent i = new Intent(AlbumActivity.this ,PhotosActivity.class) ;
+ i.putExtra("id" , itemId) ;
+ startActivity(i);
+ }
+ });
+
+
+ API.getInstance().getAlbumsAPI().getAlbums().enqueue(new Callback>() {
+ @Override
+ public void onResponse(Call> call, Response> response) {
+ adapter.updateAlbumList(response.body());
+ }
+
+ @Override
+ public void onFailure(Call> call, Throwable t) {
+
+ }
+ }); ;
+
+
+ }
+}
diff --git a/app/src/main/java/com/codingblocks/restapiretrofitjson/activities/LargePhotoActivity.java b/app/src/main/java/com/codingblocks/restapiretrofitjson/activities/LargePhotoActivity.java
new file mode 100644
index 0000000..229ae45
--- /dev/null
+++ b/app/src/main/java/com/codingblocks/restapiretrofitjson/activities/LargePhotoActivity.java
@@ -0,0 +1,26 @@
+package com.codingblocks.restapiretrofitjson.activities;
+
+import android.support.v7.app.AppCompatActivity;
+import android.os.Bundle;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.codingblocks.restapiretrofitjson.R;
+import com.squareup.picasso.Picasso;
+
+public class LargePhotoActivity extends AppCompatActivity {
+
+ ImageView ivLargePhoto ;
+ TextView tvTitle ;
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_large_photo);
+ ivLargePhoto = (ImageView)findViewById(R.id.ivPhoto) ;
+ tvTitle = (TextView)findViewById(R.id.tvPhotoLTitle) ;
+ String title = getIntent().getStringExtra("title") ;
+ String url = getIntent().getStringExtra("url") ;
+ Picasso.with(this).load(url).into(ivLargePhoto);
+ tvTitle.setText(title);
+ }
+}
diff --git a/app/src/main/java/com/codingblocks/restapiretrofitjson/activities/PhotosActivity.java b/app/src/main/java/com/codingblocks/restapiretrofitjson/activities/PhotosActivity.java
new file mode 100644
index 0000000..5f5436d
--- /dev/null
+++ b/app/src/main/java/com/codingblocks/restapiretrofitjson/activities/PhotosActivity.java
@@ -0,0 +1,57 @@
+package com.codingblocks.restapiretrofitjson.activities;
+
+import android.content.Intent;
+import android.support.v7.app.AppCompatActivity;
+import android.os.Bundle;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+
+import com.codingblocks.restapiretrofitjson.R;
+import com.codingblocks.restapiretrofitjson.adapters.PhotosAdapter;
+import com.codingblocks.restapiretrofitjson.api.API;
+import com.codingblocks.restapiretrofitjson.models.Photo;
+
+import java.util.ArrayList;
+
+import retrofit2.Call;
+import retrofit2.Callback;
+import retrofit2.Response;
+
+public class PhotosActivity extends AppCompatActivity {
+
+ RecyclerView rvPhotos ;
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_photos);
+ rvPhotos = (RecyclerView)findViewById(R.id.rvPhotoList);
+ rvPhotos.setLayoutManager(new LinearLayoutManager(this));
+ final PhotosAdapter adapter = new PhotosAdapter(new ArrayList() ,this) ;
+ rvPhotos.setAdapter(adapter);
+
+ adapter.setOpcl(new PhotosAdapter.OnPhotoClickListener() {
+ @Override
+ public void onClick(String url, String title) {
+ Intent i = new Intent(PhotosActivity.this ,LargePhotoActivity.class) ;
+ i.putExtra("url" , url) ;
+ i.putExtra("title" , title) ;
+ startActivity(i);
+ }
+ });
+
+ int id = getIntent().getIntExtra("id" , 0 ) ;
+ API.getInstance().getAlbumsAPI().getPhotoOfAlbum(id).enqueue(new Callback>() {
+ @Override
+ public void onResponse(Call> call, Response> response) {
+ adapter.updatePhotoList(response.body());
+ }
+
+ @Override
+ public void onFailure(Call> call, Throwable t) {
+
+ }
+ });
+
+
+ }
+}
diff --git a/app/src/main/java/com/codingblocks/restapiretrofitjson/adapters/AlbumAdapter.java b/app/src/main/java/com/codingblocks/restapiretrofitjson/adapters/AlbumAdapter.java
new file mode 100644
index 0000000..b352742
--- /dev/null
+++ b/app/src/main/java/com/codingblocks/restapiretrofitjson/adapters/AlbumAdapter.java
@@ -0,0 +1,78 @@
+package com.codingblocks.restapiretrofitjson.adapters;
+
+import android.content.Context;
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import com.codingblocks.restapiretrofitjson.R;
+import com.codingblocks.restapiretrofitjson.interfaces.OnItemClickListener;
+import com.codingblocks.restapiretrofitjson.models.Album;
+
+import java.util.ArrayList;
+
+/**
+ * Created by anirudh on 03/07/17.
+ */
+
+public class AlbumAdapter extends RecyclerView.Adapter {
+
+ ArrayList albumArrayList ;
+ Context context ;
+
+ OnItemClickListener oacl ;
+
+ public void setOnItemClickListener(OnItemClickListener oacl) {
+ this.oacl = oacl;
+ }
+
+ public void updateAlbumList(ArrayList albums){
+ this.albumArrayList =albums ;
+ notifyDataSetChanged();
+ }
+
+
+ public AlbumAdapter(ArrayList albumArrayList, Context context) {
+ this.albumArrayList = albumArrayList;
+ this.context = context;
+ }
+
+ @Override
+ public AlbumViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
+ LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ View itemView = li.inflate(R.layout.list_item_album ,parent ,false) ;
+
+ return new AlbumViewHolder(itemView);
+ }
+
+ @Override
+ public void onBindViewHolder(final AlbumViewHolder holder, final int position) {
+ final Album thisAlbum = albumArrayList.get(position) ;
+ holder.tvAlbumTitle.setText(thisAlbum.getTitle());
+ holder.thisView.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if(oacl !=null)
+ oacl.onItemClick(thisAlbum.getId() , holder.thisView);
+ }
+ });
+ }
+
+ @Override
+ public int getItemCount() {
+ return albumArrayList.size();
+ }
+
+ public class AlbumViewHolder extends RecyclerView.ViewHolder{
+ TextView tvAlbumTitle ;
+ View thisView ;
+
+ public AlbumViewHolder(View itemView) {
+ super(itemView);
+ tvAlbumTitle = (TextView) itemView.findViewById(R.id.tvAlbumTitle);
+ thisView = itemView ;
+ }
+ }
+}
diff --git a/app/src/main/java/com/codingblocks/restapiretrofitjson/adapters/PhotosAdapter.java b/app/src/main/java/com/codingblocks/restapiretrofitjson/adapters/PhotosAdapter.java
new file mode 100644
index 0000000..c6ee032
--- /dev/null
+++ b/app/src/main/java/com/codingblocks/restapiretrofitjson/adapters/PhotosAdapter.java
@@ -0,0 +1,81 @@
+package com.codingblocks.restapiretrofitjson.adapters;
+
+import android.content.Context;
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.codingblocks.restapiretrofitjson.R;
+import com.codingblocks.restapiretrofitjson.models.Photo;
+import com.squareup.picasso.Picasso;
+
+import java.util.ArrayList;
+
+/**
+ * Created by anirudh on 03/07/17.
+ */
+
+public class PhotosAdapter extends RecyclerView.Adapter {
+
+ private ArrayList photoArrayList ;
+ private Context context ;
+ private OnPhotoClickListener opcl ;
+
+ public void setOpcl(OnPhotoClickListener opcl) {
+ this.opcl = opcl;
+ }
+
+ public PhotosAdapter(ArrayList photoArrayList, Context context) {
+ this.photoArrayList = photoArrayList;
+ this.context = context;
+ }
+ public interface OnPhotoClickListener{
+ public void onClick(String url ,String title) ;
+ }
+ public void updatePhotoList(ArrayList photos){
+ this.photoArrayList = photos ;
+ notifyDataSetChanged();
+ }
+
+ @Override
+ public PhotoViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
+ LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ View itemView = li.inflate(R.layout.list_item_photos ,parent ,false) ;
+ return new PhotoViewHolder(itemView);
+ }
+
+ @Override
+ public void onBindViewHolder(PhotoViewHolder holder, int position) {
+ final Photo thisPhoto = photoArrayList.get(position) ;
+ Picasso.with(context).load(thisPhoto.getThumbnailUrl()).into(holder.ivThumbnail);
+ holder.tvPhotoTitle.setText(thisPhoto.getTitle());
+ holder.thisView.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ opcl.onClick(thisPhoto.getUrl() ,thisPhoto.getTitle());
+ }
+ });
+ }
+
+ @Override
+ public int getItemCount() {
+ return photoArrayList.size();
+ }
+
+ public class PhotoViewHolder extends RecyclerView.ViewHolder{
+ ImageView ivThumbnail ;
+ TextView tvPhotoTitle ;
+ View thisView ;
+ public PhotoViewHolder(View itemView) {
+ super(itemView);
+ ivThumbnail = (ImageView)itemView.findViewById(R.id.ivThumbnail) ;
+ tvPhotoTitle =(TextView)itemView.findViewById(R.id.tvPhotoTitle) ;
+ thisView = itemView ;
+ }
+ }
+}
+
+
diff --git a/app/src/main/java/com/codingblocks/restapiretrofitjson/adapters/TodoAdapter.kt b/app/src/main/java/com/codingblocks/restapiretrofitjson/adapters/TodoAdapter.kt
index c0bb9b6..9e4483c 100644
--- a/app/src/main/java/com/codingblocks/restapiretrofitjson/adapters/TodoAdapter.kt
+++ b/app/src/main/java/com/codingblocks/restapiretrofitjson/adapters/TodoAdapter.kt
@@ -48,6 +48,7 @@ public class TodoAdapter (
fun bindTodo(todo: Todo) {
itemView.tvTodoTitle.text = todo.title;
+ itemView.checkBoxTodo.setChecked(todo.completed)
}
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/codingblocks/restapiretrofitjson/api/API.java b/app/src/main/java/com/codingblocks/restapiretrofitjson/api/API.java
index 771fdc2..5526abd 100644
--- a/app/src/main/java/com/codingblocks/restapiretrofitjson/api/API.java
+++ b/app/src/main/java/com/codingblocks/restapiretrofitjson/api/API.java
@@ -15,6 +15,11 @@ public class API {
private UsersAPI usersAPI;
private CommentsAPI commentsAPI;
private TodosAPI todosAPI;
+ private AlbumsAPI albumsAPI ;
+
+ public AlbumsAPI getAlbumsAPI() {
+ return albumsAPI;
+ }
public PostsAPI getPostsAPI() {
return postsAPI;
@@ -44,6 +49,7 @@ private API() {
usersAPI = retrofit.create(UsersAPI.class);
commentsAPI = retrofit.create(CommentsAPI.class);
todosAPI = retrofit.create(TodosAPI.class);
+ albumsAPI = retrofit.create(AlbumsAPI.class) ;
}
public static API getInstance() {
diff --git a/app/src/main/java/com/codingblocks/restapiretrofitjson/api/AlbumsAPI.java b/app/src/main/java/com/codingblocks/restapiretrofitjson/api/AlbumsAPI.java
new file mode 100644
index 0000000..e55ada7
--- /dev/null
+++ b/app/src/main/java/com/codingblocks/restapiretrofitjson/api/AlbumsAPI.java
@@ -0,0 +1,21 @@
+package com.codingblocks.restapiretrofitjson.api;
+
+import com.codingblocks.restapiretrofitjson.models.Album;
+import com.codingblocks.restapiretrofitjson.models.Photo;
+
+import java.util.ArrayList;
+
+import retrofit2.Call;
+import retrofit2.http.GET;
+import retrofit2.http.Path;
+
+/**
+ * Created by anirudh on 03/07/17.
+ */
+
+public interface AlbumsAPI {
+ @GET("/albums")
+ Call> getAlbums() ;
+ @GET("/albums/{id}/photos")
+ Call> getPhotoOfAlbum(@Path("id") int albumId) ;
+}
diff --git a/app/src/main/java/com/codingblocks/restapiretrofitjson/models/Album.kt b/app/src/main/java/com/codingblocks/restapiretrofitjson/models/Album.kt
new file mode 100644
index 0000000..4f1643c
--- /dev/null
+++ b/app/src/main/java/com/codingblocks/restapiretrofitjson/models/Album.kt
@@ -0,0 +1,6 @@
+package com.codingblocks.restapiretrofitjson.models
+
+/**
+ * Created by anirudh on 03/07/17.
+ */
+data class Album(val userId : kotlin.Int , val id : kotlin.Int , val title : String) ;
\ No newline at end of file
diff --git a/app/src/main/java/com/codingblocks/restapiretrofitjson/models/Photo.kt b/app/src/main/java/com/codingblocks/restapiretrofitjson/models/Photo.kt
new file mode 100644
index 0000000..e8fe49e
--- /dev/null
+++ b/app/src/main/java/com/codingblocks/restapiretrofitjson/models/Photo.kt
@@ -0,0 +1,6 @@
+package com.codingblocks.restapiretrofitjson.models
+
+/**
+ * Created by anirudh on 03/07/17.
+ */
+data class Photo(val albumId : Int ,val id : Int ,val title : String ,val url : String ,val thumbnailUrl : String)
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_album.xml b/app/src/main/res/layout/activity_album.xml
new file mode 100644
index 0000000..187253c
--- /dev/null
+++ b/app/src/main/res/layout/activity_album.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_large_photo.xml b/app/src/main/res/layout/activity_large_photo.xml
new file mode 100644
index 0000000..148bbaa
--- /dev/null
+++ b/app/src/main/res/layout/activity_large_photo.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_photos.xml b/app/src/main/res/layout/activity_photos.xml
new file mode 100644
index 0000000..8a45795
--- /dev/null
+++ b/app/src/main/res/layout/activity_photos.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/list_item_album.xml b/app/src/main/res/layout/list_item_album.xml
new file mode 100644
index 0000000..184728d
--- /dev/null
+++ b/app/src/main/res/layout/list_item_album.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/list_item_photos.xml b/app/src/main/res/layout/list_item_photos.xml
new file mode 100644
index 0000000..6b08241
--- /dev/null
+++ b/app/src/main/res/layout/list_item_photos.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/list_item_todo.xml b/app/src/main/res/layout/list_item_todo.xml
index 7dd7af1..24468ad 100644
--- a/app/src/main/res/layout/list_item_todo.xml
+++ b/app/src/main/res/layout/list_item_todo.xml
@@ -1,12 +1,45 @@
-
+
-
-
\ No newline at end of file
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file