Fix some issues

This commit is contained in:
Thomas 2020-04-24 14:41:44 +02:00
parent c7a6390346
commit 5f5ed0ac95
5 changed files with 88 additions and 60 deletions

View File

@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
android { android {
compileSdkVersion 29 compileSdkVersion 29
buildToolsVersion "29.0.2" buildToolsVersion "29.0.3"
defaultConfig { defaultConfig {
minSdkVersion 19 minSdkVersion 19
targetSdkVersion 29 targetSdkVersion 29

View File

@ -202,6 +202,7 @@ public abstract class BaseMainActivity extends BaseActivity
private View dialogReleaseNoteView; private View dialogReleaseNoteView;
private List<Account> developers; private List<Account> developers;
public static boolean isAttached = false;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -2383,6 +2384,18 @@ public abstract class BaseMainActivity extends BaseActivity
MASTALAB MASTALAB
} }
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
isAttached = true;
}
@Override
public void onDetachedFromWindow() {
super.onDetachedFromWindow();
isAttached = false;
}
/** /**
* Page Adapter for Mastodon & Peertube & PixelFed * Page Adapter for Mastodon & Peertube & PixelFed
*/ */
@ -2521,6 +2534,7 @@ public abstract class BaseMainActivity extends BaseActivity
} }
} }
@Override @Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) { public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
if (mPageReferenceMap != null) { if (mPageReferenceMap != null) {

View File

@ -225,13 +225,15 @@ public class Account implements Parcelable {
//emojis can be used several times so we have to loop //emojis can be used several times so we have to loop
for (int startPosition = -1; (startPosition = displayNameSpan.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) { for (int startPosition = -1; (startPosition = displayNameSpan.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) {
final int endPosition = startPosition + targetedEmoji.length(); final int endPosition = startPosition + targetedEmoji.length();
if (endPosition <= displayNameSpan.toString().length() && endPosition >= startPosition) { if (resource != null && endPosition <= displayNameSpan.toString().length() && endPosition >= startPosition) {
resource.setBounds(0, 0, (int) Helper.convertDpToPixel(20, context), (int) Helper.convertDpToPixel(20, context)); try {
resource.setVisible(true, true); resource.setBounds(0, 0, (int) Helper.convertDpToPixel(20, context), (int) Helper.convertDpToPixel(20, context));
ImageSpan imageSpan = new ImageSpan(resource); resource.setVisible(true, true);
displayNameSpan.setSpan( ImageSpan imageSpan = new ImageSpan(resource);
imageSpan, startPosition, displayNameSpan.setSpan(
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); imageSpan, startPosition,
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
}catch (Exception ignored){}
return; return;
} }
} }

View File

@ -890,14 +890,16 @@ public class Status implements Parcelable {
//emojis can be used several times so we have to loop //emojis can be used several times so we have to loop
for (int startPosition = -1; (startPosition = contentSpan.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) { for (int startPosition = -1; (startPosition = contentSpan.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) {
final int endPosition = startPosition + targetedEmoji.length(); final int endPosition = startPosition + targetedEmoji.length();
if (endPosition <= contentSpan.toString().length() && endPosition >= startPosition) { if (resource != null && endPosition <= contentSpan.toString().length() && endPosition >= startPosition) {
ImageSpan imageSpan; ImageSpan imageSpan;
resource.setBounds(0, 0, (int) Helper.convertDpToPixel(20, context), (int) Helper.convertDpToPixel(20, context)); try {
resource.setVisible(true, true); resource.setBounds(0, 0, (int) Helper.convertDpToPixel(20, context), (int) Helper.convertDpToPixel(20, context));
imageSpan = new ImageSpan(resource); resource.setVisible(true, true);
contentSpan.setSpan( imageSpan = new ImageSpan(resource);
imageSpan, startPosition, contentSpan.setSpan(
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); imageSpan, startPosition,
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
}catch (Exception ignored){}
} }
} }
} }

View File

@ -232,6 +232,7 @@ import okhttp3.TlsVersion;
import static android.content.Context.DOWNLOAD_SERVICE; import static android.content.Context.DOWNLOAD_SERVICE;
import static app.fedilab.android.activities.BaseMainActivity.filters; import static app.fedilab.android.activities.BaseMainActivity.filters;
import static app.fedilab.android.activities.BaseMainActivity.isAttached;
import static app.fedilab.android.activities.BaseMainActivity.mutedAccount; import static app.fedilab.android.activities.BaseMainActivity.mutedAccount;
import static app.fedilab.android.activities.BaseMainActivity.regex_home; import static app.fedilab.android.activities.BaseMainActivity.regex_home;
import static app.fedilab.android.activities.BaseMainActivity.regex_local; import static app.fedilab.android.activities.BaseMainActivity.regex_local;
@ -647,6 +648,9 @@ public class Helper {
editor.putString(Helper.PREF_INSTANCE, null); editor.putString(Helper.PREF_INSTANCE, null);
editor.putString(Helper.ID, null); editor.putString(Helper.ID, null);
editor.apply(); editor.apply();
Intent loginActivity = new Intent(activity, LoginActivity.class);
activity.startActivity(loginActivity);
activity.finish();
} else { } else {
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, newAccount.getToken()); editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, newAccount.getToken());
editor.putString(Helper.PREF_KEY_ID, newAccount.getId()); editor.putString(Helper.PREF_KEY_ID, newAccount.getId());
@ -1788,38 +1792,40 @@ public class Helper {
if (!accountChoice.getAvatar().startsWith("http")) if (!accountChoice.getAvatar().startsWith("http"))
accountChoice.setAvatar("https://" + accountChoice.getInstance() + accountChoice.getAvatar()); accountChoice.setAvatar("https://" + accountChoice.getInstance() + accountChoice.getAvatar());
ImageView itemIconAcc = new ImageView(activity); ImageView itemIconAcc = new ImageView(activity);
if( !activity.isFinishing()) { if( !activity.isFinishing() && isAttached) {
Glide.with(activity) try {
.asDrawable() Glide.with(activity)
.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(270))) .asDrawable()
.load(!disableGif ? accountChoice.getAvatar() : accountChoice.getAvatar_static()) .apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(270)))
.listener(new RequestListener<Drawable>() { .load(!disableGif ? accountChoice.getAvatar() : accountChoice.getAvatar_static())
.listener(new RequestListener<Drawable>() {
@Override @Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) { public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
return false; return false;
} }
@Override @Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA)
itemIconAcc.setImageResource(R.drawable.missing); itemIconAcc.setImageResource(R.drawable.missing);
else if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) else if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE)
itemIconAcc.setImageResource(R.drawable.missing_peertube); itemIconAcc.setImageResource(R.drawable.missing_peertube);
return false; return false;
} }
}) })
.into(new CustomTarget<Drawable>() { .into(new CustomTarget<Drawable>() {
@Override @Override
public void onResourceReady(@NonNull Drawable resource, Transition<? super Drawable> transition) { public void onResourceReady(@NonNull Drawable resource, Transition<? super Drawable> transition) {
itemIconAcc.setImageDrawable(resource); itemIconAcc.setImageDrawable(resource);
} }
@Override @Override
public void onLoadCleared(@Nullable Drawable placeholder) { public void onLoadCleared(@Nullable Drawable placeholder) {
} }
}); });
}catch (Exception ignored){}
} }
if (accounts.size() > 2) { if (accounts.size() > 2) {
@ -1927,27 +1933,31 @@ public class Helper {
} }
if (!urlHeader.contains("missing.png")) { if (!urlHeader.contains("missing.png")) {
ImageView backgroundImage = headerLayout.findViewById(R.id.back_ground_image); ImageView backgroundImage = headerLayout.findViewById(R.id.back_ground_image);
Glide.with(activity) if( !activity.isFinishing() && isAttached) {
.asDrawable() try {
.load(urlHeader) Glide.with(activity)
.into(new CustomTarget<Drawable>() { .asDrawable()
@Override .load(urlHeader)
public void onResourceReady(@NonNull Drawable resource, Transition<? super Drawable> transition) { .into(new CustomTarget<Drawable>() {
@Override
public void onResourceReady(@NonNull Drawable resource, Transition<? super Drawable> transition) {
backgroundImage.setImageDrawable(resource); backgroundImage.setImageDrawable(resource);
if (theme == THEME_LIGHT) { if (theme == THEME_LIGHT) {
backgroundImage.setImageAlpha(80); backgroundImage.setImageAlpha(80);
} else { } else {
backgroundImage.setImageAlpha(60); backgroundImage.setImageAlpha(60);
} }
} }
@Override @Override
public void onLoadCleared(@Nullable Drawable placeholder) { public void onLoadCleared(@Nullable Drawable placeholder) {
} }
}); });
}catch (Exception ignored){}
}
} }
} }
profilePicture.setOnClickListener(null); profilePicture.setOnClickListener(null);