Removed disposable

This commit is contained in:
h4h13 2019-11-05 20:24:20 +05:30
parent 89fa903f53
commit e38dc6c913
2 changed files with 18 additions and 42 deletions

View file

@ -13,7 +13,7 @@ android {
vectorDrawables.useSupportLibrary = true vectorDrawables.useSupportLibrary = true
applicationId "code.name.monkey.retromusic" applicationId "code.name.monkey.retromusic"
versionCode 389 versionCode 390
versionName '3.4.600' versionName '3.4.600'
multiDexEnabled true multiDexEnabled true

View file

@ -1,12 +1,10 @@
package code.name.monkey.retromusic.fragments.mainactivity.home package code.name.monkey.retromusic.fragments.mainactivity.home
import android.app.ActivityOptions import android.app.ActivityOptions
import android.graphics.Bitmap
import android.os.Bundle import android.os.Bundle
import android.util.DisplayMetrics import android.util.DisplayMetrics
import android.view.* import android.view.*
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import code.name.monkey.appthemehelper.common.ATHToolbarActivity import code.name.monkey.appthemehelper.common.ATHToolbarActivity
import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.ColorUtil
@ -28,15 +26,10 @@ import code.name.monkey.retromusic.model.smartplaylist.LastAddedPlaylist
import code.name.monkey.retromusic.model.smartplaylist.MyTopTracksPlaylist import code.name.monkey.retromusic.model.smartplaylist.MyTopTracksPlaylist
import code.name.monkey.retromusic.mvp.presenter.HomePresenter import code.name.monkey.retromusic.mvp.presenter.HomePresenter
import code.name.monkey.retromusic.mvp.presenter.HomeView import code.name.monkey.retromusic.mvp.presenter.HomeView
import code.name.monkey.retromusic.util.Compressor
import code.name.monkey.retromusic.util.NavigationUtil import code.name.monkey.retromusic.util.NavigationUtil
import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.PreferenceUtil
import code.name.monkey.retromusic.util.RetroColorUtil import code.name.monkey.retromusic.util.RetroColorUtil
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.abs_playlists.* import kotlinx.android.synthetic.main.abs_playlists.*
import kotlinx.android.synthetic.main.fragment_banner_home.* import kotlinx.android.synthetic.main.fragment_banner_home.*
import kotlinx.android.synthetic.main.home_content.* import kotlinx.android.synthetic.main.home_content.*
@ -45,11 +38,10 @@ import java.util.*
import javax.inject.Inject import javax.inject.Inject
class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallbacks, HomeView { class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallbacks, HomeView {
private lateinit var homeAdapter: HomeAdapter
@Inject @Inject
lateinit var homePresenter: HomePresenter lateinit var homePresenter: HomePresenter
private var disposable: CompositeDisposable = CompositeDisposable() private lateinit var homeAdapter: HomeAdapter
private lateinit var toolbar: Toolbar private lateinit var toolbar: Toolbar
override fun sections(sections: ArrayList<Home>) { override fun sections(sections: ArrayList<Home>) {
@ -62,23 +54,12 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
} }
private fun loadImageFromStorage() { private fun loadImageFromStorage() {
disposable.add(Compressor(context!!) Glide.with(requireContext())
.setMaxHeight(300) .load(File(PreferenceUtil.getInstance(requireContext()).profileImage, Constants.USER_PROFILE))
.setMaxWidth(300) .asBitmap()
.setQuality(75) .placeholder(R.drawable.ic_person_flat)
.setCompressFormat(Bitmap.CompressFormat.WEBP) .error(R.drawable.ic_person_flat)
.compressToBitmapAsFlowable(File(PreferenceUtil.getInstance(requireContext()).profileImage, Constants.USER_PROFILE)) .into(userImage)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
if (it != null) {
userImage.setImageBitmap(it)
} else {
userImage.setImageDrawable(ContextCompat.getDrawable(requireContext(), R.drawable.ic_person_flat))
}
}) {
userImage.setImageDrawable(ContextCompat.getDrawable(requireContext(), R.drawable.ic_person_flat))
})
} }
private val displayMetrics: DisplayMetrics private val displayMetrics: DisplayMetrics
@ -169,7 +150,6 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
override fun onDestroyView() { override fun onDestroyView() {
super.onDestroyView() super.onDestroyView()
disposable.dispose()
homePresenter.detachView() homePresenter.detachView()
} }
@ -200,7 +180,6 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
private fun getTimeOfTheDay() { private fun getTimeOfTheDay() {
val c = Calendar.getInstance() val c = Calendar.getInstance()
val timeOfDay = c.get(Calendar.HOUR_OF_DAY) val timeOfDay = c.get(Calendar.HOUR_OF_DAY)
var images = arrayOf<String>() var images = arrayOf<String>()
when (timeOfDay) { when (timeOfDay) {
in 0..5 -> images = resources.getStringArray(R.array.night) in 0..5 -> images = resources.getStringArray(R.array.night)
@ -209,28 +188,25 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
in 16..19 -> images = resources.getStringArray(R.array.evening) in 16..19 -> images = resources.getStringArray(R.array.evening)
in 20..23 -> images = resources.getStringArray(R.array.night) in 20..23 -> images = resources.getStringArray(R.array.night)
} }
val day = images[Random().nextInt(images.size)] val day = images[Random().nextInt(images.size)]
loadTimeImage(day) loadTimeImage(day)
} }
private fun loadTimeImage(day: String) { private fun loadTimeImage(day: String) {
if (bannerImage != null) { bannerImage?.let {
val request = Glide.with(requireContext())
if (PreferenceUtil.getInstance(requireContext()).bannerImage.isEmpty()) { if (PreferenceUtil.getInstance(requireContext()).bannerImage.isEmpty()) {
Glide.with(requireActivity()) request.load(day)
.load(day)
.placeholder(R.drawable.material_design_default) .placeholder(R.drawable.material_design_default)
.diskCacheStrategy(DiskCacheStrategy.ALL) .error(R.drawable.material_design_default)
.into(bannerImage!!) .into(it)
} else { } else {
disposable.add(Compressor(requireActivity()) request.load(File(PreferenceUtil.getInstance(requireContext()).bannerImage, USER_BANNER))
.setQuality(100) .asBitmap()
.setCompressFormat(Bitmap.CompressFormat.WEBP) .placeholder(R.drawable.material_design_default)
.compressToBitmapAsFlowable(File(PreferenceUtil.getInstance(requireContext()).bannerImage, USER_BANNER)) .error(R.drawable.material_design_default)
.subscribeOn(Schedulers.io()) .into(it)
.observeOn(AndroidSchedulers.mainThread())
.subscribe { bitmap -> bannerImage.setImageBitmap(bitmap) })
} }
} }
loadImageFromStorage() loadImageFromStorage()