Skip to content

Commit

Permalink
(#777) Yet another check to (hopefully) fix stupid popup window excep…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
K1rakishou committed Mar 6, 2020
1 parent 90ba1dd commit b7efd39
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 b7efd39

Please sign in to comment.