This commit is contained in:
Benedek László 2024-05-08 19:50:45 +02:00
parent 25d9688c8a
commit aa17542f98
20 changed files with 57 additions and 94 deletions

View File

@ -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) {

View File

@ -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<List<Post>> loader, List<Post> 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

View File

@ -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;

View File

@ -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<PostRecyclerViewAdapter.ViewHolder> {
private final List<Post> mValues;
private final SwitcherActivity activity;
public PostRecyclerViewAdapter(List<Post> items) {
mValues = items;
public PostRecyclerViewAdapter(List<Post> items, SwitcherActivity activity) {
this.mValues = items;
this.activity = activity;
}
@NonNull
@ -35,7 +38,13 @@ public class PostRecyclerViewAdapter extends RecyclerView.Adapter<PostRecyclerVi
public void onBindViewHolder(final ViewHolder holder, int position) {
holder.mItem = mValues.get(position);
holder.username.setText(holder.mItem.getUser().getUsername());
holder.username.setOnClickListener(v->{
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<PostRecyclerVi
});
if (!AuthService.getId().equals(holder.mItem.getUser().getId())) {
holder.remove.setAlpha(0.5f);
holder.remove.setAlpha(0.0f);
holder.remove.setClickable(false);
} else {
holder.remove.setOnClickListener(v -> {

View File

@ -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<List<Post>> loader, List<Post> 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

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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<List<Post>> {

View File

@ -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<User> {
private final String username;
public GetUserByUsername(@NonNull Context context, String username) {

View File

@ -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"

View File

@ -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"

View File

@ -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" />

View File

@ -11,10 +11,11 @@
android:layout_height="match_parent">
<EditText
android:hint="@string/content_hint"
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_margin="@dimen/default_margin"
android:ems="10"
android:gravity="start|top"
android:inputType="textMultiLine"
@ -27,10 +28,9 @@
android:id="@+id/send_post"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginTop="@dimen/default_margin"
android:text="@string/post_btn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/content"
/>

View File

@ -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"/>
<LinearLayout
android:id="@+id/post_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_margin="@dimen/default_margin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/content">
<Button
android:id="@+id/like"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="@dimen/default_margin"
android:layout_marginRight="@dimen/default_margin"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -43,8 +41,8 @@
<Button
android:id="@+id/remove"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="@dimen/default_margin"
android:layout_marginRight="@dimen/default_margin"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View File

@ -13,15 +13,12 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:padding="20dp">
android:padding="@dimen/default_margin">
<TextView
android:id="@+id/profile_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/placeholder_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.08"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -14,7 +14,7 @@
app:layout_constraintTop_toTopOf="parent"
android:hint="@string/username_hint"
android:autofillHints="username,search"
android:layout_margin="20dp"/>
android:layout_margin="@dimen/default_margin"/>
<Button
android:id="@+id/search"
@ -23,7 +23,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:text="@string/search_btn"
android:layout_margin="20dp"/>
android:layout_margin="@dimen/default_margin"/>
<androidx.recyclerview.widget.RecyclerView

View File

@ -9,7 +9,7 @@
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_margin="@dimen/default_margin"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
@ -22,5 +22,5 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_margin="20dp"/>
android:layout_margin="@dimen/default_margin"/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="text_margin">16dp</dimen>
<dimen name="default_margin">20dp</dimen>
</resources>

View File

@ -107,4 +107,5 @@
</string>
<string name="search_btn">Search</string>
<string name="view_profile">View</string>
<string name="content_hint">Content</string>
</resources>