Skip to content

Commit 47dd918

Browse files
Address PR feedback: Fix calendar interaction and refine detail section
- Fixed date selection bug where only Monday was clickable by correctly handling single taps in the GestureDetector and removing conflicting clickability on child views. - Implemented isEnabled() in the adapter to strictly prevent interaction with dates from other months or future dates. - Updated the date detail section to use string resources for status (Not Started, Incomplete, Completed). - Explicitly denote hint usage in the status with '(*hints used)'. - Added progress info (e.g., '1/4 triples found') to the incomplete status text. - Changed the month title to a TextButton for consistent click feedback. - Ensured all calendar navigation and titles use the daily accent color. - Reduced top margin of the detail section for a more compact layout. - Added necessary imports for java.util.Set and java.util.HashSet. Co-authored-by: amorris13 <4523811+amorris13@users.noreply.github.com>
1 parent a126121 commit 47dd918

3 files changed

Lines changed: 33 additions & 27 deletions

File tree

app/src/main/java/com/antsapps/triples/DailyStatisticsFragment.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import android.widget.Button;
1515
import android.widget.GridView;
1616
import android.widget.LinearLayout;
17-
import android.widget.ListView;
1817
import android.widget.TextView;
1918
import androidx.annotation.NonNull;
2019
import androidx.core.content.ContextCompat;
@@ -39,7 +38,7 @@ public class DailyStatisticsFragment extends Fragment {
3938
private List<DailyGame> mCompletedGames;
4039
private Calendar mCurrentMonth;
4140
private GridView mCalendarGrid;
42-
private TextView mMonthTitle;
41+
private Button mMonthTitle;
4342
private TextView mCurrentStreakTv;
4443
private TextView mLongestStreakTv;
4544
private TextView mTotalSolvedTv;
@@ -114,6 +113,19 @@ public boolean onDown(MotionEvent e) {
114113
return true;
115114
}
116115

116+
@Override
117+
public boolean onSingleTapUp(MotionEvent e) {
118+
int position = mCalendarGrid.pointToPosition((int) e.getX(), (int) e.getY());
119+
if (position != GridView.INVALID_POSITION && mCalendarGrid.getAdapter().isEnabled(position)) {
120+
mCalendarGrid.performItemClick(
121+
mCalendarGrid.getChildAt(position - mCalendarGrid.getFirstVisiblePosition()),
122+
position,
123+
mCalendarGrid.getAdapter().getItemId(position));
124+
return true;
125+
}
126+
return false;
127+
}
128+
117129
@Override
118130
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
119131
if (Math.abs(velocityX) > Math.abs(velocityY) && Math.abs(velocityX) > 100) {
@@ -138,12 +150,7 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve
138150
}
139151
});
140152

141-
mCalendarGrid.setOnTouchListener((v, event) -> {
142-
if (gestureDetector.onTouchEvent(event)) {
143-
return true;
144-
}
145-
return false;
146-
});
153+
mCalendarGrid.setOnTouchListener((v, event) -> gestureDetector.onTouchEvent(event));
147154

148155
mCompletedGames = new ArrayList<>();
149156
for (DailyGame game : mApplication.getCompletedDailyGames()) {
@@ -172,12 +179,8 @@ private void updateCalendar() {
172179

173180
mCalendarGrid.setOnItemClickListener((parent, view1, position, id) -> {
174181
Calendar day = (Calendar) adapter.getItem(position);
175-
if (day != null && day.get(Calendar.MONTH) == mCurrentMonth.get(Calendar.MONTH) &&
176-
day.get(Calendar.YEAR) == mCurrentMonth.get(Calendar.YEAR)) {
182+
if (adapter.isEnabled(position)) {
177183
long daySeed = getStartOfDay(day.getTimeInMillis());
178-
if (daySeed > getStartOfDay(System.currentTimeMillis())) {
179-
return;
180-
}
181184
mSelectedDate = (Calendar) day.clone();
182185
adapter.setSelectedSeed(daySeed);
183186
updateDetailSection();
@@ -201,7 +204,11 @@ private void updateDetailSection() {
201204
}
202205

203206
if (game == null || game.getGameState() != DailyGame.GameState.COMPLETED) {
204-
mDetailStatus.setText("Uncompleted");
207+
if (game == null || game.getNumTriplesFound() == 0) {
208+
mDetailStatus.setText(R.string.daily_not_started);
209+
} else {
210+
mDetailStatus.setText(getString(R.string.daily_incomplete) + " (" + game.getNumTriplesFound() + "/" + game.getTotalTriplesCount() + " triples found)");
211+
}
205212
mDetailResultsContainer.setVisibility(View.GONE);
206213
mDetailPlayBtn.setVisibility(View.VISIBLE);
207214
mDetailPlayBtn.setOnClickListener(v -> {
@@ -211,9 +218,9 @@ private void updateDetailSection() {
211218
startActivity(intent);
212219
});
213220
} else {
214-
String status = "Completed";
221+
String status = getString(R.string.daily_completed);
215222
if (game.areHintsUsed()) {
216-
status += " (*hints used)";
223+
status += getString(R.string.daily_hints_used_suffix);
217224
}
218225
mDetailStatus.setText(status);
219226
mDetailPlayBtn.setVisibility(View.GONE);

app/src/main/res/layout/daily_stats_fragment.xml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,29 +93,24 @@
9393
style="@style/Widget.Material3.Button.TextButton"
9494
android:layout_width="wrap_content"
9595
android:layout_height="wrap_content"
96-
android:text="&lt;"
97-
android:textColor="@color/daily_accent" />
96+
android:text="&lt;" />
9897

99-
<TextView
98+
<Button
10099
android:id="@+id/month_title"
100+
style="@style/Widget.Material3.Button.TextButton"
101101
android:layout_width="0dp"
102102
android:layout_height="wrap_content"
103103
android:layout_weight="1"
104104
android:gravity="center"
105105
android:textSize="18sp"
106-
android:textStyle="bold"
107-
android:textColor="@color/daily_accent"
108-
android:background="?attr/selectableItemBackground"
109-
android:clickable="true"
110-
android:focusable="true" />
106+
android:textStyle="bold" />
111107

112108
<Button
113109
android:id="@+id/next_month"
114110
style="@style/Widget.Material3.Button.TextButton"
115111
android:layout_width="wrap_content"
116112
android:layout_height="wrap_content"
117-
android:text="&gt;"
118-
android:textColor="@color/daily_accent" />
113+
android:text="&gt;" />
119114
</LinearLayout>
120115

121116
<LinearLayout
@@ -145,7 +140,7 @@
145140
android:layout_width="match_parent"
146141
android:layout_height="match_parent"
147142
android:orientation="vertical"
148-
android:layout_marginTop="24dp"
143+
android:layout_marginTop="8dp"
149144
android:gravity="center_horizontal">
150145

151146
<TextView

app/src/main/res/values/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@
142142
<string name="longest_streak">Longest Streak</string>
143143
<string name="total_solved">Total Solved</string>
144144
<string name="today">Today</string>
145+
<string name="daily_not_started">Not Started</string>
146+
<string name="daily_incomplete">Incomplete</string>
147+
<string name="daily_completed">Completed</string>
148+
<string name="daily_hints_used_suffix"> (*hints used)</string>
145149

146150
<string name="account_settings">Account</string>
147151
<string name="account_user_title">User</string>

0 commit comments

Comments
 (0)