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

Commit

Permalink
New : Add collection in main adapter + other bug fixes (trello.com/c/…
Browse files Browse the repository at this point in the history
…tMHoOkBJ)
  • Loading branch information
DawnImpulse committed Oct 28, 2018
1 parent 81c544b commit 9663401
Show file tree
Hide file tree
Showing 20 changed files with 219 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class ArtistProfileActivity : AppCompatActivity(), View.OnClickListener {
model.userDetails(intent.extras.getString(C.USERNAME)) { error, details ->
error?.let {
L.d(NAME, error.toString())
artistProgress.visibility = View.GONE
Toast.short(this, "Error Occurred")
}
details?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ class ImageActivity : AppCompatActivity(), View.OnClickListener {

// change add icon if user has image in any collection
details.current_user_collections?.let {
if (details.current_user_collections.isNotEmpty())
if (it.isNotEmpty())
imagePreviewCollectI.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.vd_plus_circle))
else
imagePreviewCollectI.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.vd_plus))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ class MainActivity : AppCompatActivity(), ViewPager.OnPageChangeListener, View.O
private lateinit var pagerAdapter: ViewPagerAdapter
private lateinit var randomFragment:MainFragment
private lateinit var latestFragment: MainFragment
private lateinit var trendingFragment: MainFragment
private lateinit var curatedFragment: MainFragment
private lateinit var navSheet: ModalSheetNav
private lateinit var navBundle: Bundle
private var lastItemSelected = 0
Expand All @@ -67,7 +65,6 @@ class MainActivity : AppCompatActivity(), ViewPager.OnPageChangeListener, View.O
mainViewPager.addOnPageChangeListener(this)
mainViewPager.offscreenPageLimit = 2

mainNavTrending.setOnClickListener(this)
mainNavRandom.setOnClickListener(this)
mainNavLatest.setOnClickListener(this)
mainNavUp.setOnClickListener(this)
Expand All @@ -82,7 +79,6 @@ class MainActivity : AppCompatActivity(), ViewPager.OnPageChangeListener, View.O
when (v.id) {
mainNavLatest.id -> currentNavItem(0)
mainNavRandom.id -> currentNavItem(1)
mainNavTrending.id -> currentNavItem(2)
mainNavUp.id -> {
navSheet.show(supportFragmentManager, C.BOTTOM_SHEET)
currentNavItem(lastItemSelected)
Expand All @@ -97,10 +93,6 @@ class MainActivity : AppCompatActivity(), ViewPager.OnPageChangeListener, View.O
toast("Refreshing Random List")
randomFragment.onRefresh()
}
2 -> {
toast("Refreshing Trending List")
trendingFragment.onRefresh()
}
}
}
mainSearch.id ->{
Expand Down Expand Up @@ -134,21 +126,15 @@ class MainActivity : AppCompatActivity(), ViewPager.OnPageChangeListener, View.O
pagerAdapter = ViewPagerAdapter(supportFragmentManager)
latestFragment = MainFragment()
randomFragment = MainFragment()
trendingFragment = MainFragment()

latestBundle.putString(C.TYPE, C.LATEST)
randomBundle.putString(C.TYPE, C.RANDOM)
trendingBundle.putString(C.TYPE, C.TRENDING)

trendingBundle.putBoolean(C.LIKE,false)

latestFragment.arguments = latestBundle
randomFragment.arguments = randomBundle
trendingFragment.arguments = trendingBundle

pagerAdapter.addFragment(latestFragment, C.LATEST)
pagerAdapter.addFragment(randomFragment, C.RANDOM)
pagerAdapter.addFragment(trendingFragment, C.TRENDING)
viewPager.adapter = pagerAdapter
}

