logout button
This commit is contained in:
parent
7b5156ff3f
commit
825617c2e6
3 changed files with 93 additions and 10 deletions
|
@ -3,9 +3,15 @@ package asgardius.page.r3forumtest;
|
|||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
|
@ -20,12 +26,21 @@ public class MainScreen extends AppCompatActivity {
|
|||
boolean success;
|
||||
BufferedReader br;
|
||||
StringBuilder sb;
|
||||
JSONObject jsonObj;
|
||||
SQLiteDatabase db;
|
||||
MyDbHelper dbHelper;
|
||||
TextView id;
|
||||
Button logout;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main_screen);
|
||||
username = getIntent().getStringExtra("username");
|
||||
id = (TextView) findViewById(R.id.username);
|
||||
logout = (Button)findViewById(R.id.logout);
|
||||
dbHelper = new MyDbHelper(this);
|
||||
id.setText(username);
|
||||
Thread login = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
|
@ -54,6 +69,7 @@ public class MainScreen extends AppCompatActivity {
|
|||
sb.append(output);
|
||||
}
|
||||
System.out.println(sb.toString());
|
||||
jsonObj = new JSONObject(sb.toString());
|
||||
} else {
|
||||
success = false;
|
||||
}
|
||||
|
@ -86,8 +102,54 @@ public class MainScreen extends AppCompatActivity {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
login.start();
|
||||
logout.setOnClickListener(new View.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
//buttonaction
|
||||
Thread logout = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
db = dbHelper.getWritableDatabase();
|
||||
db.execSQL("DELETE FROM account");
|
||||
db.close();
|
||||
runOnUiThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
//Test
|
||||
mainMenu();
|
||||
}
|
||||
});
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
runOnUiThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(getApplicationContext(), "Conexión fallida", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
//Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
|
||||
//finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
logout.start();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void mainMenu() {
|
||||
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
intent.putExtra("EXIT", true);
|
||||
startActivity(intent);
|
||||
|
||||
}
|
||||
|
||||
public void onBackPressed(){
|
||||
|
|
|
@ -11,7 +11,6 @@ import android.widget.EditText;
|
|||
import android.widget.Toast;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
|
@ -90,7 +89,7 @@ public class SignUp extends AppCompatActivity {
|
|||
//Test
|
||||
if (success) {
|
||||
Toast.makeText(getApplicationContext(), "Registro exitoso", Toast.LENGTH_SHORT).show();
|
||||
mainmenu();
|
||||
mainMenu();
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(), "El usuario ya existe", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
@ -118,7 +117,7 @@ public class SignUp extends AppCompatActivity {
|
|||
});
|
||||
}
|
||||
|
||||
private void mainmenu() {
|
||||
private void mainMenu() {
|
||||
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
|
|
|
@ -9,12 +9,34 @@
|
|||
android:background="@drawable/galaxy"
|
||||
tools:context=".MainScreen">
|
||||
|
||||
<TextView
|
||||
<LinearLayout
|
||||
android:id="@+id/linearLayoutSubmit"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Bienvenido al foro"
|
||||
android:layout_height="70dp"
|
||||
android:layout_margin="20dp"
|
||||
android:orientation="horizontal"
|
||||
tools:ignore="MissingConstraints"
|
||||
tools:layout_editor_absoluteX="20dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/username"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="25sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/logout"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:backgroundTint="@color/black"
|
||||
android:text="Salir"
|
||||
android:textColor="@color/white"
|
||||
tools:ignore="MissingConstraints" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in a new issue