basic profile layout

This commit is contained in:
Benedek László 2024-05-04 19:30:34 +02:00
parent 87c76e2614
commit 1928c1f20e
7 changed files with 124 additions and 5 deletions

View File

@ -30,6 +30,7 @@ public class PostRecyclerViewAdapter extends RecyclerView.Adapter<PostRecyclerVi
holder.mItem = mValues.get(position); holder.mItem = mValues.get(position);
holder.username.setText(holder.mItem.getUser().getUsername()); holder.username.setText(holder.mItem.getUser().getUsername());
holder.content.setText(holder.mItem.getContent()); holder.content.setText(holder.mItem.getContent());
holder.likes.setText("Likes " + holder.mItem.getLikes());
} }
@Override @Override
@ -40,12 +41,14 @@ public class PostRecyclerViewAdapter extends RecyclerView.Adapter<PostRecyclerVi
public class ViewHolder extends RecyclerView.ViewHolder { public class ViewHolder extends RecyclerView.ViewHolder {
public final TextView username; public final TextView username;
public final TextView content; public final TextView content;
public final TextView likes;
public Post mItem; public Post mItem;
public ViewHolder(@NonNull FragmentPostBinding binding) { public ViewHolder(@NonNull FragmentPostBinding binding) {
super(binding.getRoot()); super(binding.getRoot());
username = binding.username; username = binding.username;
content = binding.content; content = binding.content;
likes = binding.likes;
} }
@NonNull @NonNull

View File

@ -0,0 +1,48 @@
package com.dowerx.quack;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
public class ProfileFragment extends Fragment {
private static final String ARG_PARAM1 = "userid";
private String userID;
public ProfileFragment() {
// Required empty public constructor
}
public static ProfileFragment newInstance(String param1) {
ProfileFragment fragment = new ProfileFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
userID = getArguments().getString(ARG_PARAM1);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_profile, container, false);
getParentFragmentManager()
.beginTransaction()
.replace(R.id.profile_posts_holder, new FeedFragment())
.commit();
return view;
}
}

View File

@ -34,12 +34,17 @@ public class SwitcherActivity extends AppCompatActivity implements NavigationBar
@Override @Override
public void onNavigationItemReselected(@NonNull MenuItem menuItem) { public void onNavigationItemReselected(@NonNull MenuItem menuItem) {
this.onNavigationItemSelected(menuItem);
} }
@Override @Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
return false; if (menuItem.getItemId() == R.id.nav_feed) {
loadFragment(new FeedFragment());
} else if (menuItem.getItemId() == R.id.nav_profile) {
loadFragment(new ProfileFragment());
}
return true;
} }
private void loadFragment(Fragment fragment) { private void loadFragment(Fragment fragment) {

View File

@ -11,7 +11,19 @@ public class Post {
static { static {
ITEMS = Arrays.asList( ITEMS = Arrays.asList(
new Post(new User("username 1", "exmaple@example.com", "random_id"), "some content", null, 69, false, "random post id"), new Post(new User("username 1", "exmaple@example.com", "random_id"), "some content", null, 69, false, "random post id"),
new Post(new User("username 1", "exmaple@example.com", "random_id"), "some content", null, 69, false, "random post id") new Post(new User("username 1", "exmaple@example.com", "random_id"), "some content", null, 69, false, "random post id"),
new Post(new User("username 1", "exmaple@example.com", "random_id"), "some content", null, 69, false, "random post id"),
new Post(new User("username 1", "exmaple@example.com", "random_id"), "some content", null, 69, false, "random post id"),
new Post(new User("username 1", "exmaple@example.com", "random_id"), "some content", null, 69, false, "random post id"),
new Post(new User("username 1", "exmaple@example.com", "random_id"), "some content", null, 69, false, "random post id"),
new Post(new User("username 1", "exmaple@example.com", "random_id"), "some content", null, 69, false, "random post id"),
new Post(new User("username 1", "exmaple@example.com", "random_id"), "some content", null, 69, false, "random post id"),
new Post(new User("username 1", "exmaple@example.com", "random_id"), "some content", null, 69, false, "random post id"),
new Post(new User("username 1", "exmaple@example.com", "random_id"), "some content", null, 69, false, "random post id"),
new Post(new User("username 1", "exmaple@example.com", "random_id"), "some content", null, 69, false, "random post id"),
new Post(new User("username 1", "exmaple@example.com", "random_id"), "some content", null, 69, false, "random post id"),
new Post(new User("username 1", "exmaple@example.com", "random_id"), "some content", null, 69, false, "random post id"),
new Post(new User("username 2", "exmaple@example.com", "random_id2"), "some content 2", null, 69, false, "random post id2")
); );
} }

View File

@ -10,10 +10,10 @@
android:id="@+id/username" android:id="@+id/username"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/placeholder_name" android:text="@string/placeholder_name"
android:layout_marginTop="20dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.10" app:layout_constraintHorizontal_bias="0.067"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
@ -24,4 +24,16 @@
android:text="some random placeeholder post content" android:text="some random placeeholder post content"
app:layout_constraintTop_toBottomOf="@+id/username" app:layout_constraintTop_toBottomOf="@+id/username"
android:layout_margin="20dp"/> android:layout_margin="20dp"/>
<TextView
android:id="@+id/likes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_marginTop="20dp"
android:text="Likes 0"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/content" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ProfileFragment">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:padding="20dp">
<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>
<FrameLayout
android:id="@+id/profile_posts_holder"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/constraintLayout" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -12,4 +12,6 @@
<string name="profile">Profile</string> <string name="profile">Profile</string>
<string name="search">Search</string> <string name="search">Search</string>
<string name="placeholder_name">placeholder_name</string> <string name="placeholder_name">placeholder_name</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources> </resources>