Expand All @@ -161,21 +147,12 @@ class MainActivity : AppCompatActivity(), ViewPager.OnPageChangeListener, View.O
mainViewPager.currentItem = 0
mainNavLatestT.visibility = View.VISIBLE
mainNavRandomT.visibility = View.GONE
mainNavTrendingT.visibility = View.GONE
}
1 -> {
lastItemSelected = 1
mainViewPager.currentItem = 1
mainNavLatestT.visibility = View.GONE
mainNavRandomT.visibility = View.VISIBLE
mainNavTrendingT.visibility = View.GONE
}
2 -> {
lastItemSelected = 2
mainViewPager.currentItem = 2
mainNavLatestT.visibility = View.GONE
mainNavRandomT.visibility = View.GONE
mainNavTrendingT.visibility = View.VISIBLE
}
}
}
Expand All @@ -187,17 +164,10 @@ class MainActivity : AppCompatActivity(), ViewPager.OnPageChangeListener, View.O
0 -> {
mainNavLatestI.drawable.setColorFilter(colors.WHITE, PorterDuff.Mode.SRC_ATOP)
mainNavRandomI.drawable.setColorFilter(colors.GREY_500,PorterDuff.Mode.SRC_ATOP)
mainNavTrendingI.drawable.setColorFilter(colors.GREY_500, PorterDuff.Mode.SRC_ATOP)
}
1 -> {
mainNavLatestI.drawable.setColorFilter(colors.GREY_500, PorterDuff.Mode.SRC_ATOP)
mainNavRandomI.drawable.setColorFilter(colors.WHITE,PorterDuff.Mode.SRC_ATOP)
mainNavTrendingI.drawable.setColorFilter(colors.GREY_500, PorterDuff.Mode.SRC_ATOP)
}
2 -> {
mainNavLatestI.drawable.setColorFilter(colors.GREY_500, PorterDuff.Mode.SRC_ATOP)
mainNavRandomI.drawable.setColorFilter(colors.GREY_500,PorterDuff.Mode.SRC_ATOP)
mainNavTrendingI.drawable.setColorFilter(colors.WHITE, PorterDuff.Mode.SRC_ATOP)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class ImageCollectionAdapter(private val lifecycle: Lifecycle,
json.put(C.COLLECTION_ID, col.id)
json.put(C.POSITION, position)
json.put(C.COLLECTION, Gson().toJson(col))
json.put(C.IMAGE,image)
EventBus.getDefault().post(Event(json))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.lifecycle.Lifecycle
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
Expand All @@ -30,6 +32,7 @@ import com.dawnimpulse.wallup.activities.ImageActivity
import com.dawnimpulse.wallup.handlers.ImageHandler
import com.dawnimpulse.wallup.interfaces.OnLoadMoreListener
import com.dawnimpulse.wallup.pojo.ImagePojo
import com.dawnimpulse.wallup.sheets.ModalSheetCollection
import com.dawnimpulse.wallup.sheets.ModalSheetUnsplash
import com.dawnimpulse.wallup.utils.C
import com.dawnimpulse.wallup.utils.Config
Expand Down Expand Up @@ -113,7 +116,6 @@ class MainAdapter(

// binding view holder
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {

if (holder is MainViewHolder) {
var image = images[position]!!
var artistClick = View.OnClickListener {
Expand All @@ -138,6 +140,13 @@ class MainAdapter(
// setting the like button
F.like(context, holder.like, false, image.liked_by_user)

// setting col icon
if (image.current_user_collections != null)
if (image.current_user_collections!!.isNotEmpty())
holder.col.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.vd_plus_circle_accent))
else
holder.col.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.vd_plus_accent))

// open image activity
holder.image.setOnClickListener {
var intent = Intent(context, ImageActivity::class.java)
Expand Down Expand Up @@ -168,6 +177,24 @@ class MainAdapter(
}
}

// open collection
holder.colL.setOnClickListener {
if (Config.USER_API_KEY.isNotEmpty()) {
var colSheet = ModalSheetCollection()
var bundle = Bundle()
bundle.putString(C.IMAGE_POJO, Gson().toJson(image))
image.current_user_collections?.let { cols ->
if (cols.isNotEmpty())
bundle.putString(C.COLLECTIONS, Gson().toJson(cols))
}
colSheet.arguments = bundle
colSheet.show((context as AppCompatActivity).supportFragmentManager, colSheet.tag)
} else {
var loginSheet = ModalSheetUnsplash()
loginSheet.show((context as AppCompatActivity).supportFragmentManager, loginSheet.tag)
}
}

// open artist page
holder.name.setOnClickListener(artistClick)
holder.circleImage.setOnClickListener(artistClick)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ import com.dawnimpulse.wallup.adapters.MainAdapter
import com.dawnimpulse.wallup.interfaces.OnLoadMoreListener
import com.dawnimpulse.wallup.models.DatabaseModel
import com.dawnimpulse.wallup.models.UnsplashModel
import com.dawnimpulse.wallup.pojo.CollectionPojo
import com.dawnimpulse.wallup.pojo.ImagePojo
import com.dawnimpulse.wallup.utils.C
import com.dawnimpulse.wallup.utils.Event
import com.dawnimpulse.wallup.utils.L
import com.google.gson.Gson
import kotlinx.android.synthetic.main.fragment_main.*
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
Expand All @@ -45,6 +47,7 @@ import org.greenrobot.eventbus.ThreadMode
* @note Updates :
* Saksham - 2018 05 20 - recent - using model
* Saksham - 2018 05 25 - recent - dummy layout
* Saksham - 2018 10 28 - master - event change collection
*/

class MainFragment : Fragment(), SwipeRefreshLayout.OnRefreshListener, OnLoadMoreListener {
Expand Down Expand Up @@ -155,6 +158,48 @@ class MainFragment : Fragment(), SwipeRefreshLayout.OnRefreshListener, OnLoadMor
}
}
}
if (event.obj.getString(C.TYPE) == C.IMAGE_TO_COLLECTION) {
// if image is added to a collection
if (event.obj.getBoolean(C.IS_ADDED)) {
var col = Gson().fromJson(event.obj.getString(C.COLLECTION), CollectionPojo::class.java)
var list = images
.asSequence()
.withIndex()
.filter { it.value!!.id == event.obj.getString(C.IMAGE) }
.map { it.index }
.toList()

if (list.isNotEmpty()) {
for (l in list) {
if (images[l]!!.current_user_collections == null)
images[l]!!.current_user_collections = arrayListOf()
images[l]!!.current_user_collections!!.add(col)
mainAdapter.notifyItemChanged(l)
}
}
} else {
//if image is removed from collection
var list = images
.asSequence()
.withIndex()
.filter { it.value!!.id == event.obj.getString(C.IMAGE) }
.map { it.index }
.toList()

if (list.isNotEmpty()) {
for (l in list) {
var cid = images[l]!!.current_user_collections!!
.asSequence()
.withIndex()
.filter { it.value.id == event.obj.getString(C.COLLECTION_ID) }
.map { it.index }
.toList()
images[l]!!.current_user_collections!!.removeAt(cid[0])
mainAdapter.notifyItemChanged(l)
}
}
}
}
}
}

