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

Done!!! All Fully Functional #3

Open
wants to merge 3 commits 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
15 changes: 1 addition & 14 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.

13 changes: 7 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 26
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.codingblocks.restapiretrofitjson"
minSdkVersion 16
targetSdkVersion 26
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -27,13 +27,14 @@ 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.+'
compile 'com.android.support:recyclerview-v7:25.+'
compile 'com.android.support:cardview-v7:25.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
testCompile 'junit:junit:4.12'
implementation 'com.squareup.picasso:picasso:2.5.2'
}
repositories {
mavenCentral()
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<activity android:name=".activities.UsersActivity" />
<activity android:name=".activities.PostsActivity" />
<activity android:name=".activities.CommentsActivity" />
<activity android:name=".activities.AlbumActivity"/>
<activity android:name=".activities.PhotosActivity"/>
<activity android:name=".activities.ViewPhotoActivity"/>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,31 @@ package com.codingblocks.restapiretrofitjson
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.codingblocks.restapiretrofitjson.activities.AlbumActivity
import com.codingblocks.restapiretrofitjson.activities.PostsActivity
import com.codingblocks.restapiretrofitjson.activities.TodosActivity
import com.codingblocks.restapiretrofitjson.activities.UsersActivity

import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
class MainActivity : AppCompatActivity(), View.OnClickListener {
override fun onClick(v: View) {
when(v.id){
R.id.btnAlbums->startActivity(Intent(this@MainActivity,AlbumActivity::class.java))
R.id.btnPosts->startActivity(Intent(this@MainActivity,PostsActivity::class.java))
R.id.btnUsers->startActivity(Intent(this@MainActivity,UsersActivity::class.java))
R.id.btnTodos->startActivity(Intent(this@MainActivity,TodosActivity::class.java))
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

btnPosts.setOnClickListener({
startActivity(Intent(this@MainActivity, PostsActivity::class.java))
})

btnUsers.setOnClickListener({
startActivity(Intent(this@MainActivity, UsersActivity::class.java))
})

btnTodos.setOnClickListener({
startActivity(Intent(this@MainActivity, TodosActivity::class.java))
})


btnAlbums.setOnClickListener(this)
btnPosts.setOnClickListener(this)
btnUsers.setOnClickListener(this)
btnTodos.setOnClickListener(this)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.codingblocks.restapiretrofitjson.activities

import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.LinearLayoutManager
import android.view.View
import com.codingblocks.restapiretrofitjson.R
import com.codingblocks.restapiretrofitjson.adapters.AlbumsAdapter
import com.codingblocks.restapiretrofitjson.api.API
import com.codingblocks.restapiretrofitjson.interfaces.OnItemClickListener
import com.codingblocks.restapiretrofitjson.models.Album
import kotlinx.android.synthetic.main.activity_album.*
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import java.util.*

class AlbumActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_album)

rvAlbumsView.layoutManager = LinearLayoutManager(this)
val albumsAdapter = AlbumsAdapter(ArrayList<Album>(), this)
rvAlbumsView.adapter = albumsAdapter
pbProgress.visibility = View.VISIBLE
btnShowAllPhotos.setOnClickListener { startActivity(Intent(this@AlbumActivity, PhotosActivity::class.java)) }
albumsAdapter.setOnItemClickListener(OnItemClickListener { itemid, view ->
val i = Intent(this@AlbumActivity, PhotosActivity::class.java)
i.putExtra("albumId", itemid)
startActivity(i)
})
val receivedId = intent.getIntExtra("userId", -1)
supportActionBar!!.title = "Albums"
val albumsApi = API.getInstance().albumsApi
val receiveAlbums = object : Callback<ArrayList<Album>> {
override fun onResponse(call: Call<ArrayList<Album>>, response: Response<ArrayList<Album>>) {
albumsAdapter.updateAlbums(response.body()!!, pbProgress)
}

override fun onFailure(call: Call<ArrayList<Album>>, t: Throwable) {

}
}

if (receivedId != -1) {
albumsApi.getAlbumsbyUserId(receivedId).enqueue(receiveAlbums)
} else {
albumsApi.getAlbumsbyUserId(null).enqueue(receiveAlbums)
}

}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package com.codingblocks.restapiretrofitjson.activities

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.LinearLayoutManager

import android.view.View
import com.codingblocks.restapiretrofitjson.R
import com.codingblocks.restapiretrofitjson.adapters.CommentAdapter
import com.codingblocks.restapiretrofitjson.api.API
import com.codingblocks.restapiretrofitjson.models.Comment
import kotlinx.android.synthetic.main.activity_comments.*

import kotlinx.android.synthetic.main.activity_comments.view.*
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import retrofit2.Retrofit

class CommentsActivity : AppCompatActivity() {

Expand All @@ -25,6 +22,9 @@ class CommentsActivity : AppCompatActivity() {
val commentAdapter = CommentAdapter(this, ArrayList<Comment>())
rvCommentsList.layoutManager = LinearLayoutManager(this)
rvCommentsList.adapter = commentAdapter
pbProgress.visibility= View.VISIBLE

supportActionBar!!.title="Comments"



Expand All @@ -36,7 +36,7 @@ class CommentsActivity : AppCompatActivity() {

override fun onResponse(call: Call<ArrayList<Comment>>?, response: Response<ArrayList<Comment>>?) {
//
commentAdapter.updateComments(response!!.body()!!)
commentAdapter.updateComments(response!!.body()!!,pbProgress)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.codingblocks.restapiretrofitjson.activities

import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.LinearLayoutManager
import android.view.View
import com.codingblocks.restapiretrofitjson.R
import com.codingblocks.restapiretrofitjson.adapters.PhotosAdapter
import com.codingblocks.restapiretrofitjson.api.API
import com.codingblocks.restapiretrofitjson.interfaces.OnPhotoClickListener
import com.codingblocks.restapiretrofitjson.models.Photos
import kotlinx.android.synthetic.main.activity_photos.*
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import java.util.*

class PhotosActivity : AppCompatActivity() {


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_photos)
rvPhotosView.layoutManager = LinearLayoutManager(this)
val photosAdapter = PhotosAdapter(ArrayList<Photos>(), this)
rvPhotosView.adapter = photosAdapter
pbProgress.visibility = View.VISIBLE

photosAdapter.setOnPhotoClickListener(OnPhotoClickListener { url, title ->
val i = Intent(this@PhotosActivity, ViewPhotoActivity::class.java)
i.putExtra("url", url)
i.putExtra("title", title)
startActivity(i)
})

val receivedId = intent.getIntExtra("albumId", -1)

supportActionBar!!.title = "Photos"

val photosApi = API.getInstance().photosApi

val receivePhotos = object : Callback<ArrayList<Photos>> {
override fun onResponse(call: Call<ArrayList<Photos>>, response: Response<ArrayList<Photos>>) {
photosAdapter.updateAlbums(response.body()!!, pbProgress)
}

override fun onFailure(call: Call<ArrayList<Photos>>, t: Throwable) {

}
}
if (receivedId != -1) {
photosApi.getPhotosOfAlbumId(receivedId).enqueue(receivePhotos)
} else {
photosApi.photos.enqueue(receivePhotos)
}
}
}

This file was deleted.

Loading