Improved the helpers package.

This commit is contained in:
Simon Sarasova 2024-08-11 12:31:40 +00:00
parent 60ee8afb6c
commit 1f30bfa71c
No known key found for this signature in database
GPG key ID: EEDA4103C9C36944
13 changed files with 24 additions and 46 deletions

View file

@ -9,4 +9,4 @@ Many other people have written code for modules which are imported by Seekia. Th
Name | Date Of First Commit | Number Of Commits Name | Date Of First Commit | Number Of Commits
--- | --- | --- --- | --- | ---
Simon Sarasova | June 13, 2023 | 276 Simon Sarasova | June 13, 2023 | 277

View file

@ -2451,7 +2451,7 @@ func setBuildMateProfilePage_Tags(window fyne.Window, previousPage func()){
deleteButton := widget.NewButtonWithIcon("", theme.DeleteIcon(), func(){ deleteButton := widget.NewButtonWithIcon("", theme.DeleteIcon(), func(){
newList, deletedAny := helpers.DeleteAllMatchingItemsFromStringList(myTagsList, tagName) newList, deletedAny := helpers.DeleteAllMatchingItemsFromList(myTagsList, tagName)
if (deletedAny == false){ if (deletedAny == false){
setErrorEncounteredPage(window, errors.New("Cannot delete tag: tag not found."), currentPage) setErrorEncounteredPage(window, errors.New("Cannot delete tag: tag not found."), currentPage)
return return

View file

@ -2445,7 +2445,7 @@ func setBuildMateProfilePage_EyeColor(window fyne.Window, previousPage func()){
getNewAttributeList := func()[]string{ getNewAttributeList := func()[]string{
if (newChoice == false){ if (newChoice == false){
newList, _ := helpers.DeleteAllMatchingItemsFromStringList(currentEyeColorList, colorName) newList, _ := helpers.DeleteAllMatchingItemsFromList(currentEyeColorList, colorName)
return newList return newList
} }
@ -2613,7 +2613,7 @@ func setBuildMateProfilePage_HairColor(window fyne.Window, previousPage func()){
getNewAttributeList := func()[]string{ getNewAttributeList := func()[]string{
if (newChoice == false){ if (newChoice == false){
newList, _ := helpers.DeleteAllMatchingItemsFromStringList(currentHairColorList, colorName) newList, _ := helpers.DeleteAllMatchingItemsFromList(currentHairColorList, colorName)
return newList return newList
} }

View file

@ -482,7 +482,7 @@ func setAddContactFromIdentityHashPage(window fyne.Window, userIdentityHash [16]
newContactCategoriesList := helpers.AddItemToStringListAndAvoidDuplicate(currentContactCategoriesList, categoryName) newContactCategoriesList := helpers.AddItemToStringListAndAvoidDuplicate(currentContactCategoriesList, categoryName)
contactCategoriesListBinding.Set(newContactCategoriesList) contactCategoriesListBinding.Set(newContactCategoriesList)
} else { } else {
newContactCategoriesList, _ := helpers.DeleteAllMatchingItemsFromStringList(currentContactCategoriesList, categoryName) newContactCategoriesList, _ := helpers.DeleteAllMatchingItemsFromList(currentContactCategoriesList, categoryName)
contactCategoriesListBinding.Set(newContactCategoriesList) contactCategoriesListBinding.Set(newContactCategoriesList)
} }
} }
@ -785,8 +785,8 @@ func setEditContactCategoriesPage(window fyne.Window, contactIdentityHash [16]by
newCategoriesList := append(currentContactCategoriesList, categoryName) newCategoriesList := append(currentContactCategoriesList, categoryName)
return newCategoriesList return newCategoriesList
} }
newCategoriesList, _ := helpers.DeleteAllMatchingItemsFromStringList(currentContactCategoriesList, categoryName) newCategoriesList, _ := helpers.DeleteAllMatchingItemsFromList(currentContactCategoriesList, categoryName)
return newCategoriesList return newCategoriesList
} }

View file

@ -275,7 +275,7 @@ func setChooseDesiresPage_ProfileLanguage(window fyne.Window, previousPage func(
deleteLanguageButton := widget.NewButtonWithIcon("", theme.DeleteIcon(), func(){ deleteLanguageButton := widget.NewButtonWithIcon("", theme.DeleteIcon(), func(){
newDesiredLanguagesList, _ := helpers.DeleteAllMatchingItemsFromStringList(currentDesiredChoicesList, languageIdentifierBase64) newDesiredLanguagesList, _ := helpers.DeleteAllMatchingItemsFromList(currentDesiredChoicesList, languageIdentifierBase64)
if (len(newDesiredLanguagesList) == 0){ if (len(newDesiredLanguagesList) == 0){
@ -499,7 +499,7 @@ func setChooseDesiresPage_Country(window fyne.Window, previousPage func()){
deleteCountryButton := widget.NewButtonWithIcon("", theme.DeleteIcon(), func(){ deleteCountryButton := widget.NewButtonWithIcon("", theme.DeleteIcon(), func(){
newDesiredCountriesList, _ := helpers.DeleteAllMatchingItemsFromStringList(currentDesiredChoicesList, countryIdentifierBase64) newDesiredCountriesList, _ := helpers.DeleteAllMatchingItemsFromList(currentDesiredChoicesList, countryIdentifierBase64)
if (len(newDesiredCountriesList) == 0){ if (len(newDesiredCountriesList) == 0){
@ -805,7 +805,7 @@ func setChooseDesiresPage_SearchTerms(window fyne.Window, previousPage func()){
deleteTermButton := widget.NewButtonWithIcon("", theme.DeleteIcon(), func(){ deleteTermButton := widget.NewButtonWithIcon("", theme.DeleteIcon(), func(){
newDesiredTermsList, _ := helpers.DeleteAllMatchingItemsFromStringList(currentDesiredChoicesList, termNameBase64) newDesiredTermsList, _ := helpers.DeleteAllMatchingItemsFromList(currentDesiredChoicesList, termNameBase64)
if (len(newDesiredTermsList) == 0){ if (len(newDesiredTermsList) == 0){
@ -1287,7 +1287,7 @@ func getDesireEditor_Choice(window fyne.Window, currentPage func(), desireName s
return emptyList return emptyList
} }
newAttributeList, _ := helpers.DeleteAllMatchingItemsFromStringList(currentDesiredChoicesList, "Other") newAttributeList, _ := helpers.DeleteAllMatchingItemsFromList(currentDesiredChoicesList, "Other")
return newAttributeList return newAttributeList
} }

View file

@ -109,7 +109,7 @@ func setChooseDesiresPage_Language(window fyne.Window, previousPage func()){
if (response == false){ if (response == false){
newList, _ := helpers.DeleteAllMatchingItemsFromStringList(currentDesiredChoicesList, "Other") newList, _ := helpers.DeleteAllMatchingItemsFromList(currentDesiredChoicesList, "Other")
return newList return newList
} }
@ -195,7 +195,8 @@ func setChooseDesiresPage_Language(window fyne.Window, previousPage func()){
languageNameLabel := getBoldLabelCentered(translate(languageName)) languageNameLabel := getBoldLabelCentered(translate(languageName))
deleteLanguageButton := widget.NewButtonWithIcon("", theme.DeleteIcon(), func(){ deleteLanguageButton := widget.NewButtonWithIcon("", theme.DeleteIcon(), func(){
newDesiredLanguagesList, _ := helpers.DeleteAllMatchingItemsFromStringList(currentDesiredChoicesList, languageNameBase64)
newDesiredLanguagesList, _ := helpers.DeleteAllMatchingItemsFromList(currentDesiredChoicesList, languageNameBase64)
if (len(newDesiredLanguagesList) == 0){ if (len(newDesiredLanguagesList) == 0){

View file

@ -1305,7 +1305,7 @@ func setChooseDesiresPage_23andMe_Haplogroup(window fyne.Window, maternalOrPater
return emptyList return emptyList
} }
newAttributeList, _ := helpers.DeleteAllMatchingItemsFromStringList(currentDesiredChoicesList, "Other") newAttributeList, _ := helpers.DeleteAllMatchingItemsFromList(currentDesiredChoicesList, "Other")
return newAttributeList return newAttributeList
} }
@ -1393,7 +1393,7 @@ func setChooseDesiresPage_23andMe_Haplogroup(window fyne.Window, maternalOrPater
deleteHaplogroupButton := widget.NewButtonWithIcon("", theme.DeleteIcon(), func(){ deleteHaplogroupButton := widget.NewButtonWithIcon("", theme.DeleteIcon(), func(){
newDesiredHaplogroupsList, _ := helpers.DeleteAllMatchingItemsFromStringList(currentDesiredChoicesList, haplogroupNameBase64) newDesiredHaplogroupsList, _ := helpers.DeleteAllMatchingItemsFromList(currentDesiredChoicesList, haplogroupNameBase64)
if (len(newDesiredHaplogroupsList) == 0){ if (len(newDesiredHaplogroupsList) == 0){

View file

@ -1329,7 +1329,7 @@ func setCreateCouplePage(window fyne.Window, previousPage func()){
return return
} }
newList, deletedAny := helpers.DeleteAllMatchingItemsFromStringList(existingList, personIdentifier) newList, deletedAny := helpers.DeleteAllMatchingItemsFromList(existingList, personIdentifier)
if (deletedAny == false){ if (deletedAny == false){
setErrorEncounteredPage(window, errors.New("Person not found when trying to delete person from chosen people list."), currentPage) setErrorEncounteredPage(window, errors.New("Person not found when trying to delete person from chosen people list."), currentPage)
return return

View file

@ -762,7 +762,7 @@ func setBrowseMatchesPage(window fyne.Window, previousPage func()){
currentAttributesList := strings.Split(currentAttributesListString, ",") currentAttributesList := strings.Split(currentAttributesListString, ",")
displayAttributesListPruned, _ := helpers.DeleteAllMatchingItemsFromStringList(currentAttributesList, currentSortByAttribute) displayAttributesListPruned, _ := helpers.DeleteAllMatchingItemsFromList(currentAttributesList, currentSortByAttribute)
newDisplayAttributesList := []string{currentSortByAttribute} newDisplayAttributesList := []string{currentSortByAttribute}
@ -1390,7 +1390,7 @@ func setCustomizeMatchDisplayPage(window fyne.Window, previousPage func()){
deleteAttributeButton := widget.NewButtonWithIcon("", theme.DeleteIcon(), func(){ deleteAttributeButton := widget.NewButtonWithIcon("", theme.DeleteIcon(), func(){
newAttributesList, _ := helpers.DeleteAllMatchingItemsFromStringList(customDisplayAttributesList, attributeName) newAttributesList, _ := helpers.DeleteAllMatchingItemsFromList(customDisplayAttributesList, attributeName)
if (len(newAttributesList) == 0){ if (len(newAttributesList) == 0){

View file

@ -1098,34 +1098,11 @@ func DeleteIndexFromStringList(inputList []string, indexToDelete int)([]string,
//Outputs: //Outputs:
// -[]string: New list // -[]string: New list
// -bool: Deleted any items // -bool: Deleted any items
func DeleteAllMatchingItemsFromStringList(inputList []string, itemToDelete string)([]string, bool){ func DeleteAllMatchingItemsFromList[E comparable](inputList []E, itemToDelete E)([]E, bool){
listCopy := slices.Clone(inputList) listCopy := slices.Clone(inputList)
deletionFunction := func(input string)bool{ deletionFunction := func(input E)bool{
if (input == itemToDelete){
return true
}
return false
}
newList := slices.DeleteFunc(listCopy, deletionFunction)
if (len(newList) == len(inputList)){
return newList, false
}
return newList, true
}
//Outputs:
// -[]string: New list
// -bool: Deleted any items
func DeleteAllMatchingItemsFromProfileHashList(inputList [][28]byte, itemToDelete [28]byte)([][28]byte, bool){
listCopy := slices.Clone(inputList)
deletionFunction := func(input [28]byte)bool{
if (input == itemToDelete){ if (input == itemToDelete){
return true return true
} }

View file

@ -776,7 +776,7 @@ func GetProfileVerdictMaps(profileHash [28]byte, profileNetworkType byte, integr
} }
// We can omit the current profileHash, because we are already checking it // We can omit the current profileHash, because we are already checking it
attributeProfileHashesList, _ := helpers.DeleteAllMatchingItemsFromProfileHashList(attributeProfilesList, profileHash) attributeProfileHashesList, _ := helpers.DeleteAllMatchingItemsFromList(attributeProfilesList, profileHash)
return attributeProfileHashesList, nil return attributeProfileHashesList, nil
} }

View file

@ -467,7 +467,7 @@ func DeleteContactCategory(identityType string, categoryToDeleteName string)erro
contactCategoriesListBase64 := strings.Split(contactCategoriesListString, "+") contactCategoriesListBase64 := strings.Split(contactCategoriesListString, "+")
newCategoriesList, deletedAny := helpers.DeleteAllMatchingItemsFromStringList(contactCategoriesListBase64, categoryToDeleteNameBase64) newCategoriesList, deletedAny := helpers.DeleteAllMatchingItemsFromList(contactCategoriesListBase64, categoryToDeleteNameBase64)
if (deletedAny == false){ if (deletedAny == false){
newContactsMapList = append(newContactsMapList, contactMap) newContactsMapList = append(newContactsMapList, contactMap)
continue continue

View file

@ -163,7 +163,7 @@ func (listObject *MyList) DeleteListItem(item string)error{
currentList := listObject.memoryList currentList := listObject.memoryList
newList, anyDeleted := helpers.DeleteAllMatchingItemsFromStringList(currentList, item) newList, anyDeleted := helpers.DeleteAllMatchingItemsFromList(currentList, item)
if (anyDeleted == false){ if (anyDeleted == false){
listObject.memoryMutex.Unlock() listObject.memoryMutex.Unlock()
return nil return nil