Expand All @@ -170,7 +215,7 @@ class MainFragment : Fragment(), SwipeRefreshLayout.OnRefreshListener, OnLoadMor
timestamp = images[images.size - 1]!!.timestamp

if (arguments?.containsKey(C.LIKE)!!)
mainAdapter = MainAdapter(lifecycle, images, mainRecycler,false)
mainAdapter = MainAdapter(lifecycle, images, mainRecycler, false)
else
mainAdapter = MainAdapter(lifecycle, images, mainRecycler)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ data class ImagePojo(
@SerializedName("downloads") val downloads: Int = 0,
@SerializedName("exif") val exif: Exif? = null,
@SerializedName("liked_by_user") var liked_by_user: Boolean = false,
@SerializedName("current_user_collections") val current_user_collections: MutableList<CollectionPojo>? = null
@SerializedName("current_user_collections") var current_user_collections: MutableList<CollectionPojo>? = null
)

data class Urls(
Expand Down
1 change: 1 addition & 0 deletions app/src/main/kotlin/com/dawnimpulse/wallup/utils/C.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ object C {
const val IMAGE_TO_COLLECTION = "imageToCollection"
const val IS_ADDED = "isAdded"
const val VIEW = "view"
const val IMAGE = "image"



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ class MainViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val name = itemView.mainName!!
val like = itemView.mainLike!!
val likeL = itemView.mainLikeL!!
val col = itemView.mainCol
val colL = itemView.mainColL

}
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.
7 changes: 7 additions & 0 deletions app/src/main/res/drawable/vd_plus_accent.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>

<vector xmlns:android="http://schemas.android.com/apk/res/android" android:viewportWidth="24"
android:viewportHeight="24" android:width="24dp" android:height="24dp">
<path android:fillColor="@color/colorAccent"
android:pathData="M19 13H13V19H11V13H5V11H11V5H13V11H19V13Z" />
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/vd_plus_circle_accent.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>

<vector xmlns:android="http://schemas.android.com/apk/res/android" android:viewportWidth="36"
android:viewportHeight="36" android:width="36dp" android:height="36dp">
<group android:name="#ffa000ff">
<path android:fillColor="@color/colorAccent" android:fillAlpha="1.00"
android:pathData=" M 13.49 3.73 C 21.03 1.07 29.99 5.81 32.24 13.43 C 34.95 21.01 30.16 30.06 22.48 32.27 C 14.92 34.93 5.96 30.13 3.73 22.50 C 1.05 14.93 5.85 5.96 13.49 3.73 M 16.50 10.53 C 16.50 12.53 16.50 14.53 16.50 16.53 C 14.50 16.53 12.50 16.53 10.50 16.54 C 10.50 17.28 10.50 18.78 10.50 19.53 C 12.50 19.53 14.50 19.53 16.50 19.54 C 16.50 21.53 16.50 23.53 16.50 25.53 C 17.25 25.53 18.75 25.54 19.50 25.54 C 19.50 23.54 19.50 21.54 19.50 19.54 C 21.50 19.54 23.50 19.53 25.50 19.53 C 25.50 18.78 25.50 17.28 25.50 16.54 C 23.50 16.53 21.50 16.53 19.50 16.53 C 19.50 14.53 19.50 12.53 19.50 10.53 C 18.75 10.53 17.25 10.53 16.50 10.53 Z" />
</group>
</vector>
5 changes: 3 additions & 2 deletions app/src/main/res/layout/activity_artist_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
tools:context=".activities.ArtistProfileActivity">

<ScrollView
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="match_parent">

Expand All @@ -21,7 +22,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible">
android:visibility="gone">

<!--Name & DP-->
<RelativeLayout
Expand Down Expand Up @@ -324,8 +325,8 @@
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="128dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:indeterminate="true" />

</RelativeLayout>
Expand Down
Loading

0 comments on commit 9663401

Please sign in to comment.