Skip to content

Commit

Permalink
Merge pull request #805 from Adamantcheese/(#777)-yet-another-check-t…
Browse files Browse the repository at this point in the history
…o-fix-popup-exception

(#777) Yet another check to (hopefully) fix stupid popup window exceptions
  • Loading branch information
Adamantcheese authored Mar 7, 2020
2 parents 7c5f359 + b7efd39 commit 4a548fb
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
import android.widget.PopupWindow;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.github.adamantcheese.chan.R;
import com.github.adamantcheese.chan.StartActivity;
import com.github.adamantcheese.chan.utils.BackgroundUtils;

import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
Expand All @@ -53,6 +57,8 @@ public static HintPopup show(
}

private PopupWindow popupWindow;
@Nullable
private Context context;
private ViewGroup popupView;
private final View anchor;
private final int offsetX;
Expand All @@ -64,13 +70,14 @@ public static HintPopup show(
private boolean wiggle = false;

public HintPopup(
Context context,
@NonNull Context context,
final View anchor,
final String text,
final int offsetX,
final int offsetY,
final boolean top
) {
this.context = context;
this.anchor = anchor;
this.offsetX = offsetX;
this.offsetY = offsetY;
Expand All @@ -94,6 +101,17 @@ private void createView(Context context, String text) {

public void show() {
runOnMainThread(() -> {
if (context == null) {
return;
}

if (context instanceof StartActivity) {
if (((StartActivity) context).isFinishing()) {
// Activity.finish() was called we cannot show the popup now.
return;
}
}

if (!dismissed && BackgroundUtils.isInForeground()) {
popupView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
int xoff = -popupView.getMeasuredWidth() + offsetX - dp(2) + (centered ? 0 : anchor.getWidth());
Expand All @@ -120,5 +138,6 @@ public void wiggle() {
public void dismiss() {
popupWindow.dismiss();
dismissed = true;
context = null;
}
}

0 comments on commit 4a548fb

Please sign in to comment.