Skip to content

Commit

Permalink
Merge pull request #971 from PhenoApps/ux_enhancements
Browse files Browse the repository at this point in the history
Ux enhancements - explanatory info on lock and language changes
  • Loading branch information
trife authored Jun 4, 2024
2 parents 3e323b2 + dcf7728 commit 4d3585b
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -409,7 +408,7 @@ private void checkForInitialBarcodeSearch() {

} else {

Toast.makeText(this, getString(R.string.act_collect_plot_with_code_not_found), Toast.LENGTH_LONG).show();
Utils.makeToast(getApplicationContext(), getString(R.string.act_collect_plot_with_code_not_found));

}
}
Expand Down Expand Up @@ -836,7 +835,7 @@ public boolean moveToSearch(
}

if (!command.equals("quickgoto") && !command.equals("barcode"))
Utils.makeToast(getApplicationContext(), getString(R.string.main_toolbar_moveto_no_match));
Utils.makeToast(this, getString(R.string.main_toolbar_moveto_no_match));

return false;
}
Expand Down Expand Up @@ -1185,7 +1184,7 @@ public String getLocationByPreferences() {
}

private void brapiDelete(String parent, Boolean hint) {
Toast.makeText(getApplicationContext(), getString(R.string.brapi_delete_message), Toast.LENGTH_LONG).show();
Utils.makeToast(this, getString(R.string.brapi_delete_message));
TraitObject trait = traitBox.getCurrentTrait();
updateObservation(trait, getString(R.string.brapi_na), null);
if (hint) {
Expand Down Expand Up @@ -1291,7 +1290,7 @@ private void openSavedResourceFile() {
e.printStackTrace();
}
} else {
Toast.makeText(this, "No file preference saved, select a file with a short press", Toast.LENGTH_SHORT).show();
Utils.makeToast(this, "No file preference saved, select a file with a short press");
}
}

Expand Down Expand Up @@ -1402,9 +1401,18 @@ public boolean onOptionsItemSelected(MenuItem item) {
i.putExtra("trait", traitBox.getCurrentTrait().getRealPosition());
startActivityForResult(i, 2);
} else if (itemId == lockDataId) {
if (dataLocked == UNLOCKED) dataLocked = LOCKED;
else if (dataLocked == LOCKED) dataLocked = FROZEN;
else dataLocked = UNLOCKED;
if (dataLocked == UNLOCKED) {
dataLocked = LOCKED;
Utils.makeToast(this, getString(R.string.activity_collect_locked_state));
}
else if (dataLocked == LOCKED) {
dataLocked = FROZEN;
Utils.makeToast(this, getString(R.string.activity_collect_frozen_state));
}
else {
dataLocked = UNLOCKED;
Utils.makeToast(this, getString(R.string.activity_collect_unlocked_state));
}
preferences.edit().putInt(GeneralKeys.DATA_LOCK_STATE, dataLocked).apply();
lockData();
} else if (itemId == android.R.id.home) {
Expand Down Expand Up @@ -1449,35 +1457,23 @@ public boolean onOptionsItemSelected(MenuItem item) {

// if trait audio is recording, give a warning
if (isTraitAudioRecording) {
Toast.makeText(
this, R.string.trait_audio_recording_warning,
Toast.LENGTH_SHORT
).show();
Utils.makeToast(this, getString(R.string.trait_audio_recording_warning));
}
// if trait audio is playing, give a warning
else if (isTraitAudioPlaying) {
Toast.makeText(
this, R.string.trait_audio_playing_warning,
Toast.LENGTH_SHORT
).show();
Utils.makeToast(this, getString(R.string.trait_audio_playing_warning));
}
// if trait audio isn't recording or playing
// record or stop the field audio depending on its state
else if (!fieldAudioHelper.isRecording()) {
// TODO: add trait audio playback stopping logic
fieldAudioHelper.startRecording(true);
Toast.makeText(
this, R.string.field_audio_recording_start,
Toast.LENGTH_SHORT
).show();
Utils.makeToast(this, getString(R.string.field_audio_recording_start));
micItem.setIcon(R.drawable.ic_tb_field_mic_on);
micItem.setTitle(R.string.menu_collect_stop_field_audio);
} else {
fieldAudioHelper.stopRecording();
Toast.makeText(
this, R.string.field_audio_recording_stop,
Toast.LENGTH_SHORT
).show();
Utils.makeToast(this, getString(R.string.field_audio_recording_stop));
micItem.setIcon(R.drawable.ic_tb_field_mic_off);
micItem.setTitle(R.string.menu_collect_start_field_audio);
}
Expand Down Expand Up @@ -1579,7 +1575,7 @@ private void showMultiMeasureDeleteDialog() {
}
} else {

Toast.makeText(this, R.string.dialog_multi_measure_delete_no_observations, Toast.LENGTH_SHORT).show();
Utils.makeToast(this, getString(R.string.dialog_multi_measure_delete_no_observations));

}
}
Expand Down Expand Up @@ -1650,15 +1646,15 @@ void lockData() {

if (state == LOCKED) {
systemMenu.findItem(R.id.lockData).setIcon(R.drawable.ic_tb_lock);
disableDataEntry();
disableDataEntry(R.string.activity_collect_locked_state);
} else if (state == UNLOCKED) {
systemMenu.findItem(R.id.lockData).setIcon(R.drawable.ic_tb_unlock);
enableDataEntry();
} else {
systemMenu.findItem(R.id.lockData).setIcon(R.drawable.ic_lock_clock);
if (collectInputView.getText().isEmpty()) {
enableDataEntry();
} else disableDataEntry();
} else disableDataEntry(R.string.activity_collect_frozen_state);
}

