Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
New : User Likes (trello.com/c/oaoLaUEU)
Browse files Browse the repository at this point in the history
  • Loading branch information
DawnImpulse committed Oct 8, 2018
1 parent 533d4e4 commit fbeebcf
Show file tree
Hide file tree
Showing 10 changed files with 228 additions and 252 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dawnimpulse.wallup.activities

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
Expand Down Expand Up @@ -48,6 +49,7 @@ class GeneralImagesActivity : AppCompatActivity(), View.OnClickListener,
private lateinit var tag: String

// on create
@SuppressLint("RestrictedApi")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_general_images)
Expand All @@ -71,6 +73,13 @@ class GeneralImagesActivity : AppCompatActivity(), View.OnClickListener,
tag = intent.extras.getString(C.TAG)
randomImages()
}
C.LIKE -> {
current = 4
username = intent.extras.getString(C.USERNAME)
L.d(NAME,username)
paginatedImages()
generalImagesFab.visibility = View.GONE
}
}

generalImagesFab.setOnClickListener(this)
Expand Down Expand Up @@ -105,6 +114,7 @@ class GeneralImagesActivity : AppCompatActivity(), View.OnClickListener,
1 -> paginatedImages()
2 -> paginatedImages()
3 -> randomImages()
4 -> paginatedImages()
}
}

Expand All @@ -120,6 +130,7 @@ class GeneralImagesActivity : AppCompatActivity(), View.OnClickListener,
else
model.curatedCollectionPhotos(colId, nextPage, 30, callbackPaginated)
}
4 -> model.userLikedPhotos(username,nextPage, callbackPaginated)
}
}

