added polling thread at join queue and disabling of login button
This commit is contained in:
parent
6385aac6b2
commit
3625bd22ca
@ -17,6 +17,8 @@ import java.util.concurrent.ExecutionException;
|
|||||||
|
|
||||||
public class JoinQueueActivity extends AppCompatActivity {
|
public class JoinQueueActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
Thread pollingThread;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -27,6 +29,10 @@ public class JoinQueueActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
|
||||||
|
if(pollingThread.isAlive()){
|
||||||
|
pollingThread.interrupt();
|
||||||
|
}
|
||||||
|
|
||||||
SharedPreferences preferences = getApplicationContext().getSharedPreferences("scheduler_preferences", Context.MODE_PRIVATE);
|
SharedPreferences preferences = getApplicationContext().getSharedPreferences("scheduler_preferences", Context.MODE_PRIVATE);
|
||||||
QueueTask task = new QueueTask("location1", preferences.getString("api_key", null));
|
QueueTask task = new QueueTask("location1", preferences.getString("api_key", null));
|
||||||
|
|
||||||
@ -49,21 +55,59 @@ public class JoinQueueActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
SharedPreferences preferences = getApplicationContext().getSharedPreferences("scheduler_preferences", Context.MODE_PRIVATE);
|
final SharedPreferences preferences = getApplicationContext().getSharedPreferences("scheduler_preferences", Context.MODE_PRIVATE);
|
||||||
GetUserTask task = new GetUserTask(preferences.getString("api_key", null));
|
final long timeInterval = 2000;
|
||||||
|
Runnable runnable = new Runnable() {
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
boolean changed = false;
|
||||||
|
while (!changed) {
|
||||||
|
|
||||||
|
GetUserTask task = new GetUserTask(preferences.getString("api_key", null));
|
||||||
task.execute();
|
task.execute();
|
||||||
try {
|
try {
|
||||||
User user = task.get();
|
User user = task.get();
|
||||||
|
|
||||||
if(user.getState() != User.State.inactive){
|
Intent intent;
|
||||||
joinButton.setEnabled(false);
|
switch(user.getState()){
|
||||||
|
case in_queue:
|
||||||
|
intent = new Intent(JoinQueueActivity.this, WaitingActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
changed = true;
|
||||||
|
break;
|
||||||
|
case assigned:
|
||||||
|
intent = new Intent(JoinQueueActivity.this, PluginWait_Activity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
changed = true;
|
||||||
|
break;
|
||||||
|
case connected_charging:
|
||||||
|
intent = new Intent(JoinQueueActivity.this, ChargingActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
changed = true;
|
||||||
|
break;
|
||||||
|
case connected_full:
|
||||||
|
intent = new Intent(JoinQueueActivity.this, FullActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
changed = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(timeInterval);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
pollingThread = new Thread(runnable);
|
||||||
|
pollingThread.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ import java.util.concurrent.ExecutionException;
|
|||||||
public class Login2Activity extends AppCompatActivity {
|
public class Login2Activity extends AppCompatActivity {
|
||||||
|
|
||||||
ProgressBar loading;
|
ProgressBar loading;
|
||||||
|
Button signInButton;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -55,9 +56,9 @@ public class Login2Activity extends AppCompatActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final Button signInButton = findViewById(R.id.login);
|
|
||||||
final EditText usernameEditText = findViewById(R.id.username);
|
final EditText usernameEditText = findViewById(R.id.username);
|
||||||
final EditText passwordEditText = findViewById(R.id.password);
|
final EditText passwordEditText = findViewById(R.id.password);
|
||||||
|
signInButton = findViewById(R.id.login);
|
||||||
loading = findViewById(R.id.loading);
|
loading = findViewById(R.id.loading);
|
||||||
signInButton.setOnClickListener(new View.OnClickListener() {
|
signInButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -92,8 +93,9 @@ public class Login2Activity extends AppCompatActivity {
|
|||||||
|
|
||||||
private void tryLogin(String username, String password) {
|
private void tryLogin(String username, String password) {
|
||||||
|
|
||||||
NativeLoginTask task = new NativeLoginTask(username, password);
|
signInButton.setEnabled(false);
|
||||||
|
|
||||||
|
NativeLoginTask task = new NativeLoginTask(username, password);
|
||||||
task.execute();
|
task.execute();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -101,6 +103,7 @@ public class Login2Activity extends AppCompatActivity {
|
|||||||
|
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
|
|
||||||
|
signInButton.setEnabled(true);
|
||||||
Toast.makeText(Login2Activity.this, "error", Toast.LENGTH_SHORT).show();
|
Toast.makeText(Login2Activity.this, "error", Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
|
Loading…
Reference in New Issue
Block a user