fix Glide crash in MainActivity (#1224)
This commit is contained in:
parent
4456f255c5
commit
c410600fe4
3 changed files with 23 additions and 42 deletions
|
@ -23,7 +23,6 @@ import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
|
@ -518,25 +517,14 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fetchUserInfo() {
|
private void fetchUserInfo() {
|
||||||
|
mastodonApi.accountVerifyCredentials()
|
||||||
mastodonApi.accountVerifyCredentials().enqueue(new Callback<Account>() {
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
@Override
|
.as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY)))
|
||||||
public void onResponse(@NonNull Call<Account> call, @NonNull Response<Account> response) {
|
.subscribe(this::onFetchUserInfoSuccess, MainActivity::onFetchUserInfoFailure);
|
||||||
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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onFetchUserInfoSuccess(Account me) {
|
private void onFetchUserInfoSuccess(Account me) {
|
||||||
|
|
||||||
// Add the header image and avatar from the account, into the navigation drawer header.
|
// Add the header image and avatar from the account, into the navigation drawer header.
|
||||||
|
|
||||||
ImageView background = headerResult.getHeaderBackgroundView();
|
ImageView background = headerResult.getHeaderBackgroundView();
|
||||||
|
@ -598,8 +586,8 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut
|
||||||
headerResult.setActiveProfile(accountManager.getActiveAccount().getId());
|
headerResult.setActiveProfile(accountManager.getActiveAccount().getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void onFetchUserInfoFailure(Exception exception) {
|
private static void onFetchUserInfoFailure(Throwable throwable) {
|
||||||
Log.e(TAG, "Failed to fetch user info. " + exception.getMessage());
|
Log.e(TAG, "Failed to fetch user info. " + throwable.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|
|
@ -176,7 +176,7 @@ public interface MastodonApi {
|
||||||
Single<Status> unpinStatus(@Path("id") String statusId);
|
Single<Status> unpinStatus(@Path("id") String statusId);
|
||||||
|
|
||||||
@GET("api/v1/accounts/verify_credentials")
|
@GET("api/v1/accounts/verify_credentials")
|
||||||
Call<Account> accountVerifyCredentials();
|
Single<Account> accountVerifyCredentials();
|
||||||
|
|
||||||
@FormUrlEncoded
|
@FormUrlEncoded
|
||||||
@PATCH("api/v1/accounts/update_credentials")
|
@PATCH("api/v1/accounts/update_credentials")
|
||||||
|
|
|
@ -31,6 +31,8 @@ import com.keylesspalace.tusky.entity.StringField
|
||||||
import com.keylesspalace.tusky.network.MastodonApi
|
import com.keylesspalace.tusky.network.MastodonApi
|
||||||
import com.keylesspalace.tusky.util.*
|
import com.keylesspalace.tusky.util.*
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
|
import io.reactivex.rxkotlin.addTo
|
||||||
import io.reactivex.schedulers.Schedulers
|
import io.reactivex.schedulers.Schedulers
|
||||||
import okhttp3.MediaType
|
import okhttp3.MediaType
|
||||||
import okhttp3.MultipartBody
|
import okhttp3.MultipartBody
|
||||||
|
@ -63,32 +65,24 @@ class EditProfileViewModel @Inject constructor(
|
||||||
|
|
||||||
private var oldProfileData: Account? = null
|
private var oldProfileData: Account? = null
|
||||||
|
|
||||||
private val callList: MutableList<Call<*>> = mutableListOf()
|
private val disposeables = CompositeDisposable()
|
||||||
|
|
||||||
fun obtainProfile() {
|
fun obtainProfile() {
|
||||||
if(profileData.value == null || profileData.value is Error) {
|
if(profileData.value == null || profileData.value is Error) {
|
||||||
|
|
||||||
profileData.postValue(Loading())
|
profileData.postValue(Loading())
|
||||||
|
|
||||||
val call = mastodonApi.accountVerifyCredentials()
|
mastodonApi.accountVerifyCredentials()
|
||||||
call.enqueue(object : Callback<Account> {
|
.subscribe(
|
||||||
override fun onResponse(call: Call<Account>,
|
{profile ->
|
||||||
response: Response<Account>) {
|
oldProfileData = profile
|
||||||
if (response.isSuccessful) {
|
profileData.postValue(Success(profile))
|
||||||
val profile = response.body()
|
},
|
||||||
oldProfileData = profile
|
{
|
||||||
profileData.postValue(Success(profile))
|
profileData.postValue(Error())
|
||||||
} else {
|
})
|
||||||
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())
|
imageLiveData.postValue(Error())
|
||||||
})
|
})
|
||||||
|
.addTo(disposeables)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun save(newDisplayName: String, newNote: String, newLocked: Boolean, newFields: List<StringField>, context: Context) {
|
fun save(newDisplayName: String, newNote: String, newLocked: Boolean, newFields: List<StringField>, context: Context) {
|
||||||
|
@ -267,9 +262,7 @@ class EditProfileViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
callList.forEach {
|
disposeables.dispose()
|
||||||
it.cancel()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue