1
0
Fork 0
mirror of https://github.com/M66B/NetGuard.git synced 2025-01-03 13:54:09 +00:00

Added pro feature to support development

This commit is contained in:
M66B 2016-07-23 10:07:39 +02:00
parent d9874759e5
commit 567e4f53f6
4 changed files with 64 additions and 1 deletions

View file

@ -54,6 +54,7 @@ public class ActivityPro extends AppCompatActivity {
private static final int SKU_SPEED_ID = 4;
private static final int SKU_THEME_ID = 5;
private static final int SKU_PRO1_ID = 6;
private static final int SKU_SUPPORT1_ID = 7;
public static final String SKU_LOG = "log";
public static final String SKU_FILTER = "filter";
@ -61,6 +62,7 @@ public class ActivityPro extends AppCompatActivity {
public static final String SKU_SPEED = "speed";
public static final String SKU_THEME = "theme";
public static final String SKU_PRO1 = "pro1";
public static final String SKU_SUPPORT1 = "support1";
public static final String SKU_DONATION = "donation";
@Override
@ -84,6 +86,7 @@ public class ActivityPro extends AppCompatActivity {
TextView tvSpeedTitle = (TextView) findViewById(R.id.tvSpeedTitle);
TextView tvThemeTitle = (TextView) findViewById(R.id.tvThemeTitle);
TextView tvAllTitle = (TextView) findViewById(R.id.tvAllTitle);
TextView tvDevTitle = (TextView) findViewById(R.id.tvDevTitle);
Linkify.TransformFilter filter = new Linkify.TransformFilter() {
@Override
@ -98,6 +101,7 @@ public class ActivityPro extends AppCompatActivity {
Linkify.addLinks(tvSpeedTitle, Pattern.compile(".*"), "http://www.netguard.me/#" + SKU_SPEED, null, filter);
Linkify.addLinks(tvThemeTitle, Pattern.compile(".*"), "http://www.netguard.me/#" + SKU_THEME, null, filter);
Linkify.addLinks(tvAllTitle, Pattern.compile(".*"), "http://www.netguard.me/#" + SKU_PRO1, null, filter);
Linkify.addLinks(tvDevTitle, Pattern.compile(".*"), "http://www.netguard.me/#" + SKU_SUPPORT1, null, filter);
// Challenge
TextView tvChallenge = (TextView) findViewById(R.id.tvChallenge);
@ -145,6 +149,7 @@ public class ActivityPro extends AppCompatActivity {
final Button btnSpeed = (Button) findViewById(R.id.btnSpeed);
final Button btnTheme = (Button) findViewById(R.id.btnTheme);
final Button btnAll = (Button) findViewById(R.id.btnAll);
final Button btnDev = (Button) findViewById(R.id.btnDev);
View.OnClickListener listener = new View.OnClickListener() {
@Override
@ -170,6 +175,9 @@ public class ActivityPro extends AppCompatActivity {
} else if (view == btnAll) {
id = SKU_PRO1_ID;
pi = iab.getBuyIntent(SKU_PRO1);
} else if (view == btnDev) {
id = SKU_SUPPORT1_ID;
pi = iab.getBuyIntent(SKU_SUPPORT1);
}
if (id > 0 && pi != null)
@ -186,6 +194,7 @@ public class ActivityPro extends AppCompatActivity {
btnSpeed.setOnClickListener(listener);
btnTheme.setOnClickListener(listener);
btnAll.setOnClickListener(listener);
btnDev.setOnClickListener(listener);
btnLog.setEnabled(true);
btnFilter.setEnabled(true);
@ -193,9 +202,11 @@ public class ActivityPro extends AppCompatActivity {
btnSpeed.setEnabled(true);
btnTheme.setEnabled(true);
btnAll.setEnabled(true);
btnDev.setEnabled(true);
} catch (Throwable ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
Util.sendCrashReport(ex, ActivityPro.this);
}
}
}, this);
@ -252,6 +263,10 @@ public class ActivityPro extends AppCompatActivity {
IAB.setBought(SKU_PRO1, this);
updateState();
break;
case SKU_SUPPORT1_ID:
IAB.setBought(SKU_SUPPORT1, this);
updateState();
break;
}
}
}
@ -263,12 +278,14 @@ public class ActivityPro extends AppCompatActivity {
Button btnSpeed = (Button) findViewById(R.id.btnSpeed);
Button btnTheme = (Button) findViewById(R.id.btnTheme);
Button btnAll = (Button) findViewById(R.id.btnAll);
Button btnDev = (Button) findViewById(R.id.btnDev);
TextView tvLog = (TextView) findViewById(R.id.tvLog);
TextView tvFilter = (TextView) findViewById(R.id.tvFilter);
TextView tvNotify = (TextView) findViewById(R.id.tvNotify);
TextView tvSpeed = (TextView) findViewById(R.id.tvSpeed);
TextView tvTheme = (TextView) findViewById(R.id.tvTheme);
TextView tvAll = (TextView) findViewById(R.id.tvAll);
TextView tvDev = (TextView) findViewById(R.id.tvDev);
LinearLayout llChallenge = (LinearLayout) findViewById(R.id.llChallenge);
btnLog.setVisibility(IAB.isPurchased(SKU_LOG, this) ? View.GONE : View.VISIBLE);
@ -277,6 +294,7 @@ public class ActivityPro extends AppCompatActivity {
btnSpeed.setVisibility(IAB.isPurchased(SKU_SPEED, this) ? View.GONE : View.VISIBLE);
btnTheme.setVisibility(IAB.isPurchased(SKU_THEME, this) ? View.GONE : View.VISIBLE);
btnAll.setVisibility(IAB.isPurchased(SKU_PRO1, this) ? View.GONE : View.VISIBLE);
btnDev.setVisibility(IAB.isPurchased(SKU_SUPPORT1, this) ? View.GONE : View.VISIBLE);
tvLog.setVisibility(IAB.isPurchased(SKU_LOG, this) ? View.VISIBLE : View.GONE);
tvFilter.setVisibility(IAB.isPurchased(SKU_FILTER, this) ? View.VISIBLE : View.GONE);
@ -284,6 +302,7 @@ public class ActivityPro extends AppCompatActivity {
tvSpeed.setVisibility(IAB.isPurchased(SKU_SPEED, this) ? View.VISIBLE : View.GONE);
tvTheme.setVisibility(IAB.isPurchased(SKU_THEME, this) ? View.VISIBLE : View.GONE);
tvAll.setVisibility(IAB.isPurchased(SKU_PRO1, this) ? View.VISIBLE : View.GONE);
tvDev.setVisibility(IAB.isPurchased(SKU_SUPPORT1, this) ? View.VISIBLE : View.GONE);
llChallenge.setVisibility(
IAB.isPurchased(SKU_DONATION, this) || Util.isPlayStoreInstall(this)

View file

@ -170,9 +170,14 @@ public class IAB implements ServiceConnection {
}
public static boolean isPurchased(String sku, Context context) {
SharedPreferences prefs = context.getSharedPreferences("IAB", Context.MODE_PRIVATE);
if (ActivityPro.SKU_SUPPORT1.equals(sku))
return prefs.getBoolean(sku, false);
if (Util.isDebuggable(context) || Util.getSelfVersionName(context).contains("beta"))
return true;
SharedPreferences prefs = context.getSharedPreferences("IAB", Context.MODE_PRIVATE);
return (prefs.getBoolean(sku, false) ||
prefs.getBoolean(ActivityPro.SKU_PRO1, false) ||
prefs.getBoolean(ActivityPro.SKU_DONATION, false));

View file

@ -246,6 +246,44 @@
android:visibility="gone" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:orientation="horizontal">
<TextView
android:id="@+id/tvDevTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="2"
android:text="@string/title_pro_dev"
android:textAppearance="@style/TextSmall" />
<Button
android:id="@+id/btnDev"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_weight="1"
android:enabled="false"
android:text="@string/title_pro_buy"
android:visibility="gone" />
<TextView
android:id="@+id/tvDev"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="@string/title_pro_bought"
android:textAppearance="@style/TextMedium"
android:textStyle="bold"
android:visibility="gone" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View file

@ -234,6 +234,7 @@ Your internet traffic is not being sent to a remote VPN server.</string>
<string name="title_pro_speed">Network speed graph notification</string>
<string name="title_pro_theme">Appearance (theme, colors)</string>
<string name="title_pro_all">All above pro features</string>
<string name="title_pro_dev">Support development</string>
<string name="title_pro_buy">Buy</string>
<string name="title_pro_bought">Enabled</string>
<string name="title_pro_details">Tap on the title for more information</string>