fix Glide crash in MainActivity (#1224)

This commit is contained in:
Konrad Pozniak 2019-04-27 18:20:42 +02:00 committed by GitHub
parent 4456f255c5
commit c410600fe4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 42 deletions

View File

@ -23,7 +23,6 @@ import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.bumptech.glide.Glide;
@ -518,25 +517,14 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut
}
private void fetchUserInfo() {
mastodonApi.accountVerifyCredentials().enqueue(new Callback<Account>() {
@Override
public void onResponse(@NonNull Call<Account> call, @NonNull Response<Account> response) {
if (response.isSuccessful()) {
onFetchUserInfoSuccess(response.body());
} else {
onFetchUserInfoFailure(new Exception(response.message()));
}
}
@Override
public void onFailure(@NonNull Call<Account> call, @NonNull Throwable t) {
onFetchUserInfoFailure((Exception) t);
}
});
mastodonApi.accountVerifyCredentials()
.observeOn(AndroidSchedulers.mainThread())
.as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY)))
.subscribe(this::onFetchUserInfoSuccess, MainActivity::onFetchUserInfoFailure);
}
private void onFetchUserInfoSuccess(Account me) {
// Add the header image and avatar from the account, into the navigation drawer header.
ImageView background = headerResult.getHeaderBackgroundView();
@ -598,8 +586,8 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut
headerResult.setActiveProfile(accountManager.getActiveAccount().getId());
}
private static void onFetchUserInfoFailure(Exception exception) {
Log.e(TAG, "Failed to fetch user info. " + exception.getMessage());
private static void onFetchUserInfoFailure(Throwable throwable) {
Log.e(TAG, "Failed to fetch user info. " + throwable.getMessage());
}
@Nullable

View File

@ -176,7 +176,7 @@ public interface MastodonApi {
Single<Status> unpinStatus(@Path("id") String statusId);
@GET("api/v1/accounts/verify_credentials")
Call<Account> accountVerifyCredentials();
Single<Account> accountVerifyCredentials();
@FormUrlEncoded
@PATCH("api/v1/accounts/update_credentials")

View File

@ -31,6 +31,8 @@ import com.keylesspalace.tusky.entity.StringField
import com.keylesspalace.tusky.network.MastodonApi
import com.keylesspalace.tusky.util.*
import io.reactivex.Single
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.addTo
import io.reactivex.schedulers.Schedulers
import okhttp3.MediaType
import okhttp3.MultipartBody
@ -63,32 +65,24 @@ class EditProfileViewModel @Inject constructor(
private var oldProfileData: Account? = null
private val callList: MutableList<Call<*>> = mutableListOf()
private val disposeables = CompositeDisposable()
fun obtainProfile() {
if(profileData.value == null || profileData.value is Error) {
profileData.postValue(Loading())
val call = mastodonApi.accountVerifyCredentials()
call.enqueue(object : Callback<Account> {
override fun onResponse(call: Call<Account>,
response: Response<Account>) {
if (response.isSuccessful) {
val profile = response.body()
oldProfileData = profile
profileData.postValue(Success(profile))
} else {
profileData.postValue(Error())
}
}
mastodonApi.accountVerifyCredentials()
.subscribe(
{profile ->
oldProfileData = profile
profileData.postValue(Success(profile))
},
{
profileData.postValue(Error())
})
.addTo(disposeables)
override fun onFailure(call: Call<Account>, t: Throwable) {
profileData.postValue(Error())
}
})
callList.add(call)
}
}
@ -138,6 +132,7 @@ class EditProfileViewModel @Inject constructor(
}, {
imageLiveData.postValue(Error())
})
.addTo(disposeables)
}
fun save(newDisplayName: String, newNote: String, newLocked: Boolean, newFields: List<StringField>, context: Context) {
@ -267,9 +262,7 @@ class EditProfileViewModel @Inject constructor(
}
override fun onCleared() {
callList.forEach {
it.cancel()
}
disposeables.dispose()
}