Remove dependency on getUserVisibleHint

pull/156/head
M66B 6 years ago
parent db0c857e29
commit ccbd430166

@ -25,12 +25,9 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
import android.view.View;
import android.widget.ScrollView;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Lifecycle; import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleOwner;
@ -158,19 +155,6 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
return Helper.hasPermission(this, name); return Helper.hasPermission(this, name);
} }
protected View getVisibleView() {
for (Fragment fragment : getSupportFragmentManager().getFragments())
if (fragment.getUserVisibleHint()) {
View view = fragment.getView();
Log.i("Visible fragment=" + fragment.getClass().getName() + " view=" + view);
if (view != null && !(view instanceof ScrollView)) // Snackbar cannot be attached to ScrollView
return view;
}
Log.i("Visible activity=" + this.getClass().getName());
return findViewById(android.R.id.content);
}
void addBackPressedListener(final IBackPressedListener listener, LifecycleOwner owner) { void addBackPressedListener(final IBackPressedListener listener, LifecycleOwner owner) {
Log.i("Adding back listener=" + listener); Log.i("Adding back listener=" + listener);
backPressedListeners.add(listener); backPressedListeners.add(listener);

@ -29,10 +29,9 @@ import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.provider.Settings; import android.provider.Settings;
import android.util.Base64; import android.util.Base64;
import android.view.View; import android.widget.Toast;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.Lifecycle; import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleOwner;
@ -53,7 +52,6 @@ import com.android.billingclient.api.PurchasesUpdatedListener;
import com.android.billingclient.api.SkuDetails; import com.android.billingclient.api.SkuDetails;
import com.android.billingclient.api.SkuDetailsParams; import com.android.billingclient.api.SkuDetailsParams;
import com.android.billingclient.api.SkuDetailsResponseListener; import com.android.billingclient.api.SkuDetailsResponseListener;
import com.google.android.material.snackbar.Snackbar;
import java.security.KeyFactory; import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
@ -168,7 +166,7 @@ abstract class ActivityBilling extends ActivityBase implements PurchasesUpdatedL
String text = getBillingResponseText(result); String text = getBillingResponseText(result);
Log.i("IAB launch billing flow response=" + text); Log.i("IAB launch billing flow response=" + text);
if (result.getResponseCode() != BillingClient.BillingResponseCode.OK) if (result.getResponseCode() != BillingClient.BillingResponseCode.OK)
Snackbar.make(getVisibleView(), text, Snackbar.LENGTH_LONG).show(); Toast.makeText(ActivityBilling.this, text, Toast.LENGTH_LONG).show();
} else } else
Helper.view(this, this, getIntentPro()); Helper.view(this, this, getIntentPro());
} }
@ -188,19 +186,10 @@ abstract class ActivityBilling extends ActivityBase implements PurchasesUpdatedL
.putBoolean("play_store", false) .putBoolean("play_store", false)
.apply(); .apply();
Log.i("Response valid"); Log.i("Response valid");
Snackbar snackbar = Snackbar.make(getVisibleView(), R.string.title_pro_valid, Snackbar.LENGTH_LONG); Toast.makeText(ActivityBilling.this, R.string.title_pro_valid, Toast.LENGTH_LONG).show();
snackbar.setAction(R.string.title_check, new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, new FragmentPro()).addToBackStack("pro");
fragmentTransaction.commit();
}
});
snackbar.show();
} else { } else {
Log.i("Response invalid"); Log.i("Response invalid");
Snackbar.make(getVisibleView(), R.string.title_pro_invalid, Snackbar.LENGTH_LONG).show(); Toast.makeText(ActivityBilling.this, R.string.title_pro_invalid, Toast.LENGTH_LONG).show();
} }
} catch (NoSuchAlgorithmException ex) { } catch (NoSuchAlgorithmException ex) {
Log.e(ex); Log.e(ex);
@ -223,7 +212,7 @@ abstract class ActivityBilling extends ActivityBase implements PurchasesUpdatedL
backoff = 4; backoff = 4;
queryPurchases(); queryPurchases();
} else } else
Snackbar.make(getVisibleView(), text, Snackbar.LENGTH_LONG).show(); Toast.makeText(ActivityBilling.this, text, Toast.LENGTH_LONG).show();
} }
@Override @Override
@ -251,7 +240,7 @@ abstract class ActivityBilling extends ActivityBase implements PurchasesUpdatedL
if (result.getResponseCode() == BillingClient.BillingResponseCode.OK) if (result.getResponseCode() == BillingClient.BillingResponseCode.OK)
checkPurchases(purchases); checkPurchases(purchases);
else else
Snackbar.make(getVisibleView(), text, Snackbar.LENGTH_LONG).show(); Toast.makeText(ActivityBilling.this, text, Toast.LENGTH_LONG).show();
} }
private void queryPurchases() { private void queryPurchases() {
@ -262,7 +251,7 @@ abstract class ActivityBilling extends ActivityBase implements PurchasesUpdatedL
if (result.getResponseCode() == BillingClient.BillingResponseCode.OK) if (result.getResponseCode() == BillingClient.BillingResponseCode.OK)
checkPurchases(result.getPurchasesList()); checkPurchases(result.getPurchasesList());
else else
Snackbar.make(getVisibleView(), text, Snackbar.LENGTH_LONG).show(); Toast.makeText(ActivityBilling.this, text, Toast.LENGTH_LONG).show();
} }
interface IBillingListener { interface IBillingListener {
@ -337,11 +326,11 @@ abstract class ActivityBilling extends ActivityBase implements PurchasesUpdatedL
} else { } else {
Log.w("Invalid signature"); Log.w("Invalid signature");
Snackbar.make(getVisibleView(), R.string.title_pro_invalid, Snackbar.LENGTH_LONG).show(); Toast.makeText(ActivityBilling.this, R.string.title_pro_invalid, Toast.LENGTH_LONG).show();
} }
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);
Snackbar.make(getVisibleView(), ex.getMessage(), Snackbar.LENGTH_LONG).show(); Toast.makeText(ActivityBilling.this, Helper.formatThrowable(ex), Toast.LENGTH_LONG).show();
} }
editor.apply(); editor.apply();

