forked from streetcomplete/StreetComplete
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from streetcomplete/quest-order
Quest order
- Loading branch information
Showing
17 changed files
with
454 additions
and
176 deletions.
There are no files selected for viewing
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
1 change: 0 additions & 1 deletion
1
app/src/main/java/de/westnordost/streetcomplete/FragmentContainerActivity.kt
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
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
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
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
56 changes: 56 additions & 0 deletions
56
...ain/java/de/westnordost/streetcomplete/data/notifications/QuestSelectionHintController.kt
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,56 @@ | ||
package de.westnordost.streetcomplete.data.notifications | ||
|
||
import android.content.SharedPreferences | ||
import de.westnordost.streetcomplete.ApplicationConstants.QUEST_COUNT_AT_WHICH_TO_SHOW_QUEST_SELECTION_HINT | ||
import de.westnordost.streetcomplete.Prefs | ||
import de.westnordost.streetcomplete.data.quest.Quest | ||
import de.westnordost.streetcomplete.data.quest.QuestKey | ||
import de.westnordost.streetcomplete.data.quest.VisibleQuestsSource | ||
import de.westnordost.streetcomplete.data.notifications.QuestSelectionHintState.* | ||
import java.util.concurrent.CopyOnWriteArrayList | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
@Singleton class QuestSelectionHintController @Inject constructor( | ||
private val visibleQuestsSource: VisibleQuestsSource, | ||
private val prefs: SharedPreferences | ||
) { | ||
|
||
interface Listener { | ||
fun onQuestSelectionHintStateChanged() | ||
} | ||
private val listeners: MutableList<Listener> = CopyOnWriteArrayList() | ||
|
||
var state: QuestSelectionHintState | ||
set(value) { | ||
prefs.edit().putString(Prefs.QUEST_SELECTION_HINT_STATE, value.toString()).apply() | ||
listeners.forEach { it.onQuestSelectionHintStateChanged() } | ||
} | ||
get() { | ||
val str = prefs.getString(Prefs.QUEST_SELECTION_HINT_STATE, null) | ||
return if (str == null) NOT_SHOWN else QuestSelectionHintState.valueOf(str) | ||
} | ||
|
||
init { | ||
visibleQuestsSource.addListener(object : VisibleQuestsSource.Listener { | ||
override fun onUpdatedVisibleQuests(added: Collection<Quest>, removed: Collection<QuestKey>) { | ||
if (state == NOT_SHOWN && added.size >= QUEST_COUNT_AT_WHICH_TO_SHOW_QUEST_SELECTION_HINT) { | ||
state = SHOULD_SHOW | ||
} | ||
} | ||
|
||
override fun onVisibleQuestsInvalidated() {} | ||
}) | ||
} | ||
|
||
fun addListener(listener: Listener) { | ||
listeners.add(listener) | ||
} | ||
fun removeListener(listener: Listener) { | ||
listeners.remove(listener) | ||
} | ||
} | ||
|
||
enum class QuestSelectionHintState { | ||
NOT_SHOWN, SHOULD_SHOW, SHOWN | ||
} |
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.