Skip to content

Commit

Permalink
feat: add PlantCalendar.kt (overview of seasons for each plant type)
Browse files Browse the repository at this point in the history
  • Loading branch information
xjcl committed Oct 2, 2022
1 parent 71fa5d1 commit 0db2e5c
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 8 deletions.
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<activity
android:name=".activities.PlantAtlas"
android:label="@string/plant_atlas" />
<activity
android:name=".activities.PlantCalendar"
android:label="@string/plant_calendar" />
<activity
android:name=".activities.AppSettings"
android:label="@string/title_activity_app_settings" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class FruitBarMapFragment : SupportMapFragment() {
iv?.let { animateJump(it) }
mMap?.animateCamera(CameraUpdateFactory.zoomBy(0F)) // trigger updateMarkers()
infoBar.removeViewAt(1) // removes monthsBar
infoBar.addView(createMonthsBarLayout(context!!, key))
infoBar.addView(createMonthsBarLayout(context!!, key, withLetters = false))
infoBar.setOnClickListener {
if (treeIdToProfileUrl[key] != null)
(context as Activity).startActivity(Intent(context, PlantProfile::class.java).putExtra("tid", key))
Expand Down Expand Up @@ -215,7 +215,7 @@ class FruitBarMapFragment : SupportMapFragment() {
}
infoBar.addView(infoSpecies)

val months = createMonthsBarLayout(context!!, 99)
val months = createMonthsBarLayout(context!!, 99, withLetters = false)
infoBar.addView(months)

infoBar.background = materialDesignBg((7.5 * density).toInt(), (2.5 * density).toInt(), 999F)
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/xjcl/mundraub/activities/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ class Main : AppCompatActivity(), OnMapReadyCallback, OnCameraIdleListener, Acti
ItemMenu.PLANT_LIST.value -> startActivityForResult(Intent(this, PlantList::class.java), ActivityRequest.PlantList.value)
ItemMenu.PLANT_FORM.value -> startActivityForResult(Intent(this, PlantForm::class.java), ActivityRequest.PlantForm.value)
ItemMenu.PLANT_ATLAS.value -> startActivityForResult(Intent(this, PlantAtlas::class.java), ActivityRequest.IRRELEVANT.value)
ItemMenu.PLANT_CALENDAR.value -> startActivityForResult(Intent(this, PlantCalendar::class.java), ActivityRequest.IRRELEVANT.value)
ItemMenu.IMPRINT.value -> openUrl(getString(R.string.imprint_url))
ItemMenu.PRIVACY.value -> openUrl(getString(R.string.privacy_url))
ItemMenu.MUNDRAUB_RULES.value -> openUrl(getString(R.string.mundraub_rules_url))
Expand Down Expand Up @@ -314,6 +315,7 @@ class Main : AppCompatActivity(), OnMapReadyCallback, OnCameraIdleListener, Acti
addMenuItem(menu, ItemMenu.PLANT_LIST.value, R.string.title_activity_plant_list, R.drawable.material_list)
addMenuItem(menu, ItemMenu.PLANT_FORM.value, R.string.addNode, R.drawable.material_add_location)
addMenuItem(menu, ItemMenu.PLANT_ATLAS.value, R.string.plant_atlas, null)
addMenuItem(menu, ItemMenu.PLANT_CALENDAR.value, R.string.plant_calendar, null)
addMenuItem(menu, ItemMenu.IMPRINT.value, R.string.imprint, null)
addMenuItem(menu, ItemMenu.PRIVACY.value, R.string.privacy, null)
addMenuItem(menu, ItemMenu.MUNDRAUB_RULES.value, R.string.mundraub_rules, null)
Expand Down
52 changes: 52 additions & 0 deletions app/src/main/java/xjcl/mundraub/activities/PlantCalendar.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package xjcl.mundraub.activities

import android.graphics.Typeface
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.text.TextUtils
import android.view.Gravity
import android.widget.LinearLayout
import android.widget.ScrollView
import android.widget.TextView
import xjcl.mundraub.data.treeIdToSeason

import xjcl.mundraub.layouts.createMonthsBarLayout
import xjcl.mundraub.utils.getFruitColor

class PlantCalendar : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val density = resources.displayMetrics.density

val scrollpage = ScrollView(this)
val page = LinearLayout(this)
page.orientation = LinearLayout.VERTICAL
page.setPadding(0, (20 * density).toInt(), 0, (20 * density).toInt())

//for ((i, tid) in treeIdToSeason.keys.withIndex())
for ((i, tid) in treeIdToSeason.keys.sortedBy { treeIdToSeason[it]!!.first * 20 + treeIdToSeason[it]!!.second }.withIndex())
{
val tv = TextView(this)
tv.text = getString(resources.getIdentifier("tid$tid", "string", packageName))
tv.setTextColor(getFruitColor(resources, tid))
tv.setTypeface(null, Typeface.BOLD)
tv.ellipsize = TextUtils.TruncateAt.END
tv.setSingleLine()
tv.minWidth = (110 * density).toInt()
tv.maxWidth = (110 * density).toInt()

val mb = createMonthsBarLayout(this, tid, withLetters = i % 5 == 4)

val line = LinearLayout(this)
line.addView(tv)
line.addView(mb)
line.gravity = Gravity.CENTER_HORIZONTAL
page.addView(line)
}

scrollpage.addView(page)
setContentView(scrollpage)
}
}
1 change: 1 addition & 0 deletions app/src/main/java/xjcl/mundraub/data/ItemMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ enum class ItemMenu(val value: Int) {
PLANT_LIST(1),
PLANT_FORM(2),
PLANT_ATLAS(10),
PLANT_CALENDAR(20),
LOGOUT(68),
SETTINGS(69),
MUNDRAUB_RULES(82),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import java.util.Calendar
fun createInfoWindowLayout(context: Context, marker: Marker): View {
val md = markersData[marker.position] ?: return TextView(context)

val months = createMonthsBarLayout(context, md)
val months = createMonthsBarLayout(context, md, withLetters = true)
months.measure(0, 0)
val masterWidth = months.measuredWidth

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import xjcl.mundraub.utils.bitmapWithText
* - - - o o o - - -|- - -
* J F M A M J J A S O N D <--- only if withLetters is true
*/
fun createMonthsBarLayout(context: Context, md : MarkerData, withLetters : Boolean = true): LinearLayout {
fun createMonthsBarLayout(context: Context, md : MarkerData, withLetters : Boolean): LinearLayout {
val months = LinearLayout(context)
months.orientation = LinearLayout.HORIZONTAL
months.gravity = Gravity.CENTER
Expand Down Expand Up @@ -59,8 +59,8 @@ fun createMonthsBarLayout(context: Context, md : MarkerData, withLetters : Boole
return months
}

fun createMonthsBarLayout(context: Context, tid : Int): LinearLayout {
fun createMonthsBarLayout(context: Context, tid : Int, withLetters: Boolean): LinearLayout {
if (!treeIdToSeason.contains(tid)) return LinearLayout(context)
val fakeFeature = Feature(listOf(), Properties(0, tid), null)
return createMonthsBarLayout(context, markerDataManager.featureToMarkerData(context, fakeFeature), false)
return createMonthsBarLayout(context, markerDataManager.featureToMarkerData(context, fakeFeature), withLetters)
}
3 changes: 2 additions & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<string name="tid29">Weißdorn</string>
<string name="tid30">Andere Sträucher</string>

<string name="tid31">(!) Bärlauch</string>
<string name="tid31">Bärlauch</string>
<string name="tid32">Wacholder</string>
<string name="tid33">Minze</string>
<string name="tid34">Rosmarin</string>
Expand Down Expand Up @@ -116,6 +116,7 @@
<string name="markers">Marker</string>
<string name="plant_atlas">Pflanzen-Atlas</string>
<string name="plant_atlas_about">Hier siehst du Statistiken und Steckbriefe über die einzelnen Pflanzenarten.\n\nAußerdem erkennst du welche Arten du schon zu mundraub.org beigetragen hast (in grün).</string>
<string name="plant_calendar">Pflanzen-Kalender</string>
<string name="submitted">Danke!</string>
<string name="not_submitted">noch keine von dir</string>

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<string name="tid29">Hawthorn</string>
<string name="tid30">Other fruit shrub</string>

<string name="tid31">(!) Ramson</string>
<string name="tid31">Ramson</string>
<string name="tid32">Juniper</string>
<string name="tid33">Mint</string>
<string name="tid34">Rosemary</string>
Expand Down Expand Up @@ -121,6 +121,7 @@
<string name="markers">markers</string>
<string name="plant_atlas">Plant atlas</string>
<string name="plant_atlas_about">Here you can see statistics and profiles for our plant types.\n\nYou can also see which types you\'ve contributed to mundraub.org (in green).</string>
<string name="plant_calendar">Plant calendar</string>
<string name="submitted">Thank you!</string>
<string name="not_submitted">none are from you</string>

Expand Down

0 comments on commit 0db2e5c

Please sign in to comment.