TraitObject trait = getCurrentTrait();
Expand All @@ -1670,30 +1666,37 @@ void lockData() {
public void traitLockData() {
if (dataLocked == LOCKED) {
systemMenu.findItem(R.id.lockData).setIcon(R.drawable.ic_tb_lock);
disableDataEntry();
disableDataEntry(R.string.activity_collect_locked_state);
} else if (dataLocked == UNLOCKED) {
systemMenu.findItem(R.id.lockData).setIcon(R.drawable.ic_tb_unlock);
enableDataEntry();
} else {
systemMenu.findItem(R.id.lockData).setIcon(R.drawable.ic_lock_clock);
if (collectInputView.getText().isEmpty()) {
enableDataEntry();
} else disableDataEntry();
} else disableDataEntry(R.string.activity_collect_frozen_state);
}
}

private void enableDataEntry() {
missingValue.setEnabled(true);
deleteValue.setEnabled(true);
barcodeInput.setEnabled(true);
traitLayouts.enableViews();
}

private void disableDataEntry() {
missingValue.setEnabled(false);
deleteValue.setEnabled(false);
barcodeInput.setEnabled(false);
traitLayouts.disableViews();
// missingValue.setEnabled(true);
// deleteValue.setEnabled(true);
// barcodeInput.setEnabled(true);
// traitLayouts.enableViews();
findViewById(R.id.lockOverlay).setVisibility(View.GONE);
}

private void disableDataEntry(int toastMessageId) {
// missingValue.setEnabled(false);
// deleteValue.setEnabled(false);
// barcodeInput.setEnabled(false);
// traitLayouts.disableViews();
View overlay = findViewById(R.id.lockOverlay);
overlay.setOnClickListener((v) -> {
getSoundHelper().playError();
Utils.makeToast(this, getString(toastMessageId));
});
overlay.setVisibility(View.VISIBLE);
}

private void moveToPlotID() {
Expand Down Expand Up @@ -1847,7 +1850,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}

} else {
Toast.makeText(this, R.string.act_file_explorer_no_file_error, Toast.LENGTH_SHORT).show();
Utils.makeToast(this, getString(R.string.act_file_explorer_no_file_error));
}
break;
case 2:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.fieldbook.tracker.preferences

import android.app.AlertDialog
import android.content.res.Resources
import android.os.Bundle
import android.util.Log
import androidx.core.os.ConfigurationCompat
import androidx.fragment.app.FragmentManager
import androidx.preference.Preference
Expand Down Expand Up @@ -33,36 +35,35 @@ class LanguagePreferenceFragment : PreferenceFragmentCompat(), Preference.OnPref
* Also update the app language using app compat.
*/
override fun onPreferenceClick(preference: Preference): Boolean {

try {

context?.let { ctx ->

var id = preference.key

if (preference.key == "com.fieldbook.tracker.preference.language.default") {
id = ConfigurationCompat.getLocales(Resources.getSystem().configuration)[0]?.language ?: "en-US"
}
Log.d("LanguagePrefFragment", "Switching language to: $id")
with (PreferenceManager.getDefaultSharedPreferences(ctx)) {

if (preference.key == "com.fieldbook.tracker.preference.language.default") {

id = ConfigurationCompat.getLocales(Resources.getSystem().configuration).get(0)?.language

}

edit().putString(GeneralKeys.LANGUAGE_LOCALE_ID, id).apply()
edit().putString(GeneralKeys.LANGUAGE_LOCALE_SUMMARY, preference.title.toString()).apply()
}

AppLanguageUtil.refreshAppText(context)
AlertDialog.Builder(ctx, R.style.AppAlertDialog).apply {
setTitle(context.getString(R.string.dialog_warning))
setMessage(context.getString(R.string.preference_language_warning))
setPositiveButton(context.getString(android.R.string.ok)) { dialog, _ ->
AppLanguageUtil.refreshAppText(ctx)
dialog.dismiss()
parentFragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE)
}
setCancelable(false)
show()
}
}

} catch (e: Exception) {

e.printStackTrace()

Log.e("LanguagePreference", "Error in onPreferenceClick: ${e.message}")
}

parentFragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE)

return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,59 +184,56 @@ private void setAdapter(ArrayList<BrAPIScaleValidValuesCategories> cats) {
layoutManager.setAlignItems(AlignItems.STRETCH);
gridMultiCat.setLayoutManager(layoutManager);

if (!((CollectActivity) getContext()).isDataLocked()) {
gridMultiCat.setAdapter(new CategoryTraitAdapter(getContext()) {

gridMultiCat.setAdapter(new CategoryTraitAdapter(getContext()) {

@Override
public void onBindViewHolder(CategoryTraitViewHolder holder, int position) {
holder.bindTo();
@Override
public void onBindViewHolder(CategoryTraitViewHolder holder, int position) {
holder.bindTo();

//get the label for this position
BrAPIScaleValidValuesCategories pair = cats.get(position);
//get the label for this position
BrAPIScaleValidValuesCategories pair = cats.get(position);

//update button with the preference based text
if (labelValPref.equals("value")) {
//update button with the preference based text
if (labelValPref.equals("value")) {

holder.mButton.setText(pair.getValue());
holder.mButton.setText(pair.getValue());

} else {
} else {

holder.mButton.setText(pair.getLabel());
holder.mButton.setText(pair.getLabel());

}
}

//set the buttons tag to the json, when clicked this is updated in db
holder.mButton.setTag(pair);
holder.mButton.setOnClickListener(createClickListener(holder.mButton, position));
//set the buttons tag to the json, when clicked this is updated in db
holder.mButton.setTag(pair);
holder.mButton.setOnClickListener(createClickListener(holder.mButton, position));

//update the button's state if this category is selected
String currentText = getCollectInputView().getText();
//update the button's state if this category is selected
String currentText = getCollectInputView().getText();

if (labelValPref.equals("value")) {
if (labelValPref.equals("value")) {

if (currentText.equals(pair.getValue())) {
if (currentText.equals(pair.getValue())) {

pressOnButton(holder.mButton);
pressOnButton(holder.mButton);

} else pressOffButton(holder.mButton);
} else pressOffButton(holder.mButton);

} else {
} else {

if (currentText.equals(pair.getLabel())) {
if (currentText.equals(pair.getLabel())) {

pressOnButton(holder.mButton);
pressOnButton(holder.mButton);

} else pressOffButton(holder.mButton);
}
} else pressOffButton(holder.mButton);
}
}

@Override
public int getItemCount() {
return cats.size();
}
});
}
@Override
public int getItemCount() {
return cats.size();
}
});

gridMultiCat.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
Expand Down
Loading

0 comments on commit 4d3585b

Please sign in to comment.