Skip to content

Commit

Permalink
fix crash
Browse files Browse the repository at this point in the history
  • Loading branch information
j4velin committed Aug 23, 2019
1 parent edd1bbf commit bfb4332
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
package="de.j4velin.wifiAutoOff"
xmlns:android="http://schemas.android.com/apk/res/android"
android:installLocation="internalOnly"
android:versionCode="1840"
android:versionName="1.8.4">
android:versionCode="1850"
android:versionName="1.8.5">

<uses-sdk
android:minSdkVersion="14"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ public int onStartCommand(Intent intent, int flags, int startId) {
registerReceiver(screenOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
registerReceiver(RECEIVER, new IntentFilter(Intent.ACTION_USER_PRESENT));
} else if (screenOffReceiver != null) {
unregisterReceiver(screenOffReceiver);
try {
unregisterReceiver(screenOffReceiver);
} catch (Exception e) {
// ignore
}
screenOffReceiver = null;
}
}
Expand Down
52 changes: 25 additions & 27 deletions src/play/java/de/j4velin/wifiAutoOff/Locations.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.provider.Settings;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.PermissionChecker;
Expand Down Expand Up @@ -61,8 +60,13 @@
public class Locations extends AppCompatActivity {

private final static int REQUEST_LOCATION = 1, REQUEST_BUY = 3, REQUEST_PERMISSIONS = 4;
private final static String SKU = "de.j4velin.wifiautomatic.billing.pro";

private static boolean PREMIUM_ENABLED = false;
private IInAppBillingService mService;
private RecyclerView.Adapter mAdapter;
private RecyclerView mRecyclerView;
private List<Location> locations;
private final ServiceConnection mServiceConn = new ServiceConnection() {
@Override
public void onServiceDisconnected(final ComponentName name) {
Expand All @@ -75,27 +79,24 @@ public void onServiceConnected(final ComponentName name, final IBinder service)
try {
Bundle ownedItems = mService.getPurchases(3, getPackageName(), "inapp", null);
if (ownedItems.getInt("RESPONSE_CODE") == 0) {
PREMIUM_ENABLED =
ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST") != null &&
ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST")
.contains("de.j4velin.wifiautomatic.billing.pro");
getSharedPreferences("settings", Context.MODE_PRIVATE).edit()
.putBoolean("pro", PREMIUM_ENABLED).commit();
List<String> items = ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
for (String item : items) {
if (BuildConfig.DEBUG) Logger.log(item);
final JSONObject jo = new JSONObject(item);
if (jo.getString("productId").equals(SKU)) {
PREMIUM_ENABLED = jo.getInt("purchaseState") == 0;
getSharedPreferences("settings", Context.MODE_PRIVATE).edit()
.putBoolean("pro", PREMIUM_ENABLED).apply();
break;
}
}
}
} catch (RemoteException e) {
Toast.makeText(Locations.this, e.getClass().getName() + ": " + e.getMessage(),
Toast.LENGTH_LONG).show();
e.printStackTrace();
} catch (Exception e) {
if (BuildConfig.DEBUG) Logger.log(e);
}
}
};

private static boolean PREMIUM_ENABLED = false;
private RecyclerView.Adapter mAdapter;
private RecyclerView mRecyclerView;

private List<Location> locations;

@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -120,8 +121,7 @@ public void onClick(final View v) {
public void onClick(final DialogInterface dialog, int which) {
try {
Bundle buyIntentBundle =
mService.getBuyIntent(3, getPackageName(),
"de.j4velin.wifiautomatic.billing.pro",
mService.getBuyIntent(3, getPackageName(), SKU,
"inapp", getPackageName());
if (buyIntentBundle.getInt("RESPONSE_CODE") == 0) {
PendingIntent pendingIntent =
Expand All @@ -135,7 +135,6 @@ public void onClick(final DialogInterface dialog, int which) {
Toast.makeText(Locations.this,
e.getClass().getName() + ": " + e.getMessage(),
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
dialog.dismiss();
}
Expand Down Expand Up @@ -220,10 +219,10 @@ public void afterTextChanged(final Editable s) {
public void onClick(final View v) {
try {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://j4velin.de/faq/index.php?app=wa")));
Uri.parse("https://j4velin.de/faq/index.php?app=wa")));
} catch (ActivityNotFoundException anf) {
Toast.makeText(Locations.this,
"No browser found to load http://j4velin.de/faq/index.php?app=wa",
"No browser found to load https://j4velin.de/faq/index.php?app=wa",
Toast.LENGTH_LONG).show();
}
}
Expand Down Expand Up @@ -316,11 +315,10 @@ protected void onActivityResult(int requestCode, int resultCode, final Intent da
if (data.getIntExtra("RESPONSE_CODE", 0) == 0) {
try {
JSONObject jo = new JSONObject(data.getStringExtra("INAPP_PURCHASE_DATA"));
PREMIUM_ENABLED = jo.getString("productId")
.equals("de.j4velin.wifiautomatic.billing.pro") &&
PREMIUM_ENABLED = jo.getString("productId").equals(SKU) &&
jo.getString("developerPayload").equals(getPackageName());
getSharedPreferences("settings", Context.MODE_PRIVATE).edit()
.putBoolean("pro", PREMIUM_ENABLED).commit();
.putBoolean("pro", PREMIUM_ENABLED).apply();
if (PREMIUM_ENABLED) {
Toast.makeText(this, "Thank you!", Toast.LENGTH_SHORT).show();
}
Expand Down Expand Up @@ -411,8 +409,8 @@ public class LocationHolder extends RecyclerView.ViewHolder {

public LocationHolder(final View v) {
super(v);
text = (TextView) v.findViewById(R.id.text);
subtext = (TextView) v.findViewById(R.id.subtext);
text = v.findViewById(R.id.text);
subtext = v.findViewById(R.id.subtext);
delete = v.findViewById(R.id.delete);
}
}
Expand Down

0 comments on commit bfb4332

Please sign in to comment.