mirror of https://github.com/M66B/NetGuard.git
Rely on Play store refunds for trials
This commit is contained in:
parent
642ff08405
commit
8ac70110b1
|
@ -55,9 +55,6 @@ import android.widget.CompoundButton;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class ActivityMain extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
@ -92,31 +89,6 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
}
|
||||
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
// Pro trial
|
||||
long now = new Date().getTime();
|
||||
long trial = IAB.getTrialEnd(this);
|
||||
if (now < trial) {
|
||||
if (!IAB.isPurchased(ActivityPro.SKU_SELECT, false, this) ||
|
||||
!IAB.isPurchased(ActivityPro.SKU_NOTIFY, false, this) ||
|
||||
!IAB.isPurchased(ActivityPro.SKU_THEME, false, this) ||
|
||||
!IAB.isPurchased(ActivityPro.SKU_SPEED, false, this) ||
|
||||
!IAB.isPurchased(ActivityPro.SKU_BACKUP, false, this)) {
|
||||
DateFormat df = SimpleDateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
|
||||
Toast.makeText(this, getString(R.string.title_pro_trial_until, df.format(trial)), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} else {
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putBoolean("show_user", true);
|
||||
editor.putBoolean("show_system", prefs.getBoolean("manage_system", false));
|
||||
editor.putBoolean("show_nointernet", true);
|
||||
editor.putBoolean("show_disabled", true);
|
||||
editor.putString("sort", "name");
|
||||
editor.putBoolean("dark_theme", false);
|
||||
editor.putBoolean("show_stats", false);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
setTheme(prefs.getBoolean("dark_theme", false) ? R.style.AppThemeDark : R.style.AppTheme);
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -496,7 +468,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
if (TextUtils.isEmpty(query) || IAB.isPurchased(ActivityPro.SKU_SELECT, true, ActivityMain.this)) {
|
||||
if (TextUtils.isEmpty(query) || IAB.isPurchased(ActivityPro.SKU_SELECT, ActivityMain.this)) {
|
||||
if (adapter != null)
|
||||
adapter.getFilter().filter(query);
|
||||
} else
|
||||
|
@ -506,7 +478,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
if (TextUtils.isEmpty(newText) || IAB.isPurchased(ActivityPro.SKU_SELECT, true, ActivityMain.this)) {
|
||||
if (TextUtils.isEmpty(newText) || IAB.isPurchased(ActivityPro.SKU_SELECT, ActivityMain.this)) {
|
||||
if (adapter != null)
|
||||
adapter.getFilter().filter(newText);
|
||||
} else
|
||||
|
@ -565,7 +537,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_app_user:
|
||||
if (IAB.isPurchased(ActivityPro.SKU_SELECT, true, ActivityMain.this)) {
|
||||
if (IAB.isPurchased(ActivityPro.SKU_SELECT, ActivityMain.this)) {
|
||||
item.setChecked(!item.isChecked());
|
||||
prefs.edit().putBoolean("show_user", item.isChecked()).apply();
|
||||
} else
|
||||
|
@ -574,7 +546,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
|
||||
case R.id.menu_app_system:
|
||||
boolean manage = prefs.getBoolean("manage_system", false);
|
||||
if (manage == !item.isChecked() || IAB.isPurchased(ActivityPro.SKU_SELECT, true, ActivityMain.this)) {
|
||||
if (manage == !item.isChecked() || IAB.isPurchased(ActivityPro.SKU_SELECT, ActivityMain.this)) {
|
||||
item.setChecked(!item.isChecked());
|
||||
prefs.edit().putBoolean("show_system", item.isChecked()).apply();
|
||||
} else
|
||||
|
@ -582,7 +554,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
return true;
|
||||
|
||||
case R.id.menu_app_nointernet:
|
||||
if (IAB.isPurchased(ActivityPro.SKU_SELECT, true, ActivityMain.this)) {
|
||||
if (IAB.isPurchased(ActivityPro.SKU_SELECT, ActivityMain.this)) {
|
||||
item.setChecked(!item.isChecked());
|
||||
prefs.edit().putBoolean("show_nointernet", item.isChecked()).apply();
|
||||
} else
|
||||
|
@ -590,7 +562,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
return true;
|
||||
|
||||
case R.id.menu_app_disabled:
|
||||
if (IAB.isPurchased(ActivityPro.SKU_SELECT, true, ActivityMain.this)) {
|
||||
if (IAB.isPurchased(ActivityPro.SKU_SELECT, ActivityMain.this)) {
|
||||
item.setChecked(!item.isChecked());
|
||||
prefs.edit().putBoolean("show_disabled", item.isChecked()).apply();
|
||||
} else
|
||||
|
@ -603,7 +575,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
return true;
|
||||
|
||||
case R.id.menu_sort_data:
|
||||
if (IAB.isPurchased(ActivityPro.SKU_SELECT, true, ActivityMain.this)) {
|
||||
if (IAB.isPurchased(ActivityPro.SKU_SELECT, ActivityMain.this)) {
|
||||
item.setChecked(true);
|
||||
prefs.edit().putString("sort", "data").apply();
|
||||
} else
|
||||
|
|
|
@ -37,10 +37,6 @@ import android.widget.EditText;
|
|||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class ActivityPro extends AppCompatActivity {
|
||||
private static final String TAG = "NetGuard.Pro";
|
||||
|
||||
|
@ -161,17 +157,6 @@ public class ActivityPro extends AppCompatActivity {
|
|||
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
||||
Util.sendCrashReport(ex, ActivityPro.this);
|
||||
}
|
||||
|
||||
// Trial
|
||||
long now = new Date().getTime();
|
||||
long trial = IAB.getTrialEnd(this);
|
||||
TextView tvTrial = (TextView) findViewById(R.id.tvTrial);
|
||||
if (now < trial) {
|
||||
DateFormat df = SimpleDateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
|
||||
tvTrial.setText(getString(R.string.title_pro_trial_until, df.format(trial)));
|
||||
} else
|
||||
tvTrial.setText(getString(R.string.title_pro_trial_ended));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -231,18 +216,18 @@ public class ActivityPro extends AppCompatActivity {
|
|||
TextView tvBackup = (TextView) findViewById(R.id.tvBackup);
|
||||
LinearLayout llChallenge = (LinearLayout) findViewById(R.id.llChallenge);
|
||||
|
||||
btnSelect.setVisibility(IAB.isPurchased(SKU_SELECT, false, this) ? View.GONE : View.VISIBLE);
|
||||
btnNotify.setVisibility(IAB.isPurchased(SKU_NOTIFY, false, this) ? View.GONE : View.VISIBLE);
|
||||
btnTheme.setVisibility(IAB.isPurchased(SKU_THEME, false, this) ? View.GONE : View.VISIBLE);
|
||||
btnSpeed.setVisibility(IAB.isPurchased(SKU_SPEED, false, this) ? View.GONE : View.VISIBLE);
|
||||
btnBackup.setVisibility(IAB.isPurchased(SKU_BACKUP, false, this) ? View.GONE : View.VISIBLE);
|
||||
btnSelect.setVisibility(IAB.isPurchased(SKU_SELECT, this) ? View.GONE : View.VISIBLE);
|
||||
btnNotify.setVisibility(IAB.isPurchased(SKU_NOTIFY, this) ? View.GONE : View.VISIBLE);
|
||||
btnTheme.setVisibility(IAB.isPurchased(SKU_THEME, this) ? View.GONE : View.VISIBLE);
|
||||
btnSpeed.setVisibility(IAB.isPurchased(SKU_SPEED, this) ? View.GONE : View.VISIBLE);
|
||||
btnBackup.setVisibility(IAB.isPurchased(SKU_BACKUP, this) ? View.GONE : View.VISIBLE);
|
||||
|
||||
tvSelect.setVisibility(IAB.isPurchased(SKU_SELECT, false, this) ? View.VISIBLE : View.GONE);
|
||||
tvNotify.setVisibility(IAB.isPurchased(SKU_NOTIFY, false, this) ? View.VISIBLE : View.GONE);
|
||||
tvTheme.setVisibility(IAB.isPurchased(SKU_THEME, false, this) ? View.VISIBLE : View.GONE);
|
||||
tvSpeed.setVisibility(IAB.isPurchased(SKU_SPEED, false, this) ? View.VISIBLE : View.GONE);
|
||||
tvBackup.setVisibility(IAB.isPurchased(SKU_BACKUP, false, this) ? View.VISIBLE : View.GONE);
|
||||
tvSelect.setVisibility(IAB.isPurchased(SKU_SELECT, this) ? View.VISIBLE : View.GONE);
|
||||
tvNotify.setVisibility(IAB.isPurchased(SKU_NOTIFY, this) ? View.VISIBLE : View.GONE);
|
||||
tvTheme.setVisibility(IAB.isPurchased(SKU_THEME, this) ? View.VISIBLE : View.GONE);
|
||||
tvSpeed.setVisibility(IAB.isPurchased(SKU_SPEED, this) ? View.VISIBLE : View.GONE);
|
||||
tvBackup.setVisibility(IAB.isPurchased(SKU_BACKUP, this) ? View.VISIBLE : View.GONE);
|
||||
|
||||
llChallenge.setVisibility(IAB.isPurchased(SKU_DONATION, false, this) ? View.GONE : View.VISIBLE);
|
||||
llChallenge.setVisibility(IAB.isPurchased(SKU_DONATION, this) ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -141,7 +141,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
|
|||
pref_export.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
if (IAB.isPurchased(ActivityPro.SKU_BACKUP, true, ActivitySettings.this))
|
||||
if (IAB.isPurchased(ActivityPro.SKU_BACKUP, ActivitySettings.this))
|
||||
startActivityForResult(getIntentCreateDocument(), ActivitySettings.REQUEST_EXPORT);
|
||||
else
|
||||
startActivity(new Intent(ActivitySettings.this, ActivityPro.class));
|
||||
|
@ -155,7 +155,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
|
|||
pref_import.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
if (IAB.isPurchased(ActivityPro.SKU_BACKUP, true, ActivitySettings.this))
|
||||
if (IAB.isPurchased(ActivityPro.SKU_BACKUP, ActivitySettings.this))
|
||||
startActivityForResult(getIntentOpenDocument(), ActivitySettings.REQUEST_IMPORT);
|
||||
else
|
||||
startActivity(new Intent(ActivitySettings.this, ActivityPro.class));
|
||||
|
@ -284,14 +284,14 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
|
|||
public void onSharedPreferenceChanged(SharedPreferences prefs, String name) {
|
||||
// Pro features
|
||||
if ("dark_theme".equals(name)) {
|
||||
if (prefs.getBoolean(name, false) && !IAB.isPurchased(ActivityPro.SKU_THEME, true, this)) {
|
||||
if (prefs.getBoolean(name, false) && !IAB.isPurchased(ActivityPro.SKU_THEME, this)) {
|
||||
prefs.edit().putBoolean(name, false).apply();
|
||||
((SwitchPreference) getPreferenceScreen().findPreference(name)).setChecked(false);
|
||||
startActivity(new Intent(this, ActivityPro.class));
|
||||
return;
|
||||
}
|
||||
} else if ("show_stats".equals(name)) {
|
||||
if (prefs.getBoolean(name, false) && !IAB.isPurchased(ActivityPro.SKU_SPEED, true, this)) {
|
||||
if (prefs.getBoolean(name, false) && !IAB.isPurchased(ActivityPro.SKU_SPEED, this)) {
|
||||
prefs.edit().putBoolean(name, false).apply();
|
||||
((SwitchPreference) getPreferenceScreen().findPreference(name)).setChecked(false);
|
||||
startActivity(new Intent(this, ActivityPro.class));
|
||||
|
@ -736,13 +736,13 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
|
|||
"show_nointernet".equals(key) ||
|
||||
"show_disabled".equals(key) ||
|
||||
"sort".equals(key)) {
|
||||
if (!IAB.isPurchased(ActivityPro.SKU_SELECT, true, context))
|
||||
if (!IAB.isPurchased(ActivityPro.SKU_SELECT, context))
|
||||
return;
|
||||
} else if ("dark_theme".equals(key)) {
|
||||
if (!IAB.isPurchased(ActivityPro.SKU_THEME, true, context))
|
||||
if (!IAB.isPurchased(ActivityPro.SKU_THEME, context))
|
||||
return;
|
||||
} else if ("show_stats".equals(key)) {
|
||||
if (!IAB.isPurchased(ActivityPro.SKU_SPEED, true, context))
|
||||
if (!IAB.isPurchased(ActivityPro.SKU_SPEED, context))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,6 @@ import org.json.JSONException;
|
|||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class IAB implements ServiceConnection {
|
||||
|
@ -47,7 +46,6 @@ public class IAB implements ServiceConnection {
|
|||
private IInAppBillingService service = null;
|
||||
|
||||
private static final int IAB_VERSION = 3;
|
||||
private static final long TRIAL_DURATION = 3 * 24 * 3600 * 1000L;
|
||||
|
||||
public interface Delegate {
|
||||
void onReady(IAB iab);
|
||||
|
@ -169,20 +167,9 @@ public class IAB implements ServiceConnection {
|
|||
prefs.edit().putBoolean(sku, true).apply();
|
||||
}
|
||||
|
||||
public static long getTrialEnd(Context context) {
|
||||
public static boolean isPurchased(String sku, Context context) {
|
||||
SharedPreferences prefs = context.getSharedPreferences("IAB", Context.MODE_PRIVATE);
|
||||
long until = prefs.getLong("trial", 0);
|
||||
if (until == 0) {
|
||||
until = new Date().getTime() + TRIAL_DURATION;
|
||||
}
|
||||
return until;
|
||||
}
|
||||
|
||||
public static boolean isPurchased(String sku, boolean trial, Context context) {
|
||||
long now = new Date().getTime();
|
||||
long end = IAB.getTrialEnd(context);
|
||||
SharedPreferences prefs = context.getSharedPreferences("IAB", Context.MODE_PRIVATE);
|
||||
return ((trial && now < end) || prefs.getBoolean(sku, false) || prefs.getBoolean(ActivityPro.SKU_DONATION, false));
|
||||
return (prefs.getBoolean(sku, false) || prefs.getBoolean(ActivityPro.SKU_DONATION, false));
|
||||
}
|
||||
|
||||
public static String getResult(int responseCode) {
|
||||
|
|
|
@ -49,7 +49,7 @@ public class Receiver extends BroadcastReceiver {
|
|||
// Application added
|
||||
if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
|
||||
// Show notification
|
||||
if (IAB.isPurchased(ActivityPro.SKU_NOTIFY, true, context)) {
|
||||
if (IAB.isPurchased(ActivityPro.SKU_NOTIFY, context)) {
|
||||
int uid = intent.getIntExtra(Intent.EXTRA_UID, 0);
|
||||
notifyApplication(uid, context);
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ public class Receiver extends BroadcastReceiver {
|
|||
|
||||
// Build notification
|
||||
Intent main = new Intent(context, ActivityMain.class);
|
||||
if (IAB.isPurchased(ActivityPro.SKU_SELECT, true, context))
|
||||
if (IAB.isPurchased(ActivityPro.SKU_SELECT, context))
|
||||
main.putExtra(ActivityMain.EXTRA_SEARCH, name);
|
||||
PendingIntent pi = PendingIntent.getActivity(context, 999, main, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
|
|
|
@ -235,13 +235,6 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTrial"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Medium" />
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue