diff --git a/app/build.gradle b/app/build.gradle index c3425702..319f0117 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -120,10 +120,10 @@ dependencies { implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.core:core-ktx:1.1.0' - implementation 'androidx.fragment:fragment:1.2.0-rc02' - implementation 'androidx.recyclerview:recyclerview:1.1.0-rc01' + implementation 'androidx.fragment:fragment:1.2.0-rc04' + implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha01' - implementation 'com.google.android.material:material:1.2.0-alpha01' + implementation 'com.google.android.material:material:1.2.0-alpha03' implementation 'com.google.android.play:core:1.6.4' def retrofit_version = "2.6.2" @@ -140,17 +140,12 @@ dependencies { implementation "com.afollestad.material-dialogs:bottomsheets:$material_dialog_version" implementation 'com.afollestad:material-cab:0.1.12' - implementation 'com.github.bumptech.glide:glide:3.8.0' implementation 'com.github.bumptech.glide:okhttp3-integration:1.5.0' - implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' - implementation 'io.reactivex.rxjava2:rxjava:2.2.9' - implementation('com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.11.0@aar') { transitive = true } - /*UI Library*/ implementation 'me.zhanghai.android.materialprogressbar:library:1.6.1' @@ -174,6 +169,4 @@ dependencies { def dagger_version = "2.23.1" implementation "com.google.dagger:dagger:$dagger_version" kapt "com.google.dagger:dagger-compiler:$dagger_version" - - } \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/UserInfoActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/UserInfoActivity.kt index c623d11d..732e603c 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/UserInfoActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/UserInfoActivity.kt @@ -30,18 +30,17 @@ import com.afollestad.materialdialogs.LayoutMode import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.bottomsheets.BottomSheet import com.afollestad.materialdialogs.list.listItems -import io.reactivex.android.schedulers.AndroidSchedulers -import io.reactivex.disposables.CompositeDisposable -import io.reactivex.schedulers.Schedulers import kotlinx.android.synthetic.main.activity_user_info.* +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext import java.io.File import java.io.FileOutputStream import java.io.IOException class UserInfoActivity : AbsBaseActivity() { - private var disposable = CompositeDisposable() - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_user_info) @@ -185,26 +184,28 @@ class UserInfoActivity : AbsBaseActivity() { } private fun loadBannerFromStorage(profileImagePath: String) { - disposable.add(Compressor(this).setQuality(100) - .setCompressFormat(Bitmap.CompressFormat.WEBP) - .compressToBitmapAsFlowable(File(profileImagePath, USER_BANNER)) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe({ bitmap -> bannerImage.setImageBitmap(bitmap) }, { t -> println(t) }) - ) + CoroutineScope(Dispatchers.IO).launch { + withContext(Dispatchers.IO) { + val bitmap = Compressor(this@UserInfoActivity).setQuality(100) + .setCompressFormat(Bitmap.CompressFormat.WEBP) + .compressToBitmap(File(profileImagePath, USER_BANNER)) + withContext(Dispatchers.Main) { bannerImage.setImageBitmap(bitmap) } + } + } } private fun loadImageFromStorage(path: String) { - disposable.add(Compressor(this) - .setMaxHeight(300) - .setMaxWidth(300) - .setQuality(75) - .setCompressFormat(Bitmap.CompressFormat.WEBP) - .compressToBitmapAsFlowable(File(path, USER_PROFILE)) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe({ bitmap -> userImage.setImageBitmap(bitmap) }, { t -> println(t) }) - ) + CoroutineScope(Dispatchers.IO).launch { + withContext(Dispatchers.IO) { + val bitmap = Compressor(this@UserInfoActivity) + .setMaxHeight(300) + .setMaxWidth(300) + .setQuality(75) + .setCompressFormat(Bitmap.CompressFormat.WEBP) + .compressToBitmap(File(path, USER_PROFILE)) + withContext(Dispatchers.Main) { userImage.setImageBitmap(bitmap) } + } + } } private fun saveToInternalStorage(bitmapImage: Bitmap, userBanner: String): String { diff --git a/app/src/main/java/code/name/monkey/retromusic/rest/LastFMRestClient.java b/app/src/main/java/code/name/monkey/retromusic/rest/LastFMRestClient.java index 77d0cb95..84b786ff 100644 --- a/app/src/main/java/code/name/monkey/retromusic/rest/LastFMRestClient.java +++ b/app/src/main/java/code/name/monkey/retromusic/rest/LastFMRestClient.java @@ -30,7 +30,6 @@ import okhttp3.Interceptor; import okhttp3.OkHttpClient; import okhttp3.Request; import retrofit2.Retrofit; -import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; import retrofit2.converter.gson.GsonConverterFactory; @@ -49,7 +48,6 @@ public class LastFMRestClient { .baseUrl(BASE_URL) .callFactory(client) .addConverterFactory(GsonConverterFactory.create()) - .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .build(); apiService = restAdapter.create(LastFMService.class); diff --git a/app/src/main/java/code/name/monkey/retromusic/util/Compressor.java b/app/src/main/java/code/name/monkey/retromusic/util/Compressor.java index a684fc8b..312a1f30 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/Compressor.java +++ b/app/src/main/java/code/name/monkey/retromusic/util/Compressor.java @@ -20,8 +20,6 @@ import android.graphics.Bitmap; import java.io.File; import java.io.IOException; -import io.reactivex.Flowable; - /** * Created on : June 18, 2016 * Author : zetbaitsu @@ -77,28 +75,4 @@ public class Compressor { public Bitmap compressToBitmap(File imageFile) throws IOException { return ImageUtil.decodeSampledBitmapFromFile(imageFile, maxWidth, maxHeight); } - - public Flowable compressToFileAsFlowable(final File imageFile) { - return compressToFileAsFlowable(imageFile, imageFile.getName()); - } - - public Flowable compressToFileAsFlowable(final File imageFile, final String compressedFileName) { - return Flowable.defer(() -> { - try { - return Flowable.just(compressToFile(imageFile, compressedFileName)); - } catch (IOException e) { - return Flowable.error(e); - } - }); - } - - public Flowable compressToBitmapAsFlowable(final File imageFile) { - return Flowable.defer(() -> { - try { - return Flowable.just(compressToBitmap(imageFile)); - } catch (IOException e) { - return Flowable.error(e); - } - }); - } }