-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More dialog improvements/refactorings
- Loading branch information
Showing
55 changed files
with
1,057 additions
and
716 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
app/src/main/java/prototype/xd/scheduler/adapters/BindingViewHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package prototype.xd.scheduler.adapters; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
import androidx.viewbinding.ViewBinding; | ||
|
||
public class BindingViewHolder<T extends ViewBinding> extends RecyclerView.ViewHolder { | ||
@NonNull | ||
protected final T binding; | ||
|
||
public BindingViewHolder(@NonNull T binding) { | ||
super(binding.getRoot()); | ||
this.binding = binding; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
app/src/main/java/prototype/xd/scheduler/adapters/CalendarEventViewAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package prototype.xd.scheduler.adapters; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
import prototype.xd.scheduler.R; | ||
import prototype.xd.scheduler.databinding.ListSelectionEventBinding; | ||
import prototype.xd.scheduler.entities.SystemCalendar; | ||
import prototype.xd.scheduler.entities.SystemCalendarEvent; | ||
import prototype.xd.scheduler.utilities.DateManager; | ||
import prototype.xd.scheduler.utilities.misc.ContextWrapper; | ||
|
||
public class CalendarEventViewAdapter extends RecyclerView.Adapter<CalendarEventViewAdapter.EntryViewHolder> { | ||
|
||
private SystemCalendar calendar; | ||
private final ContextWrapper wrapper; | ||
|
||
public CalendarEventViewAdapter(@NonNull ContextWrapper wrapper) { | ||
this.wrapper = wrapper; | ||
// Each event is unique | ||
setHasStableIds(true); | ||
} | ||
|
||
@SuppressLint("NotifyDataSetChanged") | ||
public void setCalendar(@NonNull SystemCalendar calendar) { | ||
this.calendar = calendar; | ||
notifyDataSetChanged(); | ||
} | ||
|
||
static class EntryViewHolder extends BindingViewHolder<ListSelectionEventBinding> { | ||
|
||
EntryViewHolder(@NonNull ListSelectionEventBinding binding) { | ||
super(binding); | ||
} | ||
|
||
private void bind(@NonNull SystemCalendarEvent event, @NonNull ContextWrapper wrapper) { | ||
binding.eventText.setText(event.data.title); | ||
binding.eventColor.setCardBackgroundColor(event.data.color); | ||
binding.recurrenceText.setVisibility(event.isRecurring() ? View.VISIBLE : View.GONE); | ||
String timeSpan = DateManager.getTimeSpan(event.getFirstInstanceTimeRange()); | ||
if (event.isAllDay()) { | ||
binding.timeText.setText(wrapper.getString(R.string.calendar_event_all_day) + " (" + timeSpan + ")"); | ||
} else { | ||
binding.timeText.setText(timeSpan); | ||
} | ||
} | ||
|
||
} | ||
|
||
@NonNull | ||
@Override | ||
public EntryViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | ||
return new EntryViewHolder(ListSelectionEventBinding.inflate(wrapper.getLayoutInflater(), parent, false)); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(@NonNull EntryViewHolder holder, int position) { | ||
holder.bind(calendar.systemCalendarEventMap.valueAt(position), wrapper); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return calendar.systemCalendarEventMap.size(); | ||
} | ||
|
||
@Override | ||
public long getItemId(int position) { | ||
return calendar.systemCalendarEventMap.valueAt(position).hashCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.