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

Commit

Permalink
Improvement: Sorted images
Browse files Browse the repository at this point in the history
Added both sorted & random images
  • Loading branch information
DawnImpulse committed Jul 9, 2019
1 parent 1589d2e commit 3e1605d
Show file tree
Hide file tree
Showing 15 changed files with 266 additions and 37 deletions.
4 changes: 0 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,12 @@ android {
buildTypes {
debug {
buildConfigField "String", "WALLUP_URL", "\"${WALLUP_DEBUG_URL}\""
buildConfigField "String", "UNSPLASH_API_KEY", "\"${UNSPLASH_API_KEY}\""
buildConfigField "String", "WALLUP_API_KEY", "\"${WALLUP_API_KEY_DEBUG}\""
buildConfigField "String", "WALLUP_EDITORIAL_CID", "\"${WALLUP_EDITORIAL_CID}\""
}

release {
buildConfigField "String", "WALLUP_URL", "\"${WALLUP_RELEASE_URL}\""
buildConfigField "String", "UNSPLASH_API_KEY", "\"${UNSPLASH_API_KEY}\""
buildConfigField "String", "WALLUP_API_KEY", "\"${WALLUP_API_KEY_RELEASE}\""
buildConfigField "String", "WALLUP_EDITORIAL_CID", "\"${WALLUP_EDITORIAL_CID}\""

minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,34 @@ object WallupRepo {
}


/**
* get sorted images
*
* @param page
* @param callback
*/
fun getSortedImages(page: Int, callback: (Any?, List<ImageObject>?) -> Unit) {

val call = client.sortedImages(page)

call.enqueue(object : Callback<ImageList> {

// response
override fun onResponse(call: Call<ImageList>, response: Response<ImageList>) {
if (response.isSuccessful)
callback(null, response.body()!!.details)
else
callback(ErrorWallupUtil.parseError(response), null)
}

// on failure
override fun onFailure(call: Call<ImageList>, t: Throwable) {
callback(t.toString(), null)
}
})
}


/**
* get homescreen
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,26 @@ interface WallupSource {
/**
* get random images
*/
@GET("/v1/images/random?limit=30")
@GET("wallup/v1/images/random?limit=30")
fun randomImages(
@Header(X_API_KEY) apiKey: String = BuildConfig.WALLUP_API_KEY
): Call<ImageList>


/**
* get sorted images
*/
@GET("wallup/v1/images/sorted?limit=30")
fun sortedImages(
@Query(PAGE) page: Int,
@Header(X_API_KEY) apiKey: String = BuildConfig.WALLUP_API_KEY
): Call<ImageList>


/**
* get homescreen
*/
@GET("/v1/generic/homescreen")
@GET("wallup/v1/generic/homescreen")
fun homescreen(
@Header(X_API_KEY) apiKey: String = BuildConfig.WALLUP_API_KEY
): Call<HomescreenDetailsObject>
Expand All @@ -60,7 +70,7 @@ interface WallupSource {
/**
* get homescreen cols
*/
@GET("/v1/collections/random/homescreen")
@GET("wallup/v1/collections/random/homescreen")
fun homescreenCols(
@Header(X_API_KEY) apiKey: String = BuildConfig.WALLUP_API_KEY,
@Query(ORIENTATION) orientation: String = ANY
Expand All @@ -69,7 +79,7 @@ interface WallupSource {
/**
* get sorted collections
*/
@GET("/v1/collections/sorted")
@GET("wallup/v1/collections/sorted")
fun sortedCols(
@Query(PAGE) page: Int,
@Query(LIMIT) limit: Int = 8,
Expand All @@ -81,7 +91,7 @@ interface WallupSource {
/**
* get sorted collection images
*/
@GET("/v1/images/collection/sorted/{cid}")
@GET("wallup/v1/images/collection/sorted/{cid}")
fun sortedCollectionImages(
@Path(CID) cid: String,
@Query(PAGE) page: Int,
Expand All @@ -92,7 +102,7 @@ interface WallupSource {
/**
* get random tag images
*/
@GET("/v1/images/random/tagged/{tag}")
@GET("wallup/v1/images/random/tagged/{tag}")
fun randomTagImages(
@Path(TAG) tag: String,
@Query(LIMIT) limit: Int = 30,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.dawnimpulse.wallup.utils.handlers.DownloadHandler
import com.dawnimpulse.wallup.utils.handlers.ImageHandler
import com.dawnimpulse.wallup.utils.handlers.WallpaperHandler
import com.dawnimpulse.wallup.utils.reusables.Config
import com.dawnimpulse.wallup.utils.reusables.UTM
import com.dawnimpulse.wallup.utils.reusables.WALLUP
import com.google.gson.Gson
import jp.wasabeef.blurry.Blurry
Expand Down Expand Up @@ -67,7 +68,7 @@ class ImageActivity : AppCompatActivity(), View.OnClickListener {

// image link
previewImageAuthorLink.id -> {
F.startWeb(this, wallup.links.html)
F.startWeb(this, wallup.links.html + UTM)
}

// download
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import com.dawnimpulse.wallup.utils.functions.*
import com.dawnimpulse.wallup.utils.reusables.Config
import com.dawnimpulse.wallup.utils.reusables.FAIL_LOAD_MORE
import com.dawnimpulse.wallup.utils.reusables.LOAD_MORE
import kotlinx.android.synthetic.main.activity_general.*
import com.dawnimpulse.wallup.utils.reusables.RANDOM
import kotlinx.android.synthetic.main.activity_random_images.*

/**
* @info -
Expand All @@ -39,24 +40,30 @@ import kotlinx.android.synthetic.main.activity_general.*
*
* @note Created on 2019-06-29 by Saksham
* @note Updates :
* Saksham - 2019 07 09 - master - handling both sorted & random images
*/
class RandomActivity : AppCompatActivity(), View.OnClickListener, OnLoadMoreListener, SwipeRefreshLayout.OnRefreshListener {
private lateinit var adapter: RandomImagesAdapter
private lateinit var items: MutableList<ImageObject?>
private lateinit var model: WallupViewModel
private var page = 1
private var type = ""

/**
* on create
*/
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_general)
setContentView(R.layout.activity_random_images)

model = WallupViewModel(this)
generalSwipe.setOnRefreshListener(this)
fetch(listener)

fetch("", listener)
Config.disposableRandomActivity.add(RxBus.subscribe { events(it) })
generalLoad.setOnClickListener(this)

randomSwipe.setOnRefreshListener(this)
randomShuffle.setOnClickListener(this)
randomLoad.setOnClickListener(this)
}

/**
Expand All @@ -74,10 +81,19 @@ class RandomActivity : AppCompatActivity(), View.OnClickListener, OnLoadMoreList
override fun onClick(v: View?) {
v?.let {
when (v.id) {
generalLoad.id -> {
generalLoad.gone()
generalP.show()
fetch(listener)
randomLoad.id -> {
randomLoad.gone()
randomP.show()
fetch(type, listener)
}

randomShuffle.id -> {
items.clear()
adapter.notifyDataSetChanged()
randomP.show()

type = RANDOM
fetch(RANDOM, listener)
}
}
}
Expand All @@ -87,21 +103,26 @@ class RandomActivity : AppCompatActivity(), View.OnClickListener, OnLoadMoreList
* get more items
*/
override fun onLoadMore() {
fetch(listenerPaginated)
fetch(type, listenerPaginated)
}

/**
* refresh items
*/
override fun onRefresh() {
fetch(listener)
page = 1
type = ""
fetch(type, listener)
}

/**
* fetch images
*/
private fun fetch(callback: (Any?, List<ImageObject>?) -> Unit) {
model.getRandomImages(callback)
private fun fetch(type: String, callback: (Any?, List<ImageObject>?) -> Unit) {
when (type) {
RANDOM -> model.getRandomImages(callback)
else -> model.getSortedImages(page, callback)
}
}


Expand All @@ -111,7 +132,7 @@ class RandomActivity : AppCompatActivity(), View.OnClickListener, OnLoadMoreList
private fun events(event: String) {
when (event) {
LOAD_MORE -> {
fetch(listenerPaginated)
fetch(type, listenerPaginated)
}
}
}
Expand All @@ -122,25 +143,27 @@ class RandomActivity : AppCompatActivity(), View.OnClickListener, OnLoadMoreList
private var listener = object : (Any?, List<ImageObject>?) -> Unit {
override fun invoke(e: Any?, r: List<ImageObject>?) {

generalSwipe.isRefreshing = false
generalP.gone()
randomSwipe.isRefreshing = false
randomP.gone()

e?.let {
loge(it)
toast("failed to fetch images")
generalLoad.show()
randomLoad.show()
}
r?.let {
items = it.toMutableList()
items.add(null)

generalRecycler.layoutManager = StaggeredGridLayoutManager(2, LinearLayoutManager.VERTICAL)
adapter = RandomImagesAdapter(items, generalRecycler)
generalRecycler.adapter = adapter
randomRecycler.layoutManager = StaggeredGridLayoutManager(2, LinearLayoutManager.VERTICAL)
adapter = RandomImagesAdapter(items, randomRecycler)
randomRecycler.adapter = adapter
adapter.setLoadMore(this@RandomActivity)

if (type.isEmpty())
page++
}
}

}


Expand Down Expand Up @@ -171,7 +194,13 @@ class RandomActivity : AppCompatActivity(), View.OnClickListener, OnLoadMoreList
items.addAll(it)
items.add(null)

adapter.notifyItemRangeInserted(count, it.size + 1)
if (count < 30)
adapter.setLoadMore(null)
else
adapter.notifyItemRangeInserted(count, it.size + 1)

if (type.isEmpty())
page++
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class CollectionVerticalAdapter(
context = parent.context

return when (viewType) {
VIEW_INITIAL -> CollectionVerticalInitialHolder(LayoutInflater.from(parent.context).inflate(R.layout.inflator_vertical_collection_init, parent, false))
VIEW_INITIAL -> CollectionVerticalInitialHolder(LayoutInflater.from(parent.context).inflate(R.layout.inflator_collections_vertical_init, parent, false))
VIEW_ITEM -> CollectionVerticalHolder(LayoutInflater.from(parent.context).inflate(R.layout.inflator_image_fullscreen, parent, false))
else -> LoadingFHolder(LayoutInflater.from(parent.context).inflate(R.layout.inflator_loading_full, parent, false))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.dawnimpulse.wallup.ui.objects.CollectionTransferObject
import com.dawnimpulse.wallup.utils.functions.gone
import com.dawnimpulse.wallup.utils.handlers.ImageHandler
import jp.wasabeef.blurry.Blurry
import kotlinx.android.synthetic.main.inflator_vertical_collection_init.view.*
import kotlinx.android.synthetic.main.inflator_collections_vertical_init.view.*

/**
* @info -
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ class WallupViewModel(private val activity: AppCompatActivity) {
}


/**
* get sorted images
* @param callback
*/
fun getSortedImages(page: Int, callback: (Any?, List<ImageObject>?) -> Unit) {
Lifecycle.onStart(activity) {
WallupRepo.getSortedImages(page, callback)
}
}


/**
* get homescreen
* @param callback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ object ImageHandler {
*/
fun setImageOnVerticalCols(view: ImageView, url: String) {
Glide.with(view.context)
.load("$url&fm=webp&h=720&q=95")
.load("$url&fm=webp&h=720&q=85")
.diskCacheStrategy(DiskCacheStrategy.ALL)
.transition(GenericTransitionOptions.with(R.anim.fade_in_animation))
.into(view)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package com.dawnimpulse.wallup.utils.reusables
*/
const val UNSPLASH_URL = "https://api.unsplash.com"
const val PEXELS_URL = "https://api.pexels.com"
const val UTM = "?utm_source=wallup&utm_medium=referral"

const val TYPE = "type"
const val WALLUP = "wallup"
Expand Down Expand Up @@ -53,6 +54,7 @@ const val WALLPAPER_TIME = "wallpaperTime"
const val WALLPAPER_WIFI = "wallpaperWifi"
const val CRASHLYTICS = "crashlytics"
const val ANALYTICS = "analytics"
const val RANDOM = "random"

const val FAIL_LOAD_MORE = "failLoadMore"
const val FAIL_LOAD_MORE_V = "failLoadMoreV"
Expand Down
Loading

0 comments on commit 3e1605d

Please sign in to comment.