Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ public interface SmartBirdsApi {
@POST("bats")
Call<UploadFormResponse> createBat(@Body JsonObject request);

@POST("bears")
Call<UploadFormResponse> createBear(@Body JsonObject request);

@DELETE("user/{id}")
Call<BaseResponse> deleteUser(@Path("id") long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.bspb.smartbirds.pro.R;
import org.bspb.smartbirds.pro.forms.convert.BatsConverter;
import org.bspb.smartbirds.pro.forms.convert.BearsConverter;
import org.bspb.smartbirds.pro.forms.convert.BirdsConverter;
import org.bspb.smartbirds.pro.forms.convert.BirdsMigrationsConverter;
import org.bspb.smartbirds.pro.forms.convert.CbmConverter;
Expand All @@ -25,6 +26,7 @@
import org.bspb.smartbirds.pro.forms.convert.PylonsConverter;
import org.bspb.smartbirds.pro.forms.convert.ThreatsConverter;
import org.bspb.smartbirds.pro.forms.upload.BatsUploader;
import org.bspb.smartbirds.pro.forms.upload.BearsUploader;
import org.bspb.smartbirds.pro.forms.upload.BirdsMigrationsUploader;
import org.bspb.smartbirds.pro.forms.upload.BirdsUploader;
import org.bspb.smartbirds.pro.forms.upload.CbmUploader;
Expand All @@ -40,6 +42,7 @@
import org.bspb.smartbirds.pro.forms.upload.Uploader;
import org.bspb.smartbirds.pro.ui.fragment.BaseEntryFragment;
import org.bspb.smartbirds.pro.ui.fragment.NewBatsEntryFormFragment;
import org.bspb.smartbirds.pro.ui.fragment.NewBearsEntryFormFragment;
import org.bspb.smartbirds.pro.ui.fragment.NewBirdsEntryFormFragment;
import org.bspb.smartbirds.pro.ui.fragment.NewBirdsMigrationsEntryFormFragment;
import org.bspb.smartbirds.pro.ui.fragment.NewCbmEntryFormFragment;
Expand All @@ -66,14 +69,15 @@ public enum EntryType {
CICONIA(new NewCiconiaEntryFormFragment.Builder(), R.string.entry_type_ciconia, R.id.action_form_type_ciconia, "form_ciconia.csv", CiconiaConverter.class, CiconiaUploader.class, true),
HERPTILE(new NewHerptileEntryFormFragment.Builder(), R.string.entry_type_herptile, R.id.action_form_type_herptile, "form_herptile.csv", HerptileConverter.class, HerptileUploader.class, true),
MAMMAL(new NewMammalEntryFormFragment.Builder(), R.string.entry_type_mammal, R.id.action_form_type_mammal, "form_mammal.csv", MammalConverter.class, MammalUploader.class, true),
BEARS(new NewBearsEntryFormFragment.Builder(), R.string.entry_type_bears, R.id.action_form_type_bears, "form_bears.csv", BearsConverter.class, BearsUploader.class, true),
INVERTEBRATES(new NewInvertebratesEntryFormFragment.Builder(), R.string.entry_type_invertebrates, R.id.action_form_type_invertebrates, "form_invertebrates.csv", InvertebratesConverter.class, InvertebratesUploader.class, true),
PLANTS(new NewPlantsEntryFormFragment.Builder(), R.string.entry_type_plants, R.id.action_form_type_plants, "form_plants.csv", PlantsConverter.class, PlantsUploader.class, true),
THREATS(new NewThreatsEntryFormFragment.Builder(), R.string.entry_type_threats, R.id.action_form_type_threats, "form_threats.csv", ThreatsConverter.class, ThreatsUploader.class, true),
PYLONS(new NewPylonsEntryFormFragment.Builder(), R.string.entry_type_pylons, R.id.action_form_type_pylons, "form_pylons.csv", PylonsConverter.class, PylonsUploader.class, true),
PYLONS_CASUALTIES(new NewPylonsCasualtiesEntryFormFragment.Builder(), R.string.entry_type_pylons_casualties, R.id.action_form_type_pylons_casualties, "form_pylons_casualties.csv", PylonsCasualtiesConverter.class, PylonsCasualtiesUploader.class, true),
BIRDS_MIGRATIONS(new NewBirdsMigrationsEntryFormFragment.Builder(), R.string.entry_type_birds_migrations, R.id.action_form_type_birds_migrations, "form_birds_migrations.csv", BirdsMigrationsConverter.class, BirdsMigrationsUploader.class, true),
FISH(new NewFishesEntryFormFragment.Builder(), R.string.entry_type_fish, R.id.action_form_type_fish, "form_fish.csv", FishesConverter.class, FishesUploader.class, true),
BATS(new NewBatsEntryFormFragment.Builder(), R.string.entry_type_bats, R.id.action_form_type_bats, "form_bats.csv", BatsConverter.class, BatsUploader.class, true),
BATS(new NewBatsEntryFormFragment.Builder(), R.string.entry_type_bats, R.id.action_form_type_bats, "form_bats.csv", BatsConverter.class, BatsUploader.class, true)
// prevent auto-formatting
;

Expand All @@ -84,6 +88,7 @@ public enum EntryType {
R.id.action_form_type_humid,
R.id.action_form_type_herptile,
R.id.action_form_type_mammal,
R.id.action_form_type_bears,
R.id.action_form_type_invertebrates,
R.id.action_form_type_plants,
R.id.action_form_type_threats,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,23 @@ public boolean onOptionsItemSelected(MenuItem item) {
setZoomFree(item);
return true;
}
if ((((((((((((((itemId == R.id.action_form_type_birds) || (itemId == R.id.action_form_type_cbm)) || (itemId == R.id.action_form_type_ciconia)) || (itemId == R.id.action_form_type_humid)) || (itemId == R.id.action_form_type_herptile)) || (itemId == R.id.action_form_type_mammal)) || (itemId == R.id.action_form_type_invertebrates)) || (itemId == R.id.action_form_type_plants)) || (itemId == R.id.action_form_type_threats)) || (itemId == R.id.action_form_type_pylons)) || (itemId == R.id.action_form_type_pylons_casualties)) || (itemId == R.id.action_form_type_birds_migrations)) || (itemId == R.id.action_form_type_fish)) || (itemId == R.id.action_form_type_bats)) {
if (
(itemId == R.id.action_form_type_birds) ||
(itemId == R.id.action_form_type_cbm) ||
(itemId == R.id.action_form_type_ciconia) ||
(itemId == R.id.action_form_type_humid) ||
(itemId == R.id.action_form_type_herptile) ||
(itemId == R.id.action_form_type_mammal) ||
(itemId == R.id.action_form_type_invertebrates) ||
(itemId == R.id.action_form_type_plants) ||
(itemId == R.id.action_form_type_threats) ||
(itemId == R.id.action_form_type_pylons) ||
(itemId == R.id.action_form_type_pylons_casualties) ||
(itemId == R.id.action_form_type_birds_migrations) ||
(itemId == R.id.action_form_type_fish) ||
(itemId == R.id.action_form_type_bats) ||
(itemId == R.id.action_form_type_bears)
) {
setFormType(item);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ public void bind(MonitoringEntry entry) {
speciesView.setText(entry.data.get(context.getString(R.string.tag_species_scientific_name)));
countView.setText(entry.data.get(context.getString(R.string.tag_count)));
break;
case BEARS:
typeView.setText(R.string.entry_type_bears);
speciesView.setText(entry.data.get(context.getString(R.string.tag_species_scientific_name)));
countView.setText(entry.data.get(context.getString(R.string.tag_count)));
break;

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.bspb.smartbirds.pro.SmartBirdsApplication;
import org.bspb.smartbirds.pro.ui.exception.ViewValidationException;
import org.bspb.smartbirds.pro.ui.views.SupportReadOnly;
import org.bspb.smartbirds.pro.ui.views.SupportRequiredView;
import org.bspb.smartbirds.pro.ui.views.SupportStorage;

Expand Down Expand Up @@ -120,7 +121,10 @@ public boolean validateFields() {
}

public static void serialize(Map<String, String> storage, String field, View view) {
if (!view.isEnabled()) {
// Check if view is readonly - readonly views should persist even when disabled
boolean isReadOnly = (view instanceof SupportReadOnly) && ((SupportReadOnly) view).isReadOnly();

if (!view.isEnabled() && !isReadOnly) {
storage.put(field, "");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@
/**
* Created by groupsky on 14-10-10.
*/
public class SingleChoiceFormInput extends TextViewFormInput implements SupportStorage {
public class SingleChoiceFormInput extends TextViewFormInput implements SupportStorage, SupportReadOnly {

private CharSequence key;
private boolean mReadOnly = false;

NomenclaturesManager nomenclatures = NomenclaturesManager.Companion.getInstance();

Expand Down Expand Up @@ -77,10 +78,16 @@ public SingleChoiceFormInput(Context context, AttributeSet attrs, int defStyle)
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SingleChoiceFormInput, defStyle, 0);
try {
key = a.getText(R.styleable.SingleChoiceFormInput_entriesType);
boolean readonly = a.getBoolean(R.styleable.SingleChoiceFormInput_readonly, false);
SmartArrayAdapter<NomenclatureItem> adapter = new SmartArrayAdapter<>(context,
R.layout.item_dialog_single_choice, new ArrayList<NomenclatureItem>());
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
setAdapter(adapter);

// Apply readonly state if specified in XML
if (readonly) {
setReadOnly(true);
}
} finally {
a.recycle();
}
Expand Down Expand Up @@ -208,8 +215,31 @@ public void setSelection(NomenclatureItem item) {
if (onSelectionChangeListener != null) onSelectionChangeListener.onSelectionChange(this);
}

@Override
public void setReadOnly(boolean readOnly) {
mReadOnly = readOnly;
if (readOnly) {
// Prevent interaction with the view
setFocusable(false);
setClickable(false);
} else {
// Restore normal interaction
setFocusable(true);
setClickable(true);
}
}

@Override
public boolean isReadOnly() {
return mReadOnly;
}

@Override
public boolean performClick() {
// Block clicks when readonly
if (mReadOnly) {
return false;
}
super.performClick();
new PopupDialog().show();
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.bspb.smartbirds.pro.ui.views;

/**
* Interface for views that support read-only mode.
*/
public interface SupportReadOnly {
/**
* Set whether this view is in read-only mode.
* When read-only, the view should:
* - Display its current value
* - Prevent user editing/interaction
*
* @param readOnly true to make the view read-only, false to allow editing
*/
void setReadOnly(boolean readOnly);

/**
* Check if this view is currently in read-only mode.
*
* @return true if read-only, false otherwise
*/
boolean isReadOnly();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.bspb.smartbirds.pro.forms.convert

import android.content.Context
import org.bspb.smartbirds.pro.R

class BearsConverter(context: Context?) : Converter(context) {
init {
// Bats main form
addBool(R.string.tag_confidential, "confidential")
addBool(R.string.tag_moderator_review, "moderatorReview")
add(R.string.tag_remarks_type, "speciesNotes")
addMulti(R.string.tag_threats, "threats")

addSpecies(R.string.tag_species_scientific_name, "species")
add(R.string.tag_count, "count", "0")
addSingle(R.string.tag_sex, "sex")
addSingle(R.string.tag_age, "age")
addMulti(R.string.tag_excrement_content, "excrementContent")
addSingle(R.string.tag_excrement_consistence, "excrementConsistence")
add(R.string.tag_marking_height, "markingHeight")
addSingle(R.string.tag_den, "den")
addMulti(R.string.tag_habitat, "habitat")
addMulti(R.string.tag_threats_other, "threatsBears")
addMulti(R.string.tag_findings, "findings")

// Additional fields
add(R.string.tag_footprint_front_paw_width, "footprintFrontPawWidth")
add(R.string.tag_footprint_front_paw_length, "footprintFrontPawLength")
add(R.string.tag_footprint_hind_paw_width, "footprintHindPawWidth")
add(R.string.tag_footprint_hind_paw_length, "footprintHindPawLength")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.bspb.smartbirds.pro.forms.upload

import com.google.gson.JsonObject
import org.bspb.smartbirds.pro.backend.SmartBirdsApi
import org.bspb.smartbirds.pro.backend.dto.UploadFormResponse
import retrofit2.Call

class BearsUploader : Uploader {
override fun upload(api: SmartBirdsApi, data: JsonObject): Call<UploadFormResponse> {
return api.createBear(data)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.bspb.smartbirds.pro.ui.fragment

import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentStatePagerAdapter
import org.bspb.smartbirds.pro.R
import org.bspb.smartbirds.pro.enums.EntryType

class NewBearsEntryFormFragment : BaseTabEntryFragment() {

override fun setupTabs() {
setAdapter(object : FragmentStatePagerAdapter(parentFragmentManager) {
override fun getItem(position: Int): Fragment {
return when (position) {
0 -> NewBearsEntryMainFormFragment.newInstance(isNewEntry, readOnly)
1 -> NewBearsEntryOptionalFormFragment.newInstance(isNewEntry, readOnly)
else -> throw IllegalArgumentException("Unhandled position$position")
}
}

override fun getPageTitle(position: Int): CharSequence {
return activity!!.getString(if (position == 0) R.string.tab_required else R.string.tab_optional)
}

override fun getCount(): Int {
return 2
}
})
}

override fun getEntryType(): EntryType? {
return EntryType.BEARS
}

class Builder : BaseEntryFragment.Builder {
override fun build(lat: Double, lon: Double, geolocationAccuracy: Double): Fragment? {
return NewBearsEntryFormFragment().apply {
arguments = Bundle().apply {
putDouble(ARG_LAT, lat)
putDouble(ARG_LON, lon)
putDouble(ARG_GEOLOCATION_ACCURACY, geolocationAccuracy)
}
}
}

override fun load(id: Long, readOnly: Boolean): Fragment? {
return NewBearsEntryFormFragment().apply {
arguments = Bundle().apply {
putLong(ARG_ENTRY_ID, id)
putBoolean(ARG_READ_ONLY, readOnly)
}
}
}
}

}
Loading
Loading