-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
319 additions
and
40 deletions.
There are no files selected for viewing
Submodule gn_mobile_core
updated
20 files
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
52 changes: 52 additions & 0 deletions
52
occtax/src/main/java/fr/geonature/occtax/ui/input/taxa/FilterName.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,52 @@ | ||
package fr.geonature.occtax.ui.input.taxa | ||
|
||
import android.os.Parcel | ||
import android.os.Parcelable | ||
|
||
/** | ||
* Name filter. | ||
* | ||
* @author [S. Grimault](mailto:sebastien.grimault@gmail.com) | ||
*/ | ||
class FilterName(value: Name) : Filter<FilterName.Name>( | ||
FilterType.NAME, | ||
value | ||
) { | ||
class Name(val type: NameType) : | ||
Parcelable { | ||
|
||
private constructor(source: Parcel) : this( | ||
NameType.valueOf(source.readString() ?: NameType.SCIENTIFIC.name) | ||
) | ||
|
||
override fun describeContents(): Int { | ||
return 0 | ||
} | ||
|
||
override fun writeToParcel(dest: Parcel?, flags: Int) { | ||
dest?.also { | ||
it.writeString(type.name) | ||
} | ||
} | ||
|
||
companion object CREATOR : Parcelable.Creator<Name> { | ||
override fun createFromParcel(parcel: Parcel): Name { | ||
return Name(parcel) | ||
} | ||
|
||
override fun newArray(size: Int): Array<Name?> { | ||
return arrayOfNulls(size) | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Taxon name types. | ||
* | ||
* @author [S. Grimault](mailto:sebastien.grimault@gmail.com) | ||
*/ | ||
enum class NameType { | ||
SCIENTIFIC, | ||
COMMON | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
occtax/src/main/java/fr/geonature/occtax/ui/input/taxa/FilterNameRecyclerViewAdapter.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,65 @@ | ||
package fr.geonature.occtax.ui.input.taxa | ||
|
||
import android.view.View | ||
import android.widget.Switch | ||
import fr.geonature.commons.ui.adapter.AbstractListItemRecyclerViewAdapter | ||
import fr.geonature.occtax.R | ||
|
||
/** | ||
* Default RecyclerView Adapter for [FilterName]. | ||
* | ||
* @author [S. Grimault](mailto:sebastien.grimault@gmail.com) | ||
*/ | ||
class FilterNameRecyclerViewAdapter(val listener: FilterRecyclerViewAdapterListener<FilterName>) : | ||
AbstractListItemRecyclerViewAdapter<FilterName>() { | ||
|
||
init { | ||
setItems(listOf(FilterName(FilterName.Name(FilterName.NameType.SCIENTIFIC)))) | ||
} | ||
|
||
override fun getViewHolder(view: View, viewType: Int): AbstractViewHolder { | ||
return ViewHolder(view) | ||
} | ||
|
||
override fun getLayoutResourceId(position: Int, item: FilterName): Int { | ||
return R.layout.list_item_filter_name | ||
} | ||
|
||
override fun areItemsTheSame( | ||
oldItems: List<FilterName>, | ||
newItems: List<FilterName>, | ||
oldItemPosition: Int, | ||
newItemPosition: Int | ||
): Boolean { | ||
return oldItems[oldItemPosition] == newItems[newItemPosition] | ||
} | ||
|
||
override fun areContentsTheSame( | ||
oldItems: List<FilterName>, | ||
newItems: List<FilterName>, | ||
oldItemPosition: Int, | ||
newItemPosition: Int | ||
): Boolean { | ||
return oldItems[oldItemPosition] == newItems[newItemPosition] | ||
} | ||
|
||
fun setSelectedFilter(filter: FilterName) { | ||
this.setItems(listOf(filter)) | ||
|
||
notifyDataSetChanged() | ||
} | ||
|
||
inner class ViewHolder(itemView: View) : | ||
AbstractListItemRecyclerViewAdapter<FilterName>.AbstractViewHolder(itemView) { | ||
|
||
private val switch: Switch = itemView.findViewById(R.id.switch_name) | ||
|
||
override fun onBind(item: FilterName) { | ||
switch.setOnClickListener { | ||
listener.onSelectedFilters(if (switch.isChecked) FilterName(FilterName.Name(FilterName.NameType.COMMON)) else FilterName(FilterName.Name(FilterName.NameType.SCIENTIFIC))) | ||
} | ||
|
||
switch.isChecked = item.value.type == FilterName.NameType.COMMON | ||
} | ||
} | ||
} |
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.