Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added project #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
6 changes: 0 additions & 6 deletions .idea/encodings.xml

This file was deleted.

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

This file was deleted.

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

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion .idea/modules.xml → MyAppL11Assign/.idea/modules.xml

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

File renamed without changes.
File renamed without changes.
17 changes: 9 additions & 8 deletions app/build.gradle → MyAppL11Assign/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 26
buildToolsVersion "25.0.2"
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.codingblocks.restapiretrofitjson"
applicationId "com.example.dell.myappl11assign"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
Expand All @@ -20,21 +19,23 @@ android {
}
}
}

repositories {
mavenCentral()
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
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.constraint:constraint-layout:1.0.0-alpha8'
compile 'com.android.support:design: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.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile 'com.squareup.picasso:picasso:2.5.2'
testCompile 'junit:junit:4.12'
}
repositories {
mavenCentral()
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/championswimmer/Library/Android/sdk/tools/proguard/proguard-android.txt
# in C:\Users\dell\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.codingblocks.restapiretrofitjson;
package com.example.dell.myappl11assign;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
Expand All @@ -21,6 +21,6 @@ public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.codingblocks.restapiretrofitjson", appContext.getPackageName());
assertEquals("com.example.dell.myappl11assign", appContext.getPackageName());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.codingblocks.restapiretrofitjson">
package="com.example.dell.myappl11assign">

<uses-permission android:name="android.permission.INTERNET" />

Expand All @@ -11,17 +11,20 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".activities.UsersActivity" />
<activity android:name=".activities.PostsActivity" />
<activity android:name=".activities.CommentsActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activities.TodosActivity"></activity>
<activity android:name=".UsersActivity" />
<activity android:name=".PostsActivity" />
<activity android:name=".TodosActivity" />
<activity android:name=".AlbumsActivity" />
<activity android:name=".CommentsActivity" />
<activity android:name=".PhotosActivity" />
<activity android:name=".FullImageActivity"></activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.example.dell.myappl11assign;

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.util.Log;

import com.example.dell.myappl11assign.adapters.AlbumAdapter;
import com.example.dell.myappl11assign.api.AlbumsAPI;
import com.example.dell.myappl11assign.interfaces.OnItemClickListener;
import com.example.dell.myappl11assign.models.Album;

import java.util.ArrayList;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class AlbumsActivity extends AppCompatActivity {
public static final String TAG="AlbumsActivity";
RecyclerView rvAlbumsList;
AlbumAdapter albumAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_albums);

rvAlbumsList= (RecyclerView) findViewById(R.id.rvAlbumsList);
rvAlbumsList.setLayoutManager(new LinearLayoutManager(this));
albumAdapter=new AlbumAdapter(this,new ArrayList<Album>());
rvAlbumsList.setAdapter(albumAdapter);
albumAdapter.setOnItemClickListerner(new OnItemClickListener() {
@Override
public void onItemClick(int itemId) {
Intent photoActIntent=new Intent(AlbumsActivity.this,PhotosActivity.class);
photoActIntent.putExtra("albumId",itemId);
startActivity(photoActIntent);
}
});

Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://jsonplaceholder.typicode.com")
.addConverterFactory(
GsonConverterFactory.create()
)
.build();

AlbumsAPI albumsAPI=retrofit.create(AlbumsAPI.class);
Callback<ArrayList<Album>>albumCallBack=new Callback<ArrayList<Album>>() {
@Override
public void onResponse(Call<ArrayList<Album>> call, Response<ArrayList<Album>> response) {
Log.d(TAG, "onResponse: *****************");
albumAdapter.updateAlbums(response.body());
}

@Override
public void onFailure(Call<ArrayList<Album>> call, Throwable t) {

}
};
albumsAPI.getAlbums().enqueue(albumCallBack);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.example.dell.myappl11assign;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;

import com.example.dell.myappl11assign.adapters.CommentAdapter;
import com.example.dell.myappl11assign.api.CommentsAPI;
import com.example.dell.myappl11assign.models.Comment;

import java.util.ArrayList;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class CommentsActivity extends AppCompatActivity {
public static final String TAG="CommentsActivity";
RecyclerView rvCommentsList;
CommentAdapter commentAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_comments);

rvCommentsList= (RecyclerView) findViewById(R.id.rvCommentsList);
rvCommentsList.setLayoutManager(new LinearLayoutManager(this));
commentAdapter=new CommentAdapter(this,new ArrayList<Comment>());
rvCommentsList.setAdapter(commentAdapter);

Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://jsonplaceholder.typicode.com")
.addConverterFactory(
GsonConverterFactory.create()
)
.build();

CommentsAPI commentsAPI=retrofit.create(CommentsAPI.class);
Callback<ArrayList<Comment>> commentCallback=new Callback<ArrayList<Comment>>() {
@Override
public void onResponse(Call<ArrayList<Comment>> call, Response<ArrayList<Comment>> response) {
Log.d(TAG, "onResponse: ****************");
commentAdapter.updateComments(response.body());
}

@Override
public void onFailure(Call<ArrayList<Comment>> call, Throwable t) {

}
};
int userIdReceived = getIntent().getIntExtra("UserId",-1);
if(userIdReceived!=-1){
commentsAPI.getCommentsByPostId(userIdReceived).enqueue(commentCallback);
}else{
commentsAPI.getComments().enqueue(commentCallback);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.example.dell.myappl11assign;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

public class FullImageActivity extends AppCompatActivity {

ImageView ivFullImagePhoto;
TextView tvFullImageTitle;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_full_image);

ivFullImagePhoto = (ImageView) findViewById(R.id.ivFullImagePhoto);
tvFullImageTitle = (TextView) findViewById(R.id.tvFullImageTitle);

String photoURLReceived = getIntent().getStringExtra("photoURL");
if (photoURLReceived != null) {
Picasso.with(FullImageActivity.this).load(photoURLReceived).error(R.drawable.ic_missing).into(ivFullImagePhoto);
}
String photoTitleReceived=getIntent().getStringExtra("photoTitle");
if(photoTitleReceived!=null){
tvFullImageTitle.setText(photoTitleReceived);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.example.dell.myappl11assign;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
public static final String TAG = "MainActivity";
Button btnUsers, btnPosts, btnAlbums, btnTodos;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

btnUsers = (Button) findViewById(R.id.btnUsers);
btnPosts = (Button) findViewById(R.id.btnPosts);
btnAlbums = (Button) findViewById(R.id.btnAlbums);
btnTodos = (Button) findViewById(R.id.btnTodos);


btnUsers.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d(TAG, "onClick: *************");
Intent i = new Intent(MainActivity.this, UsersActivity.class);
startActivity(i);

}
});


btnPosts.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d(TAG, "onClick: **************");
Intent i = new Intent(MainActivity.this, PostsActivity.class);
startActivity(i);
}
});


btnAlbums.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d(TAG, "onClick: ***************");
Intent i = new Intent(MainActivity.this, AlbumsActivity.class);
startActivity(i);
}
});


btnTodos.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d(TAG, "onClick: *****************");
Intent i = new Intent(MainActivity.this, TodosActivity.class);
startActivity(i);
}
});


}
}
Loading