Expand Down Expand Up @@ -192,6 +203,9 @@ class GeneralImagesActivity : AppCompatActivity(), View.OnClickListener,
else
model.curatedCollectionPhotos(colId, 1, 30, callback)
}
4 -> {
model.userLikedPhotos(username, 1,callback)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ OR PERFORMANCE OF THIS SOFTWARE.*/
package com.dawnimpulse.wallup.activities

import android.content.DialogInterface
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.core.widget.toast
import com.dawnimpulse.wallup.R
Expand All @@ -37,9 +39,10 @@ import kotlinx.android.synthetic.main.activity_user.*
*
* @note Updates :
*/
class UserActivity : AppCompatActivity() {
class UserActivity : AppCompatActivity(), View.OnClickListener {
private val NAME = "UserActivity"
private lateinit var model: UnsplashModel
private var user: UserPojo? = null

// on create
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -65,23 +68,45 @@ class UserActivity : AppCompatActivity() {
}

// logout user
logoutL.setOnClickListener {
Dialog.simpleOk(this,
"User Profile Logout",
"Wish to logout from your profile ?",
DialogInterface.OnClickListener { dialog, _ ->
Prefs.remove(C.USER_TOKEN)
Prefs.remove(C.USER)
Config.USER_API_KEY = ""
dialog.dismiss()
toast("Successfully logout from your profile")
finish()
})
logoutL.setOnClickListener(this)
userLikes.setOnClickListener(this)
}

// on click
override fun onClick(v: View?) {
v?.let {
when (v.id) {
logoutL.id -> {
Dialog.simpleOk(this,
"User Profile Logout",
"Wish to logout from your profile ?",
DialogInterface.OnClickListener { dialog, _ ->
Prefs.remove(C.USER_TOKEN)
Prefs.remove(C.USER)
Config.USER_API_KEY = ""
dialog.dismiss()
toast("Successfully logout from your profile")
finish()
})
}
userLikes.id -> {
if (user != null) {
var intent = Intent(this, GeneralImagesActivity::class.java)
intent.putExtra(C.TYPE, C.LIKE)
intent.putExtra(C.USERNAME, user?.username)
startActivity(intent)
} else
toast("kindly wait while loading user details.")
}
else -> {
}
}
}
}

//set user details
private fun setDetails(user: UserPojo) {
this.user = user
userFullName.text = user.name
userName.text = "@${user.username}"
ImageHandler.setImageInView(lifecycle, userImage, user.profile_image.large)
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/kotlin/com/dawnimpulse/wallup/models/UnsplashModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.dawnimpulse.wallup.repositories.UnsplashRepository
* 2018 09 22 - master - Saksham - random images tag
* 2018 10 01 - master - Saksham - generate bearer token
* 2018 10 04 - master - Saksham - self profile
* 2018 10 08 - master - Saksham - user liked photos
*/
class UnsplashModel() {
private lateinit var lifecycle: Lifecycle
Expand Down Expand Up @@ -331,4 +332,20 @@ class UnsplashModel() {
})
}
}

// user liked photos
fun userLikedPhotos(username: String,page:Int, callback: (Any?, Any?) -> Unit) {
UnsplashRepository.userLikedPhotos(username,page) { e, r ->
lifecycle.addObserver(object : LifecycleObserver {
var once = true
@OnLifecycleEvent(Lifecycle.Event.ON_START)
fun onStart() {
if (once) {
callback(e, r)
once = false
}
}
})
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import retrofit2.Response
* 2018 09 22 - master - Saksham - random images tag
* 2018 10 01 - master - Saksham - generate bearer token
* 2018 10 04 - master - Saksham - user profile
* 2018 10 08 - master - Saksham - user likes
*/
object UnsplashRepository {
private val NAME = "UnsplashRepository"
Expand Down Expand Up @@ -426,7 +427,7 @@ object UnsplashRepository {
if (!response.isSuccessful)
L.dO(NAME, ErrorUtils.parseError(response))
else
L.d(NAME,"Liked Photo")
L.d(NAME, "Liked Photo")
}

override fun onFailure(call: Call<ImagePojo>?, t: Throwable?) {
Expand All @@ -449,7 +450,7 @@ object UnsplashRepository {
if (!response.isSuccessful)
L.dO(NAME, ErrorUtils.parseError(response))
else
L.d(NAME,"Unliked Photo")
L.d(NAME, "Unliked Photo")
}

override fun onFailure(call: Call<ImagePojo>?, t: Throwable?) {
Expand Down Expand Up @@ -483,7 +484,7 @@ object UnsplashRepository {
}

// user profile
fun selfProfile(callback: (Any?, Any?) -> Unit){
fun selfProfile(callback: (Any?, Any?) -> Unit) {
val apiClient = RetroApiClient.getClient()!!.create(RetroUnsplashSource::class.java)
val call = apiClient.selfProfile(
Config.apiKey()
Expand All @@ -503,5 +504,28 @@ object UnsplashRepository {
}
})
}

// user liked photos
fun userLikedPhotos(username: String, page: Int, callback: (Any?, Any?) -> Unit) {
val apiClient = RetroApiClient.getClient()!!.create(RetroUnsplashSource::class.java)
val call = apiClient.userLikedPhotos(
Config.apiKey(),
username,
page)

call.enqueue(object : Callback<List<ImagePojo>> {

override fun onResponse(call: Call<List<ImagePojo>>?, response: Response<List<ImagePojo>>) {
if (response.isSuccessful)
callback(null, response.body())
else
callback(ErrorUtils.parseError(response), null)
}

override fun onFailure(call: Call<List<ImagePojo>>?, t: Throwable?) {
t?.toString()?.let { callback(t.toString(), null) }
}
})
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,25 @@ interface RetroUnsplashSource {
@Query(C.USERNAME) username: String
): Call<List<ImagePojo>>

// ------------------------------
// User Profile
// ------------------------------
@GET("/me")
fun selfProfile(
@Header(C.AUTHORIZATION) authorization: String
): Call<UserPojo>

// ------------------------------
// User Liked Photos
// ------------------------------
@GET("/users/{username}/likes?per_page=30")
fun userLikedPhotos(
@Header(C.AUTHORIZATION) authorization: String,
@Path(C.USERNAME) username: String,
@Query(C.PAGE) page: Int
): Call<List<ImagePojo>>



//________________________________
// Collection
Expand Down
Binary file modified app/src/main/res/drawable/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit fbeebcf

Please sign in to comment.