Removed RX java
This commit is contained in:
parent
62726de918
commit
09c056f5ca
4 changed files with 26 additions and 60 deletions
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<File> compressToFileAsFlowable(final File imageFile) {
|
||||
return compressToFileAsFlowable(imageFile, imageFile.getName());
|
||||
}
|
||||
|
||||
public Flowable<File> 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<Bitmap> compressToBitmapAsFlowable(final File imageFile) {
|
||||
return Flowable.defer(() -> {
|
||||
try {
|
||||
return Flowable.just(compressToBitmap(imageFile));
|
||||
} catch (IOException e) {
|
||||
return Flowable.error(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue