From aa17542f985f1212f31b596a505a6a7786f5cc5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedek=20L=C3=A1szl=C3=B3?= Date: Wed, 8 May 2024 19:50:45 +0200 Subject: [PATCH] cleanup --- .../quack/activity/RegisterActivity.java | 19 --------------- .../dowerx/quack/fragment/FeedFragment.java | 3 ++- .../quack/fragment/NewPostFragment.java | 6 ++--- .../fragment/PostRecyclerViewAdapter.java | 23 +++++++++++++------ .../quack/fragment/ProfileFeedFragment.java | 3 ++- .../dowerx/quack/fragment/SearchFragment.java | 10 ++++---- .../fragment/UserRecyclerViewAdapter.java | 7 ++---- .../java/com/dowerx/quack/model/Post.java | 5 ---- .../com/dowerx/quack/service/PostService.java | 6 ----- .../com/dowerx/quack/service/UserService.java | 4 ---- app/src/main/res/layout/activity_main.xml | 11 ++++----- app/src/main/res/layout/activity_register.xml | 15 ++++++------ .../main/res/layout/fragment_feed_list.xml | 2 -- app/src/main/res/layout/fragment_new_post.xml | 6 ++--- app/src/main/res/layout/fragment_post.xml | 16 ++++++------- app/src/main/res/layout/fragment_profile.xml | 5 +--- .../main/res/layout/fragment_search_list.xml | 4 ++-- app/src/main/res/layout/fragment_user.xml | 4 ++-- app/src/main/res/values/dimens.xml | 1 + app/src/main/res/values/strings.xml | 1 + 20 files changed, 57 insertions(+), 94 deletions(-) diff --git a/app/src/main/java/com/dowerx/quack/activity/RegisterActivity.java b/app/src/main/java/com/dowerx/quack/activity/RegisterActivity.java index 2d06940..ba4ee0c 100644 --- a/app/src/main/java/com/dowerx/quack/activity/RegisterActivity.java +++ b/app/src/main/java/com/dowerx/quack/activity/RegisterActivity.java @@ -16,9 +16,6 @@ import com.dowerx.quack.R; import com.dowerx.quack.service.AuthService; public class RegisterActivity extends AppCompatActivity { - -// private FirebaseAuth fbs; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -30,7 +27,6 @@ public class RegisterActivity extends AppCompatActivity { return insets; }); -// fbs = FirebaseAuth.getInstance(); } public void register(View view) { @@ -52,21 +48,6 @@ public class RegisterActivity extends AppCompatActivity { AuthService.Register task = new AuthService.Register(this); task.execute(email, password, username); - -// fbs.createUserWithEmailAndPassword(email, password).addOnCompleteListener(this, task -> { -// if (task.isSuccessful()) { -// Toast toast = new Toast(this); -// toast.setText("succesful register"); -// toast.setDuration(Toast.LENGTH_LONG); -// toast.show(); -// startActivity(new Intent(this, MainActivity.class)); -// } else { -// Toast toast = new Toast(this); -// toast.setText("login failed"); -// toast.setDuration(Toast.LENGTH_LONG); -// toast.show(); -// } -// }); } public void redirect_login(View view) { diff --git a/app/src/main/java/com/dowerx/quack/fragment/FeedFragment.java b/app/src/main/java/com/dowerx/quack/fragment/FeedFragment.java index d52e252..ad2f03c 100644 --- a/app/src/main/java/com/dowerx/quack/fragment/FeedFragment.java +++ b/app/src/main/java/com/dowerx/quack/fragment/FeedFragment.java @@ -16,6 +16,7 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.dowerx.quack.R; +import com.dowerx.quack.activity.SwitcherActivity; import com.dowerx.quack.model.Post; import com.dowerx.quack.service.PostService; @@ -68,7 +69,7 @@ public class FeedFragment extends Fragment implements LoaderManager.LoaderCallba public void onLoadFinished(@NonNull Loader> loader, List data) { Log.d(this.getClass().getName(), "onLoadFinished"); Log.d(this.getClass().getName(), data.toString()); - recyclerView.setAdapter(new PostRecyclerViewAdapter(data)); + recyclerView.setAdapter(new PostRecyclerViewAdapter(data, (SwitcherActivity)getContext())); } @Override diff --git a/app/src/main/java/com/dowerx/quack/fragment/NewPostFragment.java b/app/src/main/java/com/dowerx/quack/fragment/NewPostFragment.java index 659fb1a..6a16f75 100644 --- a/app/src/main/java/com/dowerx/quack/fragment/NewPostFragment.java +++ b/app/src/main/java/com/dowerx/quack/fragment/NewPostFragment.java @@ -1,15 +1,13 @@ package com.dowerx.quack.fragment; -import android.os.AsyncTask; import android.os.Bundle; - -import androidx.fragment.app.Fragment; - import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.EditText; +import androidx.fragment.app.Fragment; + import com.dowerx.quack.R; import com.dowerx.quack.service.PostService; diff --git a/app/src/main/java/com/dowerx/quack/fragment/PostRecyclerViewAdapter.java b/app/src/main/java/com/dowerx/quack/fragment/PostRecyclerViewAdapter.java index 2606e31..5a16915 100644 --- a/app/src/main/java/com/dowerx/quack/fragment/PostRecyclerViewAdapter.java +++ b/app/src/main/java/com/dowerx/quack/fragment/PostRecyclerViewAdapter.java @@ -1,15 +1,16 @@ package com.dowerx.quack.fragment; -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; - -import android.annotation.SuppressLint; import android.graphics.Color; import android.view.LayoutInflater; import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.dowerx.quack.R; +import com.dowerx.quack.activity.SwitcherActivity; import com.dowerx.quack.databinding.FragmentPostBinding; import com.dowerx.quack.model.Post; import com.dowerx.quack.service.AuthService; @@ -20,9 +21,11 @@ import java.util.List; public class PostRecyclerViewAdapter extends RecyclerView.Adapter { private final List mValues; + private final SwitcherActivity activity; - public PostRecyclerViewAdapter(List items) { - mValues = items; + public PostRecyclerViewAdapter(List items, SwitcherActivity activity) { + this.mValues = items; + this.activity = activity; } @NonNull @@ -35,7 +38,13 @@ public class PostRecyclerViewAdapter extends RecyclerView.Adapter{ + activity.setUser(holder.mItem.getUser().getId()); + activity.findViewById(R.id.nav_profile).performClick(); + }); + holder.content.setText(holder.mItem.getContent()); + holder.like.setText((holder.mItem.isLiked() ? "Liked " : "Likes ") + holder.mItem.getLikes()); holder.like.setBackgroundColor(holder.mItem.isLiked() ? Color.rgb(36, 166, 71) : Color.rgb(173, 33, 61)); holder.like.setOnClickListener(v -> { @@ -57,7 +66,7 @@ public class PostRecyclerViewAdapter extends RecyclerView.Adapter { diff --git a/app/src/main/java/com/dowerx/quack/fragment/ProfileFeedFragment.java b/app/src/main/java/com/dowerx/quack/fragment/ProfileFeedFragment.java index f43e490..35a8b41 100644 --- a/app/src/main/java/com/dowerx/quack/fragment/ProfileFeedFragment.java +++ b/app/src/main/java/com/dowerx/quack/fragment/ProfileFeedFragment.java @@ -16,6 +16,7 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.dowerx.quack.R; +import com.dowerx.quack.activity.SwitcherActivity; import com.dowerx.quack.model.Post; import com.dowerx.quack.service.PostService; @@ -75,7 +76,7 @@ public class ProfileFeedFragment extends Fragment implements LoaderManager.Loade public void onLoadFinished(@NonNull Loader> loader, List data) { Log.d(this.getClass().getName(), "onLoadFinished"); Log.d(this.getClass().getName(), data.toString()); - recyclerView.setAdapter(new PostRecyclerViewAdapter(data)); + recyclerView.setAdapter(new PostRecyclerViewAdapter(data, (SwitcherActivity)getContext())); } @Override diff --git a/app/src/main/java/com/dowerx/quack/fragment/SearchFragment.java b/app/src/main/java/com/dowerx/quack/fragment/SearchFragment.java index 030f0ab..d2c5bc4 100644 --- a/app/src/main/java/com/dowerx/quack/fragment/SearchFragment.java +++ b/app/src/main/java/com/dowerx/quack/fragment/SearchFragment.java @@ -1,8 +1,11 @@ package com.dowerx.quack.fragment; -import android.app.Activity; import android.content.Context; import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.EditText; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -12,11 +15,6 @@ import androidx.loader.content.Loader; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.EditText; - import com.dowerx.quack.R; import com.dowerx.quack.activity.SwitcherActivity; import com.dowerx.quack.model.User; diff --git a/app/src/main/java/com/dowerx/quack/fragment/UserRecyclerViewAdapter.java b/app/src/main/java/com/dowerx/quack/fragment/UserRecyclerViewAdapter.java index 12118aa..2d0baee 100644 --- a/app/src/main/java/com/dowerx/quack/fragment/UserRecyclerViewAdapter.java +++ b/app/src/main/java/com/dowerx/quack/fragment/UserRecyclerViewAdapter.java @@ -1,19 +1,16 @@ package com.dowerx.quack.fragment; -import androidx.recyclerview.widget.RecyclerView; - -import android.app.Activity; import android.view.LayoutInflater; import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; +import androidx.recyclerview.widget.RecyclerView; + import com.dowerx.quack.R; import com.dowerx.quack.activity.SwitcherActivity; import com.dowerx.quack.databinding.FragmentUserBinding; import com.dowerx.quack.model.User; -import androidx.fragment.app.Fragment; - import java.util.List; diff --git a/app/src/main/java/com/dowerx/quack/model/Post.java b/app/src/main/java/com/dowerx/quack/model/Post.java index 0dc2ccf..4ad4bca 100644 --- a/app/src/main/java/com/dowerx/quack/model/Post.java +++ b/app/src/main/java/com/dowerx/quack/model/Post.java @@ -1,10 +1,5 @@ package com.dowerx.quack.model; -import java.sql.Array; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - public class Post { public User getUser() { return user; diff --git a/app/src/main/java/com/dowerx/quack/service/PostService.java b/app/src/main/java/com/dowerx/quack/service/PostService.java index 6e03497..8136e82 100644 --- a/app/src/main/java/com/dowerx/quack/service/PostService.java +++ b/app/src/main/java/com/dowerx/quack/service/PostService.java @@ -2,7 +2,6 @@ package com.dowerx.quack.service; import android.app.Activity; import android.content.Context; -import android.content.Intent; import android.os.AsyncTask; import android.util.Log; import android.widget.Toast; @@ -14,25 +13,20 @@ import androidx.loader.content.AsyncTaskLoader; import com.dowerx.quack.R; import com.dowerx.quack.model.Post; import com.dowerx.quack.model.User; -import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.Tasks; import com.google.firebase.auth.FirebaseAuth; -import com.google.firebase.firestore.CollectionReference; import com.google.firebase.firestore.DocumentReference; import com.google.firebase.firestore.DocumentSnapshot; import com.google.firebase.firestore.Filter; import com.google.firebase.firestore.FirebaseFirestore; -import com.google.firebase.firestore.Query; import com.google.firebase.firestore.QueryDocumentSnapshot; import com.google.firebase.firestore.QuerySnapshot; -import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; -import java.util.concurrent.atomic.AtomicBoolean; public class PostService { public static class GetFeed extends AsyncTaskLoader> { diff --git a/app/src/main/java/com/dowerx/quack/service/UserService.java b/app/src/main/java/com/dowerx/quack/service/UserService.java index 40b8585..25aa911 100644 --- a/app/src/main/java/com/dowerx/quack/service/UserService.java +++ b/app/src/main/java/com/dowerx/quack/service/UserService.java @@ -5,15 +5,12 @@ import android.content.Context; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.loader.content.AsyncTaskLoader; -import androidx.loader.content.Loader; -import com.dowerx.quack.model.Post; import com.dowerx.quack.model.User; import com.google.android.gms.tasks.Tasks; import com.google.firebase.firestore.DocumentSnapshot; import com.google.firebase.firestore.Filter; import com.google.firebase.firestore.FirebaseFirestore; -import com.google.firebase.firestore.QueryDocumentSnapshot; import com.google.firebase.firestore.QuerySnapshot; import java.util.LinkedList; @@ -22,7 +19,6 @@ import java.util.concurrent.ExecutionException; public class UserService { public static class GetUserByUsername extends AsyncTaskLoader { - private final String username; public GetUserByUsername(@NonNull Context context, String username) { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index e92460c..98cf674 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -11,7 +11,7 @@ android:id="@+id/logo" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="20dp" + android:layout_marginTop="@dimen/default_margin" android:text="@string/app_name" android:textSize="48sp" app:layout_constraintEnd_toEndOf="parent" @@ -22,13 +22,12 @@ android:id="@+id/email" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="20dp" + android:layout_marginTop="@dimen/default_margin" android:autofillHints="emailAddress" android:ems="10" android:hint="@string/email_hint" android:inputType="textEmailAddress" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintHorizontal_bias="0.502" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/logo" /> @@ -36,7 +35,7 @@ android:id="@+id/password" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="20dp" + android:layout_marginTop="@dimen/default_margin" android:ems="10" android:inputType="textPassword" android:autofillHints="password" @@ -49,7 +48,7 @@ android:id="@+id/login" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="20dp" + android:layout_marginTop="@dimen/default_margin" android:text="@string/login_btn" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" @@ -60,7 +59,7 @@ android:id="@+id/register" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="20dp" + android:layout_marginTop="@dimen/default_margin" android:text="@string/register_btn" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" diff --git a/app/src/main/res/layout/activity_register.xml b/app/src/main/res/layout/activity_register.xml index 1e2e4b2..b5c6df8 100644 --- a/app/src/main/res/layout/activity_register.xml +++ b/app/src/main/res/layout/activity_register.xml @@ -11,7 +11,7 @@ android:id="@+id/logo" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="20dp" + android:layout_marginTop="@dimen/default_margin" android:text="@string/register_btn" android:textSize="48sp" app:layout_constraintEnd_toEndOf="parent" @@ -22,13 +22,12 @@ android:id="@+id/email" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="20dp" + android:layout_marginTop="@dimen/default_margin" android:autofillHints="emailAddress" android:ems="10" android:hint="@string/email_hint" android:inputType="textEmailAddress" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintHorizontal_bias="0.502" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/logo" /> @@ -36,7 +35,7 @@ android:id="@+id/username" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="20dp" + android:layout_marginTop="@dimen/default_margin" android:ems="10" android:inputType="textPersonName" android:autofillHints="username" @@ -49,7 +48,7 @@ android:id="@+id/password" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="20dp" + android:layout_marginTop="@dimen/default_margin" android:ems="10" android:inputType="textPassword" android:autofillHints="password" @@ -62,7 +61,7 @@ android:id="@+id/repeat_password" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="20dp" + android:layout_marginTop="@dimen/default_margin" android:ems="10" android:inputType="textPassword" android:autofillHints="password" @@ -75,7 +74,7 @@ android:id="@+id/register" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="20dp" + android:layout_marginTop="@dimen/default_margin" android:text="@string/register_btn" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" @@ -86,7 +85,7 @@ android:id="@+id/login" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="20dp" + android:layout_marginTop="@dimen/default_margin" android:text="@string/login_btn" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" diff --git a/app/src/main/res/layout/fragment_feed_list.xml b/app/src/main/res/layout/fragment_feed_list.xml index 2ff8d93..1b7ae0d 100644 --- a/app/src/main/res/layout/fragment_feed_list.xml +++ b/app/src/main/res/layout/fragment_feed_list.xml @@ -6,8 +6,6 @@ android:name="com.dowerx.quack.FeedFragment" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_marginLeft="16dp" - android:layout_marginRight="16dp" app:layoutManager="LinearLayoutManager" tools:context=".fragment.FeedFragment" tools:listitem="@layout/fragment_post" /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_new_post.xml b/app/src/main/res/layout/fragment_new_post.xml index 6986343..cf1a820 100644 --- a/app/src/main/res/layout/fragment_new_post.xml +++ b/app/src/main/res/layout/fragment_new_post.xml @@ -11,10 +11,11 @@ android:layout_height="match_parent"> diff --git a/app/src/main/res/layout/fragment_post.xml b/app/src/main/res/layout/fragment_post.xml index d81c759..d15e4ff 100644 --- a/app/src/main/res/layout/fragment_post.xml +++ b/app/src/main/res/layout/fragment_post.xml @@ -10,8 +10,7 @@ android:id="@+id/username" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_margin="20dp" - android:text="" + android:layout_margin="@dimen/default_margin" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> @@ -19,23 +18,22 @@ android:id="@+id/content" android:layout_width="match_parent" android:layout_height="wrap_content" - android:text="" app:layout_constraintTop_toBottomOf="@+id/username" - android:layout_margin="20dp"/> + android:layout_margin="@dimen/default_margin"/>