@ -69,7 +69,6 @@ import androidx.recyclerview.widget.RecyclerView;
import com.android.colorpicker.ColorPickerDialog; import com.android.colorpicker.ColorPickerDialog;
import com.android.colorpicker.ColorPickerSwatch; import com.android.colorpicker.ColorPickerSwatch;
import com.google.android.material.snackbar.Snackbar;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
@ -689,10 +688,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalArgumentException) Toast.makeText(ActivityView.this, Helper.formatThrowable(ex), Toast.LENGTH_LONG).show();
Snackbar.make(getVisibleView(), ex.getMessage(), Snackbar.LENGTH_LONG).show();
else
Toast.makeText(ActivityView.this, ex.toString(), Toast.LENGTH_LONG).show();
} }
}.execute(this, new Bundle(), "crash:log"); }.execute(this, new Bundle(), "crash:log");
} }
@ -815,7 +811,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
if (args.getBoolean("always")) if (args.getBoolean("always"))
if (ex instanceof IllegalArgumentException || ex instanceof IOException) if (ex instanceof IllegalArgumentException || ex instanceof IOException)
Snackbar.make(getVisibleView(), ex.getMessage(), Snackbar.LENGTH_LONG).show(); Toast.makeText(ActivityView.this, ex.getMessage(), Toast.LENGTH_LONG).show();
else else
Helper.unexpectedError(ActivityView.this, ActivityView.this, ex); Helper.unexpectedError(ActivityView.this, ActivityView.this, ex);
} }
@ -996,7 +992,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalArgumentException) if (ex instanceof IllegalArgumentException)
Snackbar.make(getVisibleView(), ex.getMessage(), Snackbar.LENGTH_LONG).show(); Toast.makeText(ActivityView.this, ex.getMessage(), Toast.LENGTH_LONG).show();
else else
Toast.makeText(ActivityView.this, ex.toString(), Toast.LENGTH_LONG).show(); Toast.makeText(ActivityView.this, ex.toString(), Toast.LENGTH_LONG).show();
} }
@ -1120,7 +1116,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
create.setType("*/*"); create.setType("*/*");
create.putExtra(Intent.EXTRA_TITLE, "email.eml"); create.putExtra(Intent.EXTRA_TITLE, "email.eml");
if (create.resolveActivity(getPackageManager()) == null) if (create.resolveActivity(getPackageManager()) == null)
Snackbar.make(getVisibleView(), R.string.title_no_saf, Snackbar.LENGTH_LONG).show(); Toast.makeText(ActivityView.this, R.string.title_no_saf, Toast.LENGTH_LONG).show();
else else
startActivityForResult(Helper.getChooser(this, create), REQUEST_RAW); startActivityForResult(Helper.getChooser(this, create), REQUEST_RAW);
} }
@ -1170,7 +1166,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
create.setType(intent.getStringExtra("type")); create.setType(intent.getStringExtra("type"));
create.putExtra(Intent.EXTRA_TITLE, intent.getStringExtra("name")); create.putExtra(Intent.EXTRA_TITLE, intent.getStringExtra("name"));
if (create.resolveActivity(getPackageManager()) == null) if (create.resolveActivity(getPackageManager()) == null)
Snackbar.make(getVisibleView(), R.string.title_no_saf, Snackbar.LENGTH_LONG).show(); Toast.makeText(ActivityView.this, R.string.title_no_saf, Toast.LENGTH_LONG).show();
else else
startActivityForResult(Helper.getChooser(this, create), REQUEST_ATTACHMENT); startActivityForResult(Helper.getChooser(this, create), REQUEST_ATTACHMENT);
} }
@ -1180,7 +1176,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
Intent tree = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); Intent tree = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
//tree.putExtra("android.content.extra.SHOW_ADVANCED", true); //tree.putExtra("android.content.extra.SHOW_ADVANCED", true);
if (tree.resolveActivity(getPackageManager()) == null) if (tree.resolveActivity(getPackageManager()) == null)
Snackbar.make(getVisibleView(), R.string.title_no_saf, Snackbar.LENGTH_LONG).show(); Toast.makeText(ActivityView.this, R.string.title_no_saf, Toast.LENGTH_LONG).show();
else else
startActivityForResult(Helper.getChooser(this, tree), REQUEST_ATTACHMENTS); startActivityForResult(Helper.getChooser(this, tree), REQUEST_ATTACHMENTS);
} }
@ -1312,17 +1308,8 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
data.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY); data.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);
decrypt(data, intent.getLongExtra("id", -1)); decrypt(data, intent.getLongExtra("id", -1));
} else { } else
Snackbar snackbar = Snackbar.make(getVisibleView(), R.string.title_no_openpgp, Snackbar.LENGTH_LONG); Toast.makeText(ActivityView.this, R.string.title_no_openpgp, Toast.LENGTH_LONG).show();
if (Helper.getIntentOpenKeychain().resolveActivity(getPackageManager()) != null)
snackbar.setAction(R.string.title_fix, new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(Helper.getIntentOpenKeychain());
}
});
snackbar.show();
}
} }
private void onShowPro(Intent intent) { private void onShowPro(Intent intent) {
@ -1471,7 +1458,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
resid = R.string.title_signature_valid; resid = R.string.title_signature_valid;
else else
resid = R.string.title_signature_invalid; resid = R.string.title_signature_invalid;
Snackbar.make(getVisibleView(), resid, Snackbar.LENGTH_LONG).show(); Toast.makeText(ActivityView.this, resid, Toast.LENGTH_LONG).show();
break; break;
@ -1505,7 +1492,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalArgumentException) if (ex instanceof IllegalArgumentException)
Snackbar.make(getVisibleView(), ex.getMessage(), Snackbar.LENGTH_LONG).show(); Toast.makeText(ActivityView.this, ex.getMessage(), Toast.LENGTH_LONG).show();
else else
Helper.unexpectedError(ActivityView.this, ActivityView.this, ex); Helper.unexpectedError(ActivityView.this, ActivityView.this, ex);
} }
@ -1600,7 +1587,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalArgumentException) if (ex instanceof IllegalArgumentException)
Snackbar.make(getVisibleView(), ex.getMessage(), Snackbar.LENGTH_LONG).show(); Toast.makeText(ActivityView.this, ex.getMessage(), Toast.LENGTH_LONG).show();
else else
Helper.unexpectedError(ActivityView.this, ActivityView.this, ex); Helper.unexpectedError(ActivityView.this, ActivityView.this, ex);
} }
@ -1673,7 +1660,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalArgumentException) if (ex instanceof IllegalArgumentException)
Snackbar.make(getVisibleView(), ex.getMessage(), Snackbar.LENGTH_LONG).show(); Toast.makeText(ActivityView.this, ex.getMessage(), Toast.LENGTH_LONG).show();
else else
Helper.unexpectedError(ActivityView.this, ActivityView.this, ex); Helper.unexpectedError(ActivityView.this, ActivityView.this, ex);
} }

Loading…
Cancel
Save