mirror of
https://github.com/M66B/NetGuard.git
synced 2025-01-30 19:31:26 +00:00
Refactoring
This commit is contained in:
parent
245b006864
commit
927dfab970
4 changed files with 123 additions and 78 deletions
|
@ -25,17 +25,20 @@ import android.os.Build;
|
|||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.support.v4.app.NavUtils;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.text.util.Linkify;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
|
@ -108,41 +111,6 @@ public class ActivityPro extends AppCompatActivity {
|
|||
Linkify.addLinks(tvDev1Title, Pattern.compile(".*"), "http://www.netguard.me/#" + SKU_SUPPORT1, null, filter);
|
||||
Linkify.addLinks(tvDev2Title, Pattern.compile(".*"), "http://www.netguard.me/#" + SKU_SUPPORT2, null, filter);
|
||||
|
||||
String android_id = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
|
||||
String challenge = (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? Build.SERIAL : "O3" + android_id);
|
||||
String seed = (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? "NetGuard2" : "NetGuard3");
|
||||
|
||||
// Challenge
|
||||
TextView tvChallenge = findViewById(R.id.tvChallenge);
|
||||
tvChallenge.setText(challenge);
|
||||
|
||||
// Response
|
||||
try {
|
||||
final String response = Util.md5(challenge, seed);
|
||||
EditText etResponse = findViewById(R.id.etResponse);
|
||||
etResponse.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable) {
|
||||
if (response.equals(editable.toString().toUpperCase())) {
|
||||
IAB.setBought(SKU_DONATION, ActivityPro.this);
|
||||
updateState();
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (Throwable ex) {
|
||||
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
||||
}
|
||||
|
||||
try {
|
||||
iab = new IAB(new IAB.Delegate() {
|
||||
@Override
|
||||
|
@ -238,6 +206,13 @@ public class ActivityPro extends AppCompatActivity {
|
|||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.pro, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
|
@ -245,11 +220,71 @@ public class ActivityPro extends AppCompatActivity {
|
|||
Log.i(TAG, "Up");
|
||||
NavUtils.navigateUpFromSameTask(this);
|
||||
return true;
|
||||
case R.id.menu_challenge:
|
||||
menu_challenge();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
if (IAB.isPurchased(SKU_DONATION, this) || Util.isPlayStoreInstall(this))
|
||||
menu.removeItem(R.id.menu_challenge);
|
||||
|
||||
return super.onPrepareOptionsMenu(menu);
|
||||
}
|
||||
|
||||
private void menu_challenge() {
|
||||
LayoutInflater inflater = LayoutInflater.from(this);
|
||||
View view = inflater.inflate(R.layout.challenge, null, false);
|
||||
|
||||
final AlertDialog dialog = new AlertDialog.Builder(this)
|
||||
.setView(view)
|
||||
.setCancelable(true)
|
||||
.create();
|
||||
|
||||
String android_id = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
|
||||
String challenge = (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? Build.SERIAL : "O3" + android_id);
|
||||
String seed = (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? "NetGuard2" : "NetGuard3");
|
||||
|
||||
// Challenge
|
||||
TextView tvChallenge = view.findViewById(R.id.tvChallenge);
|
||||
tvChallenge.setText(challenge);
|
||||
|
||||
// Response
|
||||
try {
|
||||
final String response = Util.md5(challenge, seed);
|
||||
EditText etResponse = view.findViewById(R.id.etResponse);
|
||||
etResponse.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable) {
|
||||
if (response.equals(editable.toString().toUpperCase())) {
|
||||
IAB.setBought(SKU_DONATION, ActivityPro.this);
|
||||
dialog.dismiss();
|
||||
invalidateOptionsMenu();
|
||||
updateState();
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (Throwable ex) {
|
||||
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
||||
}
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
|
@ -307,7 +342,6 @@ public class ActivityPro extends AppCompatActivity {
|
|||
TextView tvAll = findViewById(R.id.tvAll);
|
||||
TextView tvDev1 = findViewById(R.id.tvDev1);
|
||||
TextView tvDev2 = findViewById(R.id.tvDev2);
|
||||
LinearLayout llChallenge = findViewById(R.id.llChallenge);
|
||||
|
||||
TextView tvLogUnavailable = findViewById(R.id.tvLogUnavailable);
|
||||
TextView tvFilterUnavailable = findViewById(R.id.tvFilterUnavailable);
|
||||
|
@ -334,9 +368,5 @@ public class ActivityPro extends AppCompatActivity {
|
|||
|
||||
tvLogUnavailable.setVisibility(can ? View.GONE : View.VISIBLE);
|
||||
tvFilterUnavailable.setVisibility(can ? View.GONE : View.VISIBLE);
|
||||
|
||||
llChallenge.setVisibility(
|
||||
IAB.isPurchased(SKU_DONATION, this) || Util.isPlayStoreInstall(this)
|
||||
? View.GONE : View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
|
46
app/src/main/res/layout/challenge.xml
Normal file
46
app/src/main/res/layout/challenge.xml
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp"
|
||||
tools:context=".ActivityPro">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/llChallenge"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/title_pro_challenge"
|
||||
android:textAppearance="@style/TextMedium" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvChallenge"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/title_pro_challenge"
|
||||
android:textAppearance="@style/TextMedium"
|
||||
android:textIsSelectable="true"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/title_pro_reponse"
|
||||
android:textAppearance="@style/TextMedium" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etResponse"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:importantForAccessibility="no"
|
||||
android:inputType="text" />
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
|
@ -418,42 +418,5 @@
|
|||
android:text="@string/title_pro_ads"
|
||||
android:textAppearance="@style/TextMedium"
|
||||
android:textStyle="italic"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/llChallenge"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/title_pro_challenge"
|
||||
android:textAppearance="@style/TextMedium"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvChallenge"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/title_pro_challenge"
|
||||
android:textAppearance="@style/TextMedium"
|
||||
android:textIsSelectable="true"
|
||||
android:textStyle="bold"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/title_pro_reponse"
|
||||
android:textAppearance="@style/TextMedium"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etResponse"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:importantForAccessibility="no"
|
||||
android:inputType="text"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
|
6
app/src/main/res/menu/pro.xml
Normal file
6
app/src/main/res/menu/pro.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:id="@+id/menu_challenge"
|
||||
android:title="@string/title_pro_challenge" />
|
||||
</menu>
|
Loading…
Reference in a new issue