Fixing bug SELECTED_HOST/PORT not set, adding the option

to press a lot of times a button to speed up the proxy
startup in poor version.
This commit is contained in:
sergiotarxz 2024-08-06 20:04:49 +02:00
parent b89d1ae990
commit 204e8cef5d
2 changed files with 34 additions and 16 deletions

View File

@ -48,32 +48,36 @@ public class CountDownStartProxy extends AppCompatActivity {
Timer timer; Timer timer;
int messageNumber = 0; int messageNumber = 0;
static AppCompatActivity activity; static AppCompatActivity activity;
private volatile int clicks;
@Override @Override
protected void onStop() { protected void onStop() {
super.onStop(); super.onStop();
timer.cancel(); timer.cancel();
} }
Runnable onSecondPass = new Runnable() {
@Override
public void run() {
seconds--;
if (seconds < 0) {
Intent intent = new Intent(CountDownStartProxy.this, ProxyService.class);
CountDownStartProxy.this.startForegroundService(intent);
timer.cancel();
onBackPressed();
return;
}
secondsToWaitTextView.setText(seconds+"");
}
};
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
clicks = 0;
seconds = SECONDS; seconds = SECONDS;
timer = new Timer(); timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() { timer.scheduleAtFixedRate(new TimerTask() {
public void run() { public void run() {
finishTimerHandler.post(new Runnable() { finishTimerHandler.post(onSecondPass);
@Override
public void run() {
seconds--;
if (seconds < 0) {
Intent intent = new Intent(CountDownStartProxy.this, ProxyService.class);
CountDownStartProxy.this.startForegroundService(intent);
timer.cancel();
onBackPressed();
return;
}
secondsToWaitTextView.setText(seconds+"");
}
});
} }
}, 1000, 1000 }, 1000, 1000
); );
@ -98,8 +102,22 @@ public class CountDownStartProxy extends AppCompatActivity {
secondsToWaitTextView.setText(seconds + ""); secondsToWaitTextView.setText(seconds + "");
secondsToWaitTextView.setGravity(Gravity.CENTER_HORIZONTAL); secondsToWaitTextView.setGravity(Gravity.CENTER_HORIZONTAL);
secondsToWaitTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, 70); secondsToWaitTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, 70);
TextView offer = new TextView(this);
offer.setText("People say time go faster if you are doing something.\n"
+ "Maybe you could try pressing this button");
Button fasterTime = new Button(this);
clicks = 0;
fasterTime.setOnClickListener( (View view) -> {
clicks++;
if (clicks % 2 == 0) {
finishTimerHandler.post(onSecondPass);
}
});
layout.addView(explain); layout.addView(explain);
layout.addView(secondsToWaitTextView); layout.addView(secondsToWaitTextView);
layout.addView(offer);
layout.addView(fasterTime);
setContentView(layout); setContentView(layout);
} }
} }

View File

@ -154,14 +154,14 @@ public class MainActivity extends AppCompatActivity {
directConnectionButton = new Button(this); directConnectionButton = new Button(this);
directConnectionButton.setOnClickListener( (View view) -> { directConnectionButton.setOnClickListener( (View view) -> {
options.set(Options.HOST_SELECTED, options.get(Options.HOST_CACHE));
options.set(Options.PORT_SELECTED, options.get(Options.PORT_CACHE));
if(!proxyService.isServerStarted()) { if(!proxyService.isServerStarted()) {
if (!getSystemService(NotificationManager.class) if (!getSystemService(NotificationManager.class)
.areNotificationsEnabled()) { .areNotificationsEnabled()) {
requestPermissionLauncher.launch(android.Manifest.permission.POST_NOTIFICATIONS); requestPermissionLauncher.launch(android.Manifest.permission.POST_NOTIFICATIONS);
return; return;
} }
options.set(Options.HOST_SELECTED, options.get(Options.HOST_CACHE));
options.set(Options.PORT_SELECTED, options.get(Options.PORT_CACHE));
if (Premium.ENABLED) { if (Premium.ENABLED) {
startServiceProxy(); startServiceProxy();
return; return;