Skip to content
This repository was archived by the owner on Jan 20, 2023. It is now read-only.

Commit 4d5690b

Browse files
seitencaa19marbasgraalexia312313a19marsbasgra
authored
Recycler view (#11)
* Tot preparat per la RecyclerView * Commit final del dia - NULL progress * Eliminades part deprecated * Eliminades parts deprecated * none * none 2 * none 3 * none 4 * add viewmodel to balance fragment * none 5 * Tenda WOOORKSSSSSS * Tenda compra i envia a BD * reformat code + add token to Login.java * Tenda works for real now * Balance works, hem eliminat molta cosa que no dona temps d'implementar Co-authored-by: a19marbasgra <[email protected]> Co-authored-by: alexiadltg <[email protected]> Co-authored-by: a19marsbasgra <[email protected]>
1 parent a80435b commit 4d5690b

38 files changed

+595
-639
lines changed

app/build.gradle

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,16 @@ dependencies {
4444
implementation 'androidx.navigation:navigation-fragment:2.5.3'
4545
implementation 'androidx.navigation:navigation-ui:2.5.3'
4646
implementation 'com.google.android.gms:play-services-maps:18.1.0'
47-
implementation 'com.google.android.libraries.places:places:2.6.0'
47+
implementation 'com.google.android.libraries.places:places:2.7.0'
4848
implementation 'com.android.volley:volley:1.2.1'
4949
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
5050
testImplementation 'junit:junit:4.13.2'
51-
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
52-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
51+
implementation 'com.github.bumptech.glide:glide:3.7.0'
52+
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
53+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
54+
implementation 'com.android.support:appcompat-v7:33.0.0'
55+
implementation 'com.android.support:recyclerview-v7:33.0.0'
56+
5357
}
5458

5559
secrets {

app/src/debug/res/navigation/mobile_navigation.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
<fragment
3333
android:id="@+id/nav_tenda"
34-
android:name="org.deplastic.Deplastic.ui.tenda.TendaFragment"
34+
android:name="org.deplastic.Deplastic.ui.tenda.ShopFragment"
3535
android:label="@string/menu_tenda"
3636
tools:layout="@layout/fragment_tenda" />
3737
</navigation>

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
android:theme="@style/Theme.Deplastic"
1818
tools:targetApi="31">
1919
<activity
20-
android:name=".Register"
20+
android:name=".Credentials.Register"
2121
android:exported="false">
2222
<meta-data
2323
android:name="android.app.lib_name"
@@ -32,7 +32,7 @@
3232
</activity>
3333

3434
<activity
35-
android:name=".Login"
35+
android:name=".Credentials.Login"
3636
android:exported="true">
3737
<intent-filter>
3838
<action android:name="android.intent.action.MAIN" />

app/src/main/java/org/deplastic/Deplastic/Login.java renamed to app/src/main/java/org/deplastic/Deplastic/Credentials/Login.java

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
package org.deplastic.Deplastic;
1+
package org.deplastic.Deplastic.Credentials;
22

3-
import androidx.appcompat.app.AppCompatActivity;
4-
5-
import android.content.Context;
63
import android.content.Intent;
74
import android.content.SharedPreferences;
85
import android.os.Bundle;
9-
import android.view.View;
106
import android.widget.Button;
117
import android.widget.EditText;
128
import android.widget.Toast;
139

10+
import androidx.appcompat.app.AppCompatActivity;
11+
1412
import com.android.volley.Request;
1513
import com.android.volley.RequestQueue;
1614
import com.android.volley.toolbox.JsonObjectRequest;
1715
import com.android.volley.toolbox.Volley;
1816

17+
import org.deplastic.Deplastic.MainActivity;
18+
import org.deplastic.Deplastic.R;
1919
import org.json.JSONException;
2020
import org.json.JSONObject;
2121

@@ -24,6 +24,42 @@ public class Login extends AppCompatActivity {
2424
@Override
2525
protected void onCreate(Bundle savedInstanceState) {
2626
super.onCreate(savedInstanceState);
27+
28+
SharedPreferences sp = getSharedPreferences("login", MODE_PRIVATE);
29+
RequestQueue queue = Volley.newRequestQueue(getApplicationContext());
30+
31+
JSONObject token = new JSONObject();
32+
33+
try {
34+
token.put("token", sp.getString("token", ""));
35+
token.put("email", sp.getString("email", ""));
36+
} catch (JSONException e) {
37+
e.printStackTrace();
38+
}
39+
40+
System.out.println(token);
41+
42+
String url_token = "https://deplastic.netlify.app/.netlify/functions/api/token";
43+
JsonObjectRequest tokenRequest = new JsonObjectRequest(Request.Method.POST, url_token, token,
44+
response -> {
45+
try {
46+
if (response.getBoolean("auth")) {
47+
Intent newIntent = new Intent(getApplicationContext(), MainActivity.class);
48+
startActivity(newIntent);
49+
} else {
50+
init_form();
51+
}
52+
} catch (JSONException e) {
53+
e.printStackTrace();
54+
}
55+
}, Throwable::printStackTrace);
56+
queue.add(tokenRequest);
57+
}
58+
59+
private void init_form() {
60+
SharedPreferences sp = getSharedPreferences("login", MODE_PRIVATE);
61+
RequestQueue queue = Volley.newRequestQueue(getApplicationContext());
62+
2763
setContentView(R.layout.activity_login);
2864

2965
Button b = findViewById(R.id.LoginButton);
@@ -44,17 +80,21 @@ protected void onCreate(Bundle savedInstanceState) {
4480
}
4581

4682

47-
RequestQueue queue = Volley.newRequestQueue(getApplicationContext());
4883
String url = "https://deplastic.netlify.app/.netlify/functions/api/login";
4984
JsonObjectRequest stringRequest = new JsonObjectRequest(Request.Method.POST, url, credentials,
5085
response -> {
5186
try {
5287
if (response.getBoolean("auth")) {
53-
savetoPref(response);
54-
Toast.makeText(getApplicationContext(), readfromPref(), Toast.LENGTH_LONG).show();
88+
89+
Toast.makeText(getApplicationContext(), "Logged in", Toast.LENGTH_LONG).show();
5590
Intent newIntent = new Intent(getApplicationContext(), MainActivity.class);
5691
startActivity(newIntent);
57-
}else {
92+
sp.edit()
93+
.putString("token", response.getString("token"))
94+
.putString("email", emailVal)
95+
.putString("username", response.getString("username"))
96+
.apply();
97+
} else {
5898
Toast.makeText(getApplicationContext(), "Wrong user or password, try again.", Toast.LENGTH_SHORT).show();
5999
}
60100
} catch (JSONException e) {
@@ -66,24 +106,9 @@ protected void onCreate(Bundle savedInstanceState) {
66106

67107
Button R = findViewById(org.deplastic.Deplastic.R.id.toRegisterButton);
68108
R.setOnClickListener(v -> {
69-
Intent intent = new Intent(getApplicationContext(),Register.class);
109+
Intent intent = new Intent(getApplicationContext(), Register.class);
70110
startActivity(intent);
71111
});
72112
}
73-
74-
private String readfromPref() {
75-
SharedPreferences prefs = this.getSharedPreferences("general_settings", Context.MODE_PRIVATE);
76-
String lanSettings = prefs.getString("Credentials", null);
77-
78-
return lanSettings;
79-
}
80-
81-
private void savetoPref(JSONObject response) {
82-
SharedPreferences sharedpref = getPreferences(Context.MODE_PRIVATE);
83-
SharedPreferences.Editor editor = sharedpref.edit();
84-
editor.putString("Credentials", response.toString());
85-
86-
editor.apply();}
87113
}
88114

89-

app/src/main/java/org/deplastic/Deplastic/Register.java renamed to app/src/main/java/org/deplastic/Deplastic/Credentials/Register.java

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,40 @@
1-
package org.deplastic.Deplastic;
2-
3-
import androidx.appcompat.app.AlertDialog;
4-
import androidx.appcompat.app.AppCompatActivity;
1+
package org.deplastic.Deplastic.Credentials;
52

63
import android.content.Intent;
74
import android.os.Bundle;
8-
import android.view.View;
95
import android.widget.Button;
106
import android.widget.CheckBox;
117
import android.widget.EditText;
12-
138
import android.widget.RadioButton;
149
import android.widget.Toast;
1510

11+
import androidx.appcompat.app.AlertDialog;
12+
import androidx.appcompat.app.AppCompatActivity;
13+
1614
import com.android.volley.Request;
1715
import com.android.volley.RequestQueue;
1816
import com.android.volley.toolbox.JsonObjectRequest;
1917
import com.android.volley.toolbox.Volley;
2018

19+
import org.deplastic.Deplastic.R;
2120
import org.json.JSONException;
2221
import org.json.JSONObject;
2322

2423
public class Register extends AppCompatActivity {
25-
private CheckBox alertCheckBox;
2624

2725
@Override
2826

2927
protected void onCreate(Bundle savedInstanceState) {
3028
super.onCreate(savedInstanceState);
31-
setContentView(R.layout.activity_register2);
29+
setContentView(R.layout.activity_register);
3230
Button workingRegister = findViewById(R.id.RegisterButton);
3331
CheckBox EULABox = findViewById(R.id.checkBoxEULA);
34-
alertCheckBox = (CheckBox) findViewById(R.id.checkBoxEULA);
35-
alertCheckBox.setOnClickListener(new View.OnClickListener() {
36-
@Override
37-
public void onClick(View v) {
38-
AlertDialog.Builder EULAtxt = new AlertDialog.Builder(Register.this);
39-
EULAtxt.setMessage(R.string.EULAcontents);
40-
AlertDialog title = EULAtxt.create();
41-
title.setTitle(getString(R.string.eulaAlert));
42-
title.show();
43-
}
44-
32+
EULABox.setOnClickListener(v -> {
33+
AlertDialog.Builder eula = new AlertDialog.Builder(Register.this);
34+
eula.setMessage(R.string.EULAcontents);
35+
AlertDialog title = eula.create();
36+
title.setTitle(getString(R.string.eulaAlert));
37+
title.show();
4538
});
4639

4740
workingRegister.setOnClickListener(v -> {

app/src/main/java/org/deplastic/Deplastic/MainActivity.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616

1717
public class MainActivity extends AppCompatActivity {
1818
private AppBarConfiguration mAppBarConfiguration;
19-
private ActivityMainBinding binding;
2019

2120
@Override
2221
protected void onCreate(Bundle savedInstanceState) {
2322
super.onCreate(savedInstanceState);
24-
binding = ActivityMainBinding.inflate(getLayoutInflater());
23+
org.deplastic.Deplastic.databinding.ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
2524
setContentView(binding.getRoot());
2625

2726
setSupportActionBar(binding.appBarMain.toolbar);
@@ -49,7 +48,6 @@ public boolean onCreateOptionsMenu(Menu menu) {
4948
@Override
5049
public boolean onSupportNavigateUp() {
5150
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_main);
52-
return NavigationUI.navigateUp(navController, mAppBarConfiguration)
53-
|| super.onSupportNavigateUp();
51+
return NavigationUI.navigateUp(navController, mAppBarConfiguration) || super.onSupportNavigateUp();
5452
}
5553
}

app/src/main/java/org/deplastic/Deplastic/ui/calendar/CalendarFragment.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,19 @@
44
import android.view.LayoutInflater;
55
import android.view.View;
66
import android.view.ViewGroup;
7-
import android.widget.TextView;
87

98
import androidx.annotation.NonNull;
109
import androidx.fragment.app.Fragment;
11-
import androidx.lifecycle.ViewModelProvider;
1210

1311
import org.deplastic.Deplastic.databinding.FragmentCalendarBinding;
1412

1513
public class CalendarFragment extends Fragment {
1614

1715
private FragmentCalendarBinding binding;
1816

19-
public View onCreateView(@NonNull LayoutInflater inflater,
20-
ViewGroup container, Bundle savedInstanceState) {
21-
GalleryViewModel galleryViewModel =
22-
new ViewModelProvider(this).get(GalleryViewModel.class);
23-
17+
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
2418
binding = FragmentCalendarBinding.inflate(inflater, container, false);
25-
View root = binding.getRoot();
26-
27-
28-
29-
return root;
19+
return binding.getRoot();
3020
}
3121

3222
@Override

app/src/main/java/org/deplastic/Deplastic/ui/calendar/GalleryViewModel.java

Lines changed: 0 additions & 19 deletions
This file was deleted.

app/src/main/java/org/deplastic/Deplastic/ui/config/ConfigFragment.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package org.deplastic.Deplastic.ui.config;
22

3+
import static android.content.Context.MODE_PRIVATE;
4+
35
import android.content.Intent;
6+
import android.content.SharedPreferences;
47
import android.os.Bundle;
58
import android.view.LayoutInflater;
69
import android.view.View;
@@ -14,45 +17,42 @@
1417
import androidx.fragment.app.FragmentTransaction;
1518
import androidx.lifecycle.ViewModelProvider;
1619

17-
import org.deplastic.Deplastic.Login;
20+
import org.deplastic.Deplastic.Credentials.Login;
1821
import org.deplastic.Deplastic.R;
1922
import org.deplastic.Deplastic.databinding.FragmentConfigBinding;
2023
import org.deplastic.Deplastic.ui.config.balance.BalanceFragment;
2124

2225
public class ConfigFragment extends Fragment {
23-
2426
private FragmentConfigBinding binding;
27+
private SharedPreferences sharedPreferences;
2528

26-
public View onCreateView(@NonNull LayoutInflater inflater,
27-
ViewGroup container, Bundle savedInstanceState) {
28-
ConfigViewModel configViewModel =
29-
new ViewModelProvider(this).get(ConfigViewModel.class);
30-
29+
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
3130
binding = FragmentConfigBinding.inflate(inflater, container, false);
3231
View root = binding.getRoot();
3332

34-
Button balanceButton= root.findViewById(R.id.BalanceButton);
33+
sharedPreferences = requireContext().getSharedPreferences("login", MODE_PRIVATE);
34+
35+
36+
TextView username = root.findViewById(R.id.text_Config);
37+
username.setText(sharedPreferences.getString("username","ERROR"));
38+
39+
40+
Button balanceButton = root.findViewById(R.id.BalanceButton);
3541
balanceButton.setOnClickListener(v -> {
3642
Fragment fragment = new BalanceFragment();
37-
3843
FragmentManager fm = getParentFragmentManager();
3944
FragmentTransaction transaction = fm.beginTransaction();
4045
transaction.replace(R.id.nav_host_fragment_content_main, fragment);
4146
transaction.commit();
4247
});
43-
4448
Button logoutButton= root.findViewById(R.id.logoutButton);
4549
logoutButton.setOnClickListener(v -> {
50+
sharedPreferences.edit().remove("token").apply();
4651
Intent newIntent = new Intent(getContext(), Login.class);
4752
startActivity(newIntent);
4853
});
49-
50-
51-
final TextView textView = binding.textConfig;
52-
configViewModel.getText().observe(getViewLifecycleOwner(), textView::setText);
5354
return root;
5455
}
55-
5656
@Override
5757
public void onDestroyView() {
5858
super.onDestroyView();

app/src/main/java/org/deplastic/Deplastic/ui/config/ConfigViewModel.java

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)