Skip to content

Commit

Permalink
added layout for DayFragment
Browse files Browse the repository at this point in the history
  • Loading branch information
Krithic Kumar committed Sep 20, 2020
1 parent 7189548 commit cedf2a3
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 21 deletions.
60 changes: 60 additions & 0 deletions app/src/main/java/com/attendancemanager/TimeTableAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.attendancemanager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;
import java.util.Locale;

public class TimeTableAdapter extends RecyclerView.Adapter<TimeTableAdapter.TimeTableViewHolder> {

private List<Subject> mSubjectList;

public TimeTableAdapter(List<Subject> mSubjectList) {
this.mSubjectList = mSubjectList;
}

@NonNull
@Override
public TimeTableViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.time_table_row, parent, false);
return new TimeTableViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull TimeTableViewHolder holder, int position) {

Subject subject = mSubjectList.get(position);
int percentage = subject.getTotalClasses() == 0 ? 0 : Math.round(((float) subject.getAttendedClasses()
/ (float) subject.getTotalClasses()) * 100);

holder.mPosition.setText(String.valueOf(position + 1));
holder.mSubjectName.setText(subject.getSubjectName());
holder.mAttendancePercentage.setText(String.format(Locale.US, "%d%%", percentage));
}

@Override
public int getItemCount() {
return mSubjectList.size();
}

public static class TimeTableViewHolder extends RecyclerView.ViewHolder {

private TextView mPosition;
private TextView mSubjectName;
private TextView mAttendancePercentage;

public TimeTableViewHolder(@NonNull View itemView) {
super(itemView);

mPosition = itemView.findViewById(R.id.subject_position);
mSubjectName = itemView.findViewById(R.id.time_table_subject_name);
mAttendancePercentage = itemView.findViewById(R.id.time_table_attendance_percentage);
}
}
}
45 changes: 38 additions & 7 deletions app/src/main/java/com/attendancemanager/TimeTableFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,34 @@
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class TimeTableFragment extends Fragment {

public static final String[] DAY_NAMES = new String[]{"Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday", "Sunday"};
private static final String TAG = "TimeTableFragment";
private Toolbar toolbar;
private TabLayout tabLayout;
private ViewPager viewPager;

private static final String TAG = "TimeTableFragment";
public static final String[] DAY_NAMES = new String[] {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};

public TimeTableFragment() {
// Required empty public constructor
}
Expand All @@ -44,6 +51,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

toolbar = view.findViewById(R.id.time_table_toolbar);
tabLayout = view.findViewById(R.id.tab_layout);
viewPager = view.findViewById(R.id.day_view_pager);
}
Expand All @@ -53,17 +61,30 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

TimeTableViewPagerAdapter pagerAdapter = new TimeTableViewPagerAdapter(getChildFragmentManager(), FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
toolbar.setTitleTextAppearance(getContext(), R.style.RubixFontStyle);
TimeTableViewPagerAdapter pagerAdapter = new TimeTableViewPagerAdapter(getChildFragmentManager(),
FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
viewPager.setAdapter(pagerAdapter);
tabLayout.setupWithViewPager(viewPager);
Calendar calendar = Calendar.getInstance();
Date date = new Date();
calendar.setTime(date);
viewPager.setCurrentItem((calendar.get(Calendar.DAY_OF_WEEK) + 12) % 7);

}

public static class DayFragment extends Fragment {

private static final String ARG_DAY_NAME = "argDayName";
private RecyclerView timeTableRecyclerView;
private TimeTableAdapter timeTableAdapter;
private DBHelper dbHelper;
private List<Subject> daySubjectList;
private String getArgDayName;

public static DayFragment newInstance(String day) {
/* Create new instance with the ARG_DAY_NAME */

DayFragment dayFragment = new DayFragment();
final Bundle args = new Bundle();
args.putString(ARG_DAY_NAME, day);
Expand All @@ -74,23 +95,33 @@ public static DayFragment newInstance(String day) {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String dayName = getArguments().getString(ARG_DAY_NAME);
getArgDayName = getArguments().getString(ARG_DAY_NAME);
}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_day, container, false);
}

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

timeTableRecyclerView = view.findViewById(R.id.time_table_recycler_view);
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

dbHelper = new DBHelper(getContext());
daySubjectList = dbHelper.getSubjectsOfDay(getArgDayName);
timeTableAdapter = new TimeTableAdapter(daySubjectList);
timeTableRecyclerView.setAdapter(timeTableAdapter);
timeTableRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
timeTableRecyclerView.setHasFixedSize(true);
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_edit_subject.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<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:background="@color/white"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
tools:context=".EditSubjectActivity">

<androidx.appcompat.widget.Toolbar
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/edit_subject_list_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:indeterminateOnly="false"
android:progress="50"
android:progressDrawable="@drawable/circular_progress_bar"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
tools:progress="50" />

<TextView
android:id="@+id/edit_subject_progressbar_percentage"
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/res/layout/fragment_day.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/time_table_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Hello" />
tools:listitem="@layout/time_table_row" />

</androidx.constraintlayout.widget.ConstraintLayout>
8 changes: 5 additions & 3 deletions app/src/main/res/layout/fragment_time_table.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@
android:background="@color/colorPinkPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
app:title="Time Table"
app:titleTextColor="@color/light_black" />

<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPinkPrimary"
app:tabTextAppearance="@style/TabButton.App.Theme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/time_table_toolbar"
app:tabMode="scrollable" />
app:tabMode="scrollable"
app:tabTextAppearance="@style/TabButton.App.Theme" />

<androidx.viewpager.widget.ViewPager
android:id="@+id/day_view_pager"
Expand Down
69 changes: 69 additions & 0 deletions app/src/main/res/layout/time_table_row.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="wrap_content">

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
app:cardCornerRadius="16dp">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/subject_position"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginStart="16sp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:background="@drawable/circle_button_bg"
android:backgroundTint="@color/colorPinkPrimaryDark"
android:fontFamily="@font/rubik"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="1" />

<TextView
android:id="@+id/time_table_subject_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:fontFamily="@font/raleway_semibold"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/subject_position"
app:layout_constraintTop_toTopOf="parent"
tools:text="English" />

<TextView
android:id="@+id/time_table_attendance_percentage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:fontFamily="@font/raleway_semibold"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="75%" />

</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.cardview.widget.CardView>

</LinearLayout>
7 changes: 2 additions & 5 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- General-->
<string name="app_name">Attendance Manager</string>
<string name="developer_name">Krithic Kumar</string>
<string name="app_version_number">0.5.0-alpha04</string>
<string name="app_version_number">0.6.0-alpha02</string>
<string name="time_table">Time Table</string>
<string name="home">Home</string>
<string name="settings">Settings</string>
Expand Down Expand Up @@ -47,9 +47,6 @@
<string name="add_subject">Add subject</string>
<string name="subject_name">Subject Name</string>
<string name="total_classes">Total Classes</string>
<string name="title_activity_about">FullscreenActivity</string>
<string name="title_activity_main2">MainActivity2</string>
<string name="tab_text_1">Tab 1</string>
<string name="tab_text_2">Tab 2</string>
<string name="title_activity_about">AboutActivity</string>

</resources>

0 comments on commit cedf2a3

Please sign in to comment.