From 83a929fd51fe2f81a98be0afd75e4c23d6ab568c Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Thu, 8 Oct 2020 16:57:01 -0700 Subject: [PATCH] Can now delete account --- .../java/com/example/listify/Requestor.java | 2 +- .../example/listify/ui/home/HomeFragment.java | 29 +++++++++++++++++-- .../app/src/main/res/layout/fragment_home.xml | 6 ++-- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/Listify/app/src/main/java/com/example/listify/Requestor.java b/Listify/app/src/main/java/com/example/listify/Requestor.java index 84043f1..3e65128 100644 --- a/Listify/app/src/main/java/com/example/listify/Requestor.java +++ b/Listify/app/src/main/java/com/example/listify/Requestor.java @@ -18,7 +18,7 @@ public class Requestor { String apiKey; OkHttpClient client; - Requestor(AuthManager authManager, String apiKey) { + public Requestor(AuthManager authManager, String apiKey) { this.authManager = authManager; this.apiKey = apiKey; client = new OkHttpClient(); diff --git a/Listify/app/src/main/java/com/example/listify/ui/home/HomeFragment.java b/Listify/app/src/main/java/com/example/listify/ui/home/HomeFragment.java index 2fb4fe2..48a71b9 100644 --- a/Listify/app/src/main/java/com/example/listify/ui/home/HomeFragment.java +++ b/Listify/app/src/main/java/com/example/listify/ui/home/HomeFragment.java @@ -10,7 +10,18 @@ import android.view.LayoutInflater; import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; +import static com.example.listify.MainActivity.am; + +import com.example.listify.AuthManager; +import com.example.listify.MainActivity; import com.example.listify.R; +import com.example.listify.Requestor; +import com.example.listify.ui.LoginPage; + +import org.json.JSONException; + +import java.io.IOException; +import java.util.Properties; public class HomeFragment extends Fragment { private Button toLoginPage; @@ -23,7 +34,7 @@ public class HomeFragment extends Fragment { toLoginPage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Intent intent = new Intent(HomeFragment.this.getActivity(), com.example.listify.ui.LoginPage.class); + Intent intent = new Intent(getActivity(), com.example.listify.ui.LoginPage.class); startActivity(intent); } }); @@ -32,8 +43,20 @@ public class HomeFragment extends Fragment { toListPage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Intent intent = new Intent(HomeFragment.this.getActivity(), com.example.listify.ListPage.class); - startActivity(intent); + //Intent intent = new Intent(HomeFragment.this.getActivity(), com.example.listify.ListPage.class); + //startActivity(intent); + + try { + Properties configs = new Properties(); + try { + configs = AuthManager.loadProperties(getContext(), "android.resource://" + getActivity().getPackageName() + "/raw/auths.json"); + } catch (IOException | JSONException e) { + e.printStackTrace(); + } + Requestor requestor = new Requestor(am, configs.getProperty("apiKey")); + am.deleteUser(requestor); + } + catch(Exception ex) {} } }); diff --git a/Listify/app/src/main/res/layout/fragment_home.xml b/Listify/app/src/main/res/layout/fragment_home.xml index 054c57e..f43f76a 100644 --- a/Listify/app/src/main/res/layout/fragment_home.xml +++ b/Listify/app/src/main/res/layout/fragment_home.xml @@ -11,17 +11,17 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="25dp" - android:layout_marginStart="1dp" + android:layout_marginEnd="25dp" android:text="Log in" app:layout_constraintBottom_toTopOf="@+id/button2" - app:layout_constraintStart_toStartOf="@+id/button2" /> + app:layout_constraintEnd_toEndOf="@+id/button2" />