Created
March 21, 2014 04:13
-
-
Save timorantalaiho/9679392 to your computer and use it in GitHub Desktop.
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
diff --git a/src/main/scala/fi/allacca/AllaccaMain.scala b/src/main/scala/fi/allacca/AllaccaMain.scala | |
index 3831c8e..320f207 100644 | |
--- a/src/main/scala/fi/allacca/AllaccaMain.scala | |
+++ b/src/main/scala/fi/allacca/AllaccaMain.scala | |
@@ -16,7 +16,7 @@ import android.view.animation.Animation.AnimationListener | |
class AllaccaMain extends Activity with TypedViewHolder { | |
private lazy val dimensions = new ScreenParameters(getResources.getDisplayMetrics) | |
- private lazy val weeksAdapter = new WeeksAdapter2(this, dimensions) | |
+ private lazy val weeksAdapter = new WeeksAdapter2(this, dimensions, agendaView) | |
private lazy val weeksList = new WeeksView(this, weeksAdapter, shownMonthsView) | |
private lazy val cornerView = new TextView(this) | |
diff --git a/src/main/scala/fi/allacca/agenda.scala b/src/main/scala/fi/allacca/agenda.scala | |
index 028ecef..9f905ff 100644 | |
--- a/src/main/scala/fi/allacca/agenda.scala | |
+++ b/src/main/scala/fi/allacca/agenda.scala | |
@@ -22,6 +22,7 @@ import scala.concurrent.ExecutionContext.Implicits.global | |
import scala.util.{Failure, Success} | |
import scala.collection.mutable | |
import android.view.View.OnLongClickListener | |
+import fi.allacca.dates.YearAndWeek | |
class AgendaView(activity: Activity, statusTextView: TextView) extends ListView(activity) { | |
val howManyDaysToLoadAtTime = 120 | |
@@ -54,6 +55,13 @@ class AgendaView(activity: Activity, statusTextView: TextView) extends ListView( | |
} | |
def focusDay: LocalDate = adapter.synchronized { adapter.focusDay } | |
+ | |
+ def hasEvents(time: DateTime): Boolean = adapter.hasEvents(time) | |
+ | |
+ def ensureLoaded(week: YearAndWeek) { | |
+ adapter.ensureLoaded(week) | |
+ } | |
+ | |
} | |
class AgendaAdapter(activity: Activity, listView: AgendaView, statusTextView: TextView) extends BaseAdapter with LoaderCallbacks[Cursor] { | |
@@ -105,6 +113,18 @@ class AgendaAdapter(activity: Activity, listView: AgendaView, statusTextView: Te | |
} | |
} | |
+ def ensureLoaded(week: YearAndWeek) { | |
+ loadWindowLock.synchronized { | |
+ if (firstDayToLoad.toDateTimeAtStartOfDay.isAfter(week.firstDay)) { | |
+ firstDayToLoad = week.firstDay.toLocalDate.minusDays(howManyDaysToLoadAtTime) | |
+ triggerLoading() | |
+ } else if (lastDayToLoad.toDateTimeAtStartOfDay.isBefore(week.lastDay)) { | |
+ lastDayToLoad = week.lastDay.toLocalDate.plusDays(howManyDaysToLoadAtTime) | |
+ triggerLoading() | |
+ } | |
+ } | |
+ } | |
+ | |
private def triggerLoading() { | |
if (loading.getAndSet(true)) { | |
Log.d(TAG, "Already load in progress") | |
@@ -195,7 +215,9 @@ class AgendaAdapter(activity: Activity, listView: AgendaView, statusTextView: Te | |
time({ | |
model.addOrUpdate(daysWithEvents, days) | |
}, "Update model") | |
- time({activity.runOnUiThread { statusTextView.setText("") }}, "setViewText") | |
+ time({activity.runOnUiThread { | |
+ statusTextView.setText("") | |
+ }}, "setViewText") | |
} | |
f onComplete { | |
@@ -221,6 +243,8 @@ class AgendaAdapter(activity: Activity, listView: AgendaView, statusTextView: Te | |
} | |
override def onLoaderReset(loader: Loader[Cursor]) {} | |
+ | |
+ def hasEvents(time: DateTime): Boolean = model.hasEvents(time) | |
} | |
class AgendaRenderer(activity: Activity) { | |
@@ -383,6 +407,8 @@ class AgendaModel { | |
} | |
} | |
+ def hasEvents(time: DateTime): Boolean = synchronized { sortedIds.contains(time.withTimeAtStartOfDay.toDate.getTime) } | |
+ | |
/** | |
* Fast unique sort from http://stackoverflow.com/a/8162643 | |
*/ | |
diff --git a/src/main/scala/fi/allacca/weeks.scala b/src/main/scala/fi/allacca/weeks.scala | |
index 489d3b4..6d4856d 100644 | |
--- a/src/main/scala/fi/allacca/weeks.scala | |
+++ b/src/main/scala/fi/allacca/weeks.scala | |
@@ -46,9 +46,9 @@ class WeeksView(activity: Activity, adapter: WeeksAdapter2, shownMonthsView: Sho | |
} | |
-class WeeksAdapter2(activity: Activity, dimensions: ScreenParameters) extends BaseAdapter { | |
+class WeeksAdapter2(activity: Activity, dimensions: ScreenParameters, agendaView: AgendaView) extends BaseAdapter { | |
private val idGenerator = new IdGenerator | |
- private val renderer = new WeekViewRenderer(activity, dimensions) | |
+ private val renderer = new WeekViewRenderer(activity, dimensions, agendaView) | |
private val model = new WeeksModel | |
private val loading = new AtomicBoolean(false) | |
@@ -75,6 +75,7 @@ class WeeksAdapter2(activity: Activity, dimensions: ScreenParameters) extends B | |
def getView(position: Int, convertView: View, parent: ViewGroup): View = { | |
val yearAndWeek: YearAndWeek = getItem(position) | |
+ agendaView.ensureLoaded(yearAndWeek) | |
if (convertView == null) | |
renderer.createWeekView(model.getChosenDay, yearAndWeek) | |
else | |
@@ -101,7 +102,7 @@ class WeeksModel { | |
def startYear = startDay.year() | |
} | |
-class WeekViewRenderer(activity: Activity, dimensions: ScreenParameters) { | |
+class WeekViewRenderer(activity: Activity, dimensions: ScreenParameters, agendaView: AgendaView) { | |
val fmt = DateTimeFormat.forPattern("d") | |
def updateView(focusDay: DateTime, yearAndWeek: YearAndWeek, convertView: View) = { | |
@@ -158,6 +159,11 @@ class WeekViewRenderer(activity: Activity, dimensions: ScreenParameters) { | |
val dayNumber = fmt.print(day) | |
dayView.setText(dayNumber) | |
if (focusDay.withTimeAtStartOfDay == day) dayView.setTextColor(Color.RED) else dayView.setTextColor(Color.WHITE) | |
+ if (agendaView.hasEvents(day)) { | |
+ dayView.setBackgroundColor(dimensions.funBlue) | |
+ } else { | |
+ dayView.setBackgroundColor(0) | |
+ } | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment