From cedf2a39751dcddf13c67db9639ae11945fdae8d Mon Sep 17 00:00:00 2001 From: Krithic Kumar Date: Sun, 20 Sep 2020 17:14:37 +0530 Subject: [PATCH] added layout for DayFragment --- .../attendancemanager/TimeTableAdapter.java | 60 ++++++++++++++++ .../attendancemanager/TimeTableFragment.java | 45 ++++++++++-- .../main/res/layout/activity_edit_subject.xml | 2 +- .../main/res/layout/edit_subject_list_row.xml | 4 +- app/src/main/res/layout/fragment_day.xml | 7 +- .../main/res/layout/fragment_time_table.xml | 8 ++- app/src/main/res/layout/time_table_row.xml | 69 +++++++++++++++++++ app/src/main/res/values/strings.xml | 7 +- 8 files changed, 181 insertions(+), 21 deletions(-) create mode 100644 app/src/main/java/com/attendancemanager/TimeTableAdapter.java create mode 100644 app/src/main/res/layout/time_table_row.xml diff --git a/app/src/main/java/com/attendancemanager/TimeTableAdapter.java b/app/src/main/java/com/attendancemanager/TimeTableAdapter.java new file mode 100644 index 0000000..7952c5b --- /dev/null +++ b/app/src/main/java/com/attendancemanager/TimeTableAdapter.java @@ -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 { + + private List mSubjectList; + + public TimeTableAdapter(List 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); + } + } +} diff --git a/app/src/main/java/com/attendancemanager/TimeTableFragment.java b/app/src/main/java/com/attendancemanager/TimeTableFragment.java index adda979..55eef7a 100644 --- a/app/src/main/java/com/attendancemanager/TimeTableFragment.java +++ b/app/src/main/java/com/attendancemanager/TimeTableFragment.java @@ -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 } @@ -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); } @@ -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 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); @@ -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); } } diff --git a/app/src/main/res/layout/activity_edit_subject.xml b/app/src/main/res/layout/activity_edit_subject.xml index 1e6b4b2..d6116db 100644 --- a/app/src/main/res/layout/activity_edit_subject.xml +++ b/app/src/main/res/layout/activity_edit_subject.xml @@ -2,9 +2,9 @@ + app:layout_constraintTop_toTopOf="parent" + tools:progress="50" /> - + tools:listitem="@layout/time_table_row" /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_time_table.xml b/app/src/main/res/layout/fragment_time_table.xml index 68996a1..94da275 100644 --- a/app/src/main/res/layout/fragment_time_table.xml +++ b/app/src/main/res/layout/fragment_time_table.xml @@ -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" /> + app:tabMode="scrollable" + app:tabTextAppearance="@style/TabButton.App.Theme" /> + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f575a4b..55a3389 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2,7 +2,7 @@ Attendance Manager Krithic Kumar - 0.5.0-alpha04 + 0.6.0-alpha02 Time Table Home Settings @@ -47,9 +47,6 @@ Add subject Subject Name Total Classes - FullscreenActivity - MainActivity2 - Tab 1 - Tab 2 + AboutActivity \ No newline at end of file