From 2c8952274ac6069be4353e62b250514370f1edc3 Mon Sep 17 00:00:00 2001 From: Ashuh Date: Fri, 14 Oct 2022 12:09:36 +0800 Subject: [PATCH 1/2] Add new color scheme settings page --- app/build.gradle | 1 + .../settings/ColorSchemePreference.java | 88 +++++++++++++++++++ .../settings/ColorSchemeSettingsFragment.java | 19 ++++ .../settings/ColorSchemeView.java | 79 +++++++++++++++++ .../settings/NoMenuPreferenceFragment.java | 21 +++++ .../settings/SettingsFragment.java | 40 +++------ .../main/res/drawable/color_scheme_btn.xml | 15 ++++ .../res/drawable/ic_outline_palette_24.xml | 9 ++ .../main/res/layout/color_scheme_layout.xml | 35 ++++++++ .../color_scheme_preferences_layout.xml | 8 ++ .../main/res/navigation/mobile_navigation.xml | 14 ++- app/src/main/res/values-night/themes.xml | 5 +- app/src/main/res/values/attrs.xml | 4 + app/src/main/res/values/colors.xml | 2 + app/src/main/res/values/themes.xml | 3 +- .../main/res/xml/color_scheme_preferences.xml | 9 ++ app/src/main/res/xml/preferences.xml | 18 ++-- 17 files changed, 327 insertions(+), 43 deletions(-) create mode 100644 app/src/main/java/com/ashuh/nusmoduleplanner/settings/ColorSchemePreference.java create mode 100644 app/src/main/java/com/ashuh/nusmoduleplanner/settings/ColorSchemeSettingsFragment.java create mode 100644 app/src/main/java/com/ashuh/nusmoduleplanner/settings/ColorSchemeView.java create mode 100644 app/src/main/java/com/ashuh/nusmoduleplanner/settings/NoMenuPreferenceFragment.java create mode 100644 app/src/main/res/drawable/color_scheme_btn.xml create mode 100644 app/src/main/res/drawable/ic_outline_palette_24.xml create mode 100644 app/src/main/res/layout/color_scheme_layout.xml create mode 100644 app/src/main/res/layout/color_scheme_preferences_layout.xml create mode 100644 app/src/main/res/values/attrs.xml create mode 100644 app/src/main/res/xml/color_scheme_preferences.xml diff --git a/app/build.gradle b/app/build.gradle index 20efbde..7790724 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -70,6 +70,7 @@ dependencies { implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0' implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' implementation 'androidx.preference:preference:1.2.0' + implementation 'androidx.gridlayout:gridlayout:1.0.0' implementation "androidx.room:room-runtime:$room_version" annotationProcessor "androidx.room:room-compiler:$room_version" diff --git a/app/src/main/java/com/ashuh/nusmoduleplanner/settings/ColorSchemePreference.java b/app/src/main/java/com/ashuh/nusmoduleplanner/settings/ColorSchemePreference.java new file mode 100644 index 0000000..1bd0b22 --- /dev/null +++ b/app/src/main/java/com/ashuh/nusmoduleplanner/settings/ColorSchemePreference.java @@ -0,0 +1,88 @@ +package com.ashuh.nusmoduleplanner.settings; + +import android.content.Context; +import android.content.res.TypedArray; +import android.util.AttributeSet; +import android.util.TypedValue; +import android.view.Gravity; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.gridlayout.widget.GridLayout; +import androidx.preference.Preference; +import androidx.preference.PreferenceViewHolder; + +import com.ashuh.nusmoduleplanner.common.util.ColorScheme; + +public class ColorSchemePreference extends Preference { + private static final int MARGIN_DP = 4; + + private ColorScheme colorScheme; + + public ColorSchemePreference(@NonNull Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + } + + @Nullable + @Override + protected Object onGetDefaultValue(@NonNull TypedArray a, int index) { + return a.getString(index); + } + + @Override + public void onBindViewHolder(@NonNull PreferenceViewHolder holder) { + GridLayout gridLayout = (GridLayout) holder.itemView; + + if (gridLayout.getChildCount() == 0) { + for (int i = 0; i < ColorScheme.values().length; i++) { + ColorScheme colorScheme = ColorScheme.values()[i]; + ColorSchemeView colorSchemeView = generateColorSchemeView(colorScheme, i); + gridLayout.addView(colorSchemeView); + } + } else { + for (int i = 0; i < gridLayout.getChildCount(); i++) { + ColorSchemeView child = (ColorSchemeView) gridLayout.getChildAt(i); + child.setSelected(this.colorScheme == child.getColorScheme()); + } + } + } + + private ColorSchemeView generateColorSchemeView(ColorScheme colorScheme, int index) { + ColorSchemeView colorSchemeView = new ColorSchemeView(getContext()); + colorSchemeView.setColorScheme(colorScheme); + colorSchemeView.setLayoutParams(getLayoutParams(index)); + colorSchemeView.setSelected(this.colorScheme == colorScheme); + colorSchemeView.setOnClickListener(v -> setColorScheme(colorScheme)); + return colorSchemeView; + } + + private GridLayout.LayoutParams getLayoutParams(int index) { + GridLayout.LayoutParams param = new GridLayout.LayoutParams(); + param.columnSpec = GridLayout.spec(index % 2, GridLayout.FILL, 1); + param.rowSpec = GridLayout.spec(index / 2, GridLayout.FILL, 1); + param.setGravity(Gravity.FILL_HORIZONTAL); + int marginPx = getMarginPx(); + param.setMargins(marginPx, marginPx, marginPx, marginPx); + return param; + } + + private void setColorScheme(@NonNull ColorScheme colorScheme) { + this.colorScheme = colorScheme; + persistString(colorScheme.name()); + notifyChanged(); + } + + private int getMarginPx() { + return (int) TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_DIP, + MARGIN_DP, + getContext().getResources().getDisplayMetrics() + ); + } + + @Override + protected void onSetInitialValue(@Nullable Object defaultValue) { + ColorScheme colorScheme = ColorScheme.valueOf(getPersistedString((String) defaultValue)); + setColorScheme(colorScheme); + } +} diff --git a/app/src/main/java/com/ashuh/nusmoduleplanner/settings/ColorSchemeSettingsFragment.java b/app/src/main/java/com/ashuh/nusmoduleplanner/settings/ColorSchemeSettingsFragment.java new file mode 100644 index 0000000..c426629 --- /dev/null +++ b/app/src/main/java/com/ashuh/nusmoduleplanner/settings/ColorSchemeSettingsFragment.java @@ -0,0 +1,19 @@ +package com.ashuh.nusmoduleplanner.settings; + +import static com.ashuh.nusmoduleplanner.common.data.preferences.SharedPreferencesManager.PREFERENCE_FILE_KEY; + +import android.os.Bundle; + +import androidx.annotation.Nullable; +import androidx.preference.PreferenceManager; + +import com.ashuh.nusmoduleplanner.R; + +public class ColorSchemeSettingsFragment extends NoMenuPreferenceFragment { + @Override + public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) { + PreferenceManager manager = getPreferenceManager(); + manager.setSharedPreferencesName(PREFERENCE_FILE_KEY); + setPreferencesFromResource(R.xml.color_scheme_preferences, rootKey); + } +} diff --git a/app/src/main/java/com/ashuh/nusmoduleplanner/settings/ColorSchemeView.java b/app/src/main/java/com/ashuh/nusmoduleplanner/settings/ColorSchemeView.java new file mode 100644 index 0000000..5164fc7 --- /dev/null +++ b/app/src/main/java/com/ashuh/nusmoduleplanner/settings/ColorSchemeView.java @@ -0,0 +1,79 @@ +package com.ashuh.nusmoduleplanner.settings; + +import static java.util.Objects.requireNonNull; + +import android.content.Context; +import android.graphics.Color; +import android.util.AttributeSet; +import android.util.TypedValue; +import android.view.View; +import android.widget.FrameLayout; +import android.widget.LinearLayout; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.ashuh.nusmoduleplanner.R; +import com.ashuh.nusmoduleplanner.common.util.ColorScheme; + +import java.util.List; +import java.util.stream.Collectors; + +public class ColorSchemeView extends FrameLayout { + private static final int BOX_SIZE_DP = 20; + + private ColorScheme colorScheme; + + public ColorSchemeView(@NonNull Context context) { + super(context); + init(context); + } + + private void init(Context context) { + View.inflate(context, R.layout.color_scheme_layout, this); + setClickable(true); + setBackgroundResource(R.drawable.color_scheme_btn); + TypedValue outValue = new TypedValue(); + context.getTheme() + .resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); + } + + public ColorSchemeView(@NonNull Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + init(context); + } + + public ColorScheme getColorScheme() { + return colorScheme; + } + + public void setColorScheme(@NonNull ColorScheme colorScheme) { + requireNonNull(colorScheme); + this.colorScheme = colorScheme; + + List colors = colorScheme.getColors().stream() + .map(Color::toArgb) + .collect(Collectors.toList()); + + TextView nameView = findViewById(R.id.name); + nameView.setText(colorScheme.toString()); + + LinearLayout colorsView = findViewById(R.id.colors); + colorsView.removeAllViews(); + + int px = (int) TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_DIP, + BOX_SIZE_DP, + getResources().getDisplayMetrics() + ); + + for (Integer s : colors) { + View a = new View(getContext()); + a.setBackgroundColor(s); + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(px, px); + a.setLayoutParams(params); + colorsView.addView(a); + } + } +} diff --git a/app/src/main/java/com/ashuh/nusmoduleplanner/settings/NoMenuPreferenceFragment.java b/app/src/main/java/com/ashuh/nusmoduleplanner/settings/NoMenuPreferenceFragment.java new file mode 100644 index 0000000..46d5e01 --- /dev/null +++ b/app/src/main/java/com/ashuh/nusmoduleplanner/settings/NoMenuPreferenceFragment.java @@ -0,0 +1,21 @@ +package com.ashuh.nusmoduleplanner.settings; + +import android.os.Bundle; +import android.view.Menu; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.preference.PreferenceFragmentCompat; + +public abstract class NoMenuPreferenceFragment extends PreferenceFragmentCompat { + @Override + public void onPrepareOptionsMenu(@NonNull Menu menu) { + menu.clear(); + } + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setHasOptionsMenu(true); + } +} diff --git a/app/src/main/java/com/ashuh/nusmoduleplanner/settings/SettingsFragment.java b/app/src/main/java/com/ashuh/nusmoduleplanner/settings/SettingsFragment.java index fa53d2c..ce6aabc 100644 --- a/app/src/main/java/com/ashuh/nusmoduleplanner/settings/SettingsFragment.java +++ b/app/src/main/java/com/ashuh/nusmoduleplanner/settings/SettingsFragment.java @@ -3,47 +3,27 @@ import static com.ashuh.nusmoduleplanner.common.data.preferences.SharedPreferencesManager.PREFERENCE_FILE_KEY; import android.os.Bundle; -import android.view.Menu; -import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.preference.ListPreference; -import androidx.preference.PreferenceFragmentCompat; +import androidx.navigation.Navigation; +import androidx.preference.Preference; import androidx.preference.PreferenceManager; import com.ashuh.nusmoduleplanner.R; -import com.ashuh.nusmoduleplanner.common.util.ColorScheme; - -import java.util.Arrays; - -public class SettingsFragment extends PreferenceFragmentCompat { - @Override - public void onPrepareOptionsMenu(@NonNull Menu menu) { - menu.clear(); - } - - @Override - public void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setHasOptionsMenu(true); - } +public class SettingsFragment extends NoMenuPreferenceFragment { @Override public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) { PreferenceManager manager = getPreferenceManager(); manager.setSharedPreferencesName(PREFERENCE_FILE_KEY); setPreferencesFromResource(R.xml.preferences, rootKey); - ListPreference colorSchemePreference = findPreference("color_scheme"); - assert colorSchemePreference != null; - ColorScheme[] colorSchemes = ColorScheme.values(); - CharSequence[] entries = Arrays.stream(colorSchemes) - .map(ColorScheme::toString) - .toArray(CharSequence[]::new); - CharSequence[] entryValues = Arrays.stream(colorSchemes) - .map(ColorScheme::name) - .toArray(CharSequence[]::new); - colorSchemePreference.setEntries(entries); - colorSchemePreference.setEntryValues(entryValues); + Preference colorSchemePreference = findPreference("color_scheme"); + assert colorSchemePreference != null; + colorSchemePreference.setOnPreferenceClickListener(preference -> { + Navigation.findNavController(requireActivity(), R.id.nav_host_fragment) + .navigate(R.id.action_nav_settings_main_to_colorSchemeSettingsFragment); + return true; + }); } } diff --git a/app/src/main/res/drawable/color_scheme_btn.xml b/app/src/main/res/drawable/color_scheme_btn.xml new file mode 100644 index 0000000..34bbad7 --- /dev/null +++ b/app/src/main/res/drawable/color_scheme_btn.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_outline_palette_24.xml b/app/src/main/res/drawable/ic_outline_palette_24.xml new file mode 100644 index 0000000..35c0f61 --- /dev/null +++ b/app/src/main/res/drawable/ic_outline_palette_24.xml @@ -0,0 +1,9 @@ + + + + + + + diff --git a/app/src/main/res/layout/color_scheme_layout.xml b/app/src/main/res/layout/color_scheme_layout.xml new file mode 100644 index 0000000..a4be229 --- /dev/null +++ b/app/src/main/res/layout/color_scheme_layout.xml @@ -0,0 +1,35 @@ + + + + + + + diff --git a/app/src/main/res/layout/color_scheme_preferences_layout.xml b/app/src/main/res/layout/color_scheme_preferences_layout.xml new file mode 100644 index 0000000..a94cf92 --- /dev/null +++ b/app/src/main/res/layout/color_scheme_preferences_layout.xml @@ -0,0 +1,8 @@ + + diff --git a/app/src/main/res/navigation/mobile_navigation.xml b/app/src/main/res/navigation/mobile_navigation.xml index e91afaf..2f491df 100644 --- a/app/src/main/res/navigation/mobile_navigation.xml +++ b/app/src/main/res/navigation/mobile_navigation.xml @@ -37,8 +37,20 @@ + android:label="Settings" > + + + diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index 09c0c1a..76a2b6e 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -10,7 +10,7 @@ @color/secondaryVariant @color/dark_onSecondary - ?attr/colorPrimaryVariant + ?attr/colorPrimaryVariant @color/dark_background @color/dark_error @@ -18,7 +18,8 @@ @color/dark_surface @color/dark_onSurface @color/dark_onBackground + @color/dark_colorOnBackgroundSelected @color/amber_900 12sp - \ No newline at end of file + diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml new file mode 100644 index 0000000..f81392f --- /dev/null +++ b/app/src/main/res/values/attrs.xml @@ -0,0 +1,4 @@ + + + + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 0cc24a9..cac553d 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -19,6 +19,7 @@ #000000 #000000 #FFFFFF + #d3d6db #121212 #121212 @@ -28,4 +29,5 @@ #FFFFFF #FFFFFF #000000 + #474747 diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 2cfead5..ab63223 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -10,7 +10,7 @@ @color/secondaryVariant @color/onSecondary - ?attr/colorPrimaryVariant + ?attr/colorPrimaryVariant @color/error @color/dark_onError @@ -18,6 +18,7 @@ @color/onSurface @color/background @color/onBackground + @color/colorOnBackgroundSelected @color/amber_900 12sp diff --git a/app/src/main/res/xml/color_scheme_preferences.xml b/app/src/main/res/xml/color_scheme_preferences.xml new file mode 100644 index 0000000..d4fb093 --- /dev/null +++ b/app/src/main/res/xml/color_scheme_preferences.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index ce4aa4c..de2cb1e 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -1,19 +1,19 @@ - + + app:title="Enable message notifications" /> + app:summary="Report technical issues or suggest new features" + app:title="Send feedback" /> - - + app:summary="Liven up your timetable with different color schemes!" + app:title="Theme" + android:icon="@drawable/ic_outline_palette_24"/> From 968b42b711056b6bfcf2adb97907a9f1f1860e12 Mon Sep 17 00:00:00 2001 From: Ashuh Date: Sat, 15 Oct 2022 11:12:13 +0800 Subject: [PATCH 2/2] Add timetable theme preview --- .../settings/ColorSchemePreference.java | 23 ++-- .../settings/TimetableSampleDataLoader.java | 102 ++++++++++++++++++ .../timetable/presentation/TimetableView.java | 19 ---- .../presentation/TimetableViewModel.java | 10 +- .../model/UiTimetableLessonOccurrence.java | 26 ++++- .../color_scheme_preferences_layout.xml | 44 +++++++- .../res/layout/fragment_timetable_tab.xml | 7 ++ 7 files changed, 189 insertions(+), 42 deletions(-) create mode 100644 app/src/main/java/com/ashuh/nusmoduleplanner/settings/TimetableSampleDataLoader.java diff --git a/app/src/main/java/com/ashuh/nusmoduleplanner/settings/ColorSchemePreference.java b/app/src/main/java/com/ashuh/nusmoduleplanner/settings/ColorSchemePreference.java index 1bd0b22..47e1668 100644 --- a/app/src/main/java/com/ashuh/nusmoduleplanner/settings/ColorSchemePreference.java +++ b/app/src/main/java/com/ashuh/nusmoduleplanner/settings/ColorSchemePreference.java @@ -12,11 +12,14 @@ import androidx.preference.Preference; import androidx.preference.PreferenceViewHolder; +import com.ashuh.nusmoduleplanner.R; import com.ashuh.nusmoduleplanner.common.util.ColorScheme; +import com.ashuh.nusmoduleplanner.timetable.presentation.TimetableView; public class ColorSchemePreference extends Preference { private static final int MARGIN_DP = 4; + private final TimetableSampleDataLoader loader = new TimetableSampleDataLoader(); private ColorScheme colorScheme; public ColorSchemePreference(@NonNull Context context, @Nullable AttributeSet attrs) { @@ -31,9 +34,12 @@ protected Object onGetDefaultValue(@NonNull TypedArray a, int index) { @Override public void onBindViewHolder(@NonNull PreferenceViewHolder holder) { - GridLayout gridLayout = (GridLayout) holder.itemView; + TimetableView timetableView = (TimetableView) holder.findViewById(R.id.timetable); + GridLayout gridLayout = (GridLayout) holder.findViewById(R.id.grid); if (gridLayout.getChildCount() == 0) { + timetableView.setWeekViewLoader(loader); + for (int i = 0; i < ColorScheme.values().length; i++) { ColorScheme colorScheme = ColorScheme.values()[i]; ColorSchemeView colorSchemeView = generateColorSchemeView(colorScheme, i); @@ -45,6 +51,15 @@ public void onBindViewHolder(@NonNull PreferenceViewHolder holder) { child.setSelected(this.colorScheme == child.getColorScheme()); } } + + loader.setColorScheme(colorScheme); + timetableView.notifyDatasetChanged(); + } + + @Override + protected void onSetInitialValue(@Nullable Object defaultValue) { + ColorScheme colorScheme = ColorScheme.valueOf(getPersistedString((String) defaultValue)); + setColorScheme(colorScheme); } private ColorSchemeView generateColorSchemeView(ColorScheme colorScheme, int index) { @@ -79,10 +94,4 @@ private int getMarginPx() { getContext().getResources().getDisplayMetrics() ); } - - @Override - protected void onSetInitialValue(@Nullable Object defaultValue) { - ColorScheme colorScheme = ColorScheme.valueOf(getPersistedString((String) defaultValue)); - setColorScheme(colorScheme); - } } diff --git a/app/src/main/java/com/ashuh/nusmoduleplanner/settings/TimetableSampleDataLoader.java b/app/src/main/java/com/ashuh/nusmoduleplanner/settings/TimetableSampleDataLoader.java new file mode 100644 index 0000000..4f9e0bb --- /dev/null +++ b/app/src/main/java/com/ashuh/nusmoduleplanner/settings/TimetableSampleDataLoader.java @@ -0,0 +1,102 @@ +package com.ashuh.nusmoduleplanner.settings; + +import androidx.annotation.NonNull; + +import com.ashuh.nusmoduleplanner.common.domain.model.module.lesson.LessonType; +import com.ashuh.nusmoduleplanner.common.util.ColorScheme; +import com.ashuh.nusmoduleplanner.timetable.presentation.model.UiTimetableLessonOccurrence; + +import org.threeten.bp.DayOfWeek; + +import java.util.List; + +import me.jlurena.revolvingweekview.DayTime; +import me.jlurena.revolvingweekview.WeekView; +import me.jlurena.revolvingweekview.WeekViewEvent; + +public class TimetableSampleDataLoader implements WeekView.WeekViewLoader { + private static final UiTimetableLessonOccurrence SAMPLE_COLOR_0_1 + = UiTimetableLessonOccurrence.create( + "COM1-B113", + new DayTime(DayOfWeek.TUESDAY, 10, 0), + new DayTime(DayOfWeek.TUESDAY, 11, 0), + "CS3235", + LessonType.TUTORIAL, + "2", 0); + + private static final UiTimetableLessonOccurrence SAMPLE_COLOR_0_2 + = UiTimetableLessonOccurrence.create( + "COM1-B113", + new DayTime(DayOfWeek.TUESDAY, 14, 0), + new DayTime(DayOfWeek.TUESDAY, 16, 0), + "CS3235", + LessonType.LECTURE, + "1", 0); + + private static final UiTimetableLessonOccurrence SAMPLE_COLOR_2 + = UiTimetableLessonOccurrence.create( + "AS1-0207", + new DayTime(DayOfWeek.WEDNESDAY, 10, 0), + new DayTime(DayOfWeek.WEDNESDAY, 12, 0), + "GER1000", + LessonType.TUTORIAL, + "A19", 0); + + private static final UiTimetableLessonOccurrence SAMPLE_COLOR_4 + = UiTimetableLessonOccurrence.create( + "i3-Aud", + new DayTime(DayOfWeek.WEDNESDAY, 12, 0), + new DayTime(DayOfWeek.WEDNESDAY, 14, 0), + "CS2100", + LessonType.LECTURE, + "1", 0); + + private static final UiTimetableLessonOccurrence SAMPLE_COLOR_6 + = UiTimetableLessonOccurrence.create( + "BIZ2-0509", + new DayTime(DayOfWeek.MONDAY, 10, 0), + new DayTime(DayOfWeek.MONDAY, 13, 0), + "ACC1006", + LessonType.SECTIONAL, + "1", 0); + + private static final UiTimetableLessonOccurrence SAMPLE_COLOR_7_1 + = UiTimetableLessonOccurrence.create( + "i3-Aud", + new DayTime(DayOfWeek.MONDAY, 14, 0), + new DayTime(DayOfWeek.MONDAY, 16, 0), + "CS2108", + LessonType.LECTURE, + "1", 0); + + private static final UiTimetableLessonOccurrence SAMPLE_COLOR_7_2 + = UiTimetableLessonOccurrence.create( + "COM1-0208", + new DayTime(DayOfWeek.TUESDAY, 11, 0), + new DayTime(DayOfWeek.TUESDAY, 12, 0), + "CS2108", + LessonType.TUTORIAL, + "2", 0); + + @Override + public List onWeekViewLoad() { + return List.of(SAMPLE_COLOR_0_1, SAMPLE_COLOR_0_2, SAMPLE_COLOR_2, SAMPLE_COLOR_4, + SAMPLE_COLOR_6, SAMPLE_COLOR_7_1, SAMPLE_COLOR_7_2); + } + + public void setColorScheme(@NonNull ColorScheme colorScheme) { + int color0 = colorScheme.getColor(new ColorScheme.Index(0)).toArgb(); + int color2 = colorScheme.getColor(new ColorScheme.Index(2)).toArgb(); + int color4 = colorScheme.getColor(new ColorScheme.Index(4)).toArgb(); + int color6 = colorScheme.getColor(new ColorScheme.Index(6)).toArgb(); + int color7 = colorScheme.getColor(new ColorScheme.Index(7)).toArgb(); + + SAMPLE_COLOR_0_1.setColor(color0); + SAMPLE_COLOR_0_2.setColor(color0); + SAMPLE_COLOR_2.setColor(color2); + SAMPLE_COLOR_4.setColor(color4); + SAMPLE_COLOR_6.setColor(color6); + SAMPLE_COLOR_7_1.setColor(color7); + SAMPLE_COLOR_7_2.setColor(color7); + } +} diff --git a/app/src/main/java/com/ashuh/nusmoduleplanner/timetable/presentation/TimetableView.java b/app/src/main/java/com/ashuh/nusmoduleplanner/timetable/presentation/TimetableView.java index 57b6a22..8e18e22 100644 --- a/app/src/main/java/com/ashuh/nusmoduleplanner/timetable/presentation/TimetableView.java +++ b/app/src/main/java/com/ashuh/nusmoduleplanner/timetable/presentation/TimetableView.java @@ -2,7 +2,6 @@ import android.content.Context; import android.util.AttributeSet; -import android.util.TypedValue; import org.threeten.bp.DayOfWeek; @@ -12,33 +11,15 @@ import me.jlurena.revolvingweekview.WeekView; public class TimetableView extends WeekView { - private static final int HOUR_TIMETABLE_START = 8; - private static final int HOUR_TIMETABLE_END = 22; private static final int HOUR_NOON = 12; - private static final int TEXT_SIZE = 12; - private static final int TEXT_SIZE_EVENT = 10; - public TimetableView(Context context) { super(context); init(); } private void init() { - setHorizontalFlingEnabled(false); goToDate(DayOfWeek.MONDAY); - setMinTime(HOUR_TIMETABLE_START); - setMaxTime(HOUR_TIMETABLE_END); - - setOverlappingEventGap( - (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, - getResources().getDisplayMetrics())); - setTextSize((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, TEXT_SIZE, - getResources().getDisplayMetrics())); - setEventTextSize( - (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, TEXT_SIZE_EVENT, - getResources().getDisplayMetrics())); - setDateTimeInterpreter(new TimetableDateTimeInterpreter()); } diff --git a/app/src/main/java/com/ashuh/nusmoduleplanner/timetable/presentation/TimetableViewModel.java b/app/src/main/java/com/ashuh/nusmoduleplanner/timetable/presentation/TimetableViewModel.java index 87c2088..9dea569 100644 --- a/app/src/main/java/com/ashuh/nusmoduleplanner/timetable/presentation/TimetableViewModel.java +++ b/app/src/main/java/com/ashuh/nusmoduleplanner/timetable/presentation/TimetableViewModel.java @@ -40,7 +40,6 @@ import me.jlurena.revolvingweekview.DayTime; public class TimetableViewModel extends ViewModel { - private static final String FORMAT_LESSON_OCCURRENCE_NAME = "%s\n[%s] %s"; private static final String FORMAT_DATE_RANGE = "%s-%s"; private static final String FORMAT_SINGLE_WEEK = "Week %d"; private static final String FORMAT_CONTINUOUS_WEEKS = "Weeks %d-%d"; @@ -151,13 +150,8 @@ private static UiTimetableLessonOccurrence buildTimetableLessonOccurrence( LessonType lessonType, String lessonNo, int color) { DayTime startTime = convertTime(occurrence.getDay(), occurrence.getStartTime()); DayTime endTime = convertTime(occurrence.getDay(), occurrence.getEndTime()); - String name = String.format(FORMAT_LESSON_OCCURRENCE_NAME, moduleCode, - lessonType.getShortName(), lessonNo); - UiTimetableLessonOccurrence uiOccurrence - = new UiTimetableLessonOccurrence(name, occurrence.getVenue(), startTime, - endTime, moduleCode, lessonType, lessonNo); - uiOccurrence.setColor(color); - return uiOccurrence; + return UiTimetableLessonOccurrence.create(occurrence.getVenue(), startTime, endTime, + moduleCode, lessonType, lessonNo, color); } private static DayTime convertTime(DayOfWeek day, LocalTime time) { diff --git a/app/src/main/java/com/ashuh/nusmoduleplanner/timetable/presentation/model/UiTimetableLessonOccurrence.java b/app/src/main/java/com/ashuh/nusmoduleplanner/timetable/presentation/model/UiTimetableLessonOccurrence.java index 9c72d20..cbf1e56 100644 --- a/app/src/main/java/com/ashuh/nusmoduleplanner/timetable/presentation/model/UiTimetableLessonOccurrence.java +++ b/app/src/main/java/com/ashuh/nusmoduleplanner/timetable/presentation/model/UiTimetableLessonOccurrence.java @@ -10,6 +10,7 @@ import me.jlurena.revolvingweekview.WeekViewEvent; public class UiTimetableLessonOccurrence extends WeekViewEvent { + private static final String FORMAT_NAME = "%s\n[%s] %s"; private static int id = 0; @NonNull @@ -19,9 +20,10 @@ public class UiTimetableLessonOccurrence extends WeekViewEvent { @NonNull private final String lessonNo; - public UiTimetableLessonOccurrence(String name, String location, DayTime startTime, - DayTime endTime, @NonNull String moduleCode, - @NonNull LessonType lessonType, @NonNull String lessonNo) { + private UiTimetableLessonOccurrence(@NonNull String name, @NonNull String location, + @NonNull DayTime startTime, @NonNull DayTime endTime, + @NonNull String moduleCode, @NonNull LessonType lessonType, + @NonNull String lessonNo) { super(generateId(), name, location, startTime, endTime); this.moduleCode = requireNonNull(moduleCode); this.lessonType = requireNonNull(lessonType); @@ -32,6 +34,24 @@ private static String generateId() { return String.valueOf(id++); } + public static UiTimetableLessonOccurrence create(@NonNull String location, + @NonNull DayTime startTime, + @NonNull DayTime endTime, + @NonNull String moduleCode, + @NonNull LessonType lessonType, + @NonNull String lessonNo, int color) { + String name = generateName(moduleCode, lessonType, lessonNo); + UiTimetableLessonOccurrence occurrence = new UiTimetableLessonOccurrence(name, location, + startTime, endTime, moduleCode, lessonType, lessonNo); + occurrence.setColor(color); + return occurrence; + } + + private static String generateName(@NonNull String moduleCode, @NonNull LessonType lessonType, + @NonNull String lessonNo) { + return String.format(FORMAT_NAME, moduleCode, lessonType.getShortName(), lessonNo); + } + @NonNull public String getModuleCode() { return moduleCode; diff --git a/app/src/main/res/layout/color_scheme_preferences_layout.xml b/app/src/main/res/layout/color_scheme_preferences_layout.xml index a94cf92..b21241f 100644 --- a/app/src/main/res/layout/color_scheme_preferences_layout.xml +++ b/app/src/main/res/layout/color_scheme_preferences_layout.xml @@ -1,8 +1,42 @@ - + android:layout_height="wrap_content"> + + + + + diff --git a/app/src/main/res/layout/fragment_timetable_tab.xml b/app/src/main/res/layout/fragment_timetable_tab.xml index 5b1f5b6..76c13e0 100644 --- a/app/src/main/res/layout/fragment_timetable_tab.xml +++ b/app/src/main/res/layout/fragment_timetable_tab.xml @@ -16,18 +16,25 @@ android:layout_height="0dp" app:dayBackgroundColor="#05000000" app:eventTextColor="@android:color/white" + app:eventTextSize="10sp" app:headerColumnPadding="8dp" app:headerColumnTextColor="?android:attr/textColorPrimary" app:headerRowBackgroundColor="?android:attr/colorBackground" app:headerRowPadding="12dp" + app:horizontalFlingEnabled="false" + app:horizontalScrollingEnabled="false" app:hourHeight="60dp" app:hourSeparatorColor="#00FFFFFF" app:layout_constraintBottom_toTopOf="@id/timetable_recycler_view" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" + app:maxTime="22" + app:minTime="8" app:noOfVisibleDays="5" + app:overlappingEventGap="2dp" app:showHeaderBottomLine="true" + app:textSize="12sp" app:todayBackgroundColor="#1848adff" tools:weekendHeaderTextColor="#FFFFFF" />