Skip to content

Commit 215a93d

Browse files
committed
fix for uiPager search casting & generics
1 parent c72ad23 commit 215a93d

File tree

1 file changed

+41
-41
lines changed
  • SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/menuStates/uiPager

1 file changed

+41
-41
lines changed

SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/menuStates/uiPager/UiPager.java

+41-41
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
import android.view.ViewGroup;
99
import android.widget.GridLayout;
1010
import android.widget.ScrollView;
11-
import com.scrappers.superiorExtendedEngine.menuStates.UiStateManager;
12-
import com.scrappers.superiorExtendedEngine.menuStates.UiStatesLooper;
1311
import java.util.Arrays;
1412
import java.util.ConcurrentModificationException;
1513
import java.util.HashMap;
1614
import java.util.concurrent.Executors;
1715
import androidx.annotation.IdRes;
1816

17+
import com.scrappers.superiorExtendedEngine.menuStates.UiStateManager;
18+
import com.scrappers.superiorExtendedEngine.menuStates.UiStatesLooper;
19+
1920
/**
2021
* A UiState Class that could hold multiple UiStates in a list/grid form.
2122
* The UiPager, UiState does extend #{@link GridLayout}, so you can use all the functionality of it as rows/columns.
@@ -69,12 +70,12 @@ public UiPager(ViewGroup viewGroup) {
6970
* @return a scroll view instance representing a Scrollable Container
7071
*/
7172
public ScrollView initializeScrollableContainer(){
72-
ScrollView scrollView = new ScrollView(getContext());
73-
scrollView.setLayoutParams(getLayoutParams());
74-
scrollView.setSmoothScrollingEnabled(true);
75-
scrollView.setScrollContainer(true);
76-
setScrollContainer(true);
77-
scrollView.addView(this);
73+
ScrollView scrollView = new ScrollView(getContext());
74+
scrollView.setLayoutParams(getLayoutParams());
75+
scrollView.setSmoothScrollingEnabled(true);
76+
scrollView.setScrollContainer(true);
77+
setScrollContainer(true);
78+
scrollView.addView(this);
7879
return scrollView;
7980
}
8081

@@ -195,7 +196,7 @@ public void forEachUiState(UiStatesLooper.Modifiable.Looper uiStatesLooper){
195196
* @return a list of the founded strings from the searchList based on the search keywords.
196197
*/
197198
public <M extends PageDataModel> M[] search(M[] searchList, String[] searchKeyWords, ActionInjector injector) {
198-
M[] resultList = (M[]) new PageDataModel[0];
199+
M[] resultList = Arrays.copyOf(searchList, 0);
199200
M[] temp;
200201
int index = 0;
201202
//loop over the main list items
@@ -209,7 +210,7 @@ public <M extends PageDataModel> M[] search(M[] searchList, String[] searchKeyWo
209210
//creating temp pointer producing a deep copy of resultList[0] array
210211
temp = resultList;
211212
//expanding the array through a new wider in size pointer
212-
resultList = (M[]) new PageDataModel[temp.length + 1];
213+
resultList = Arrays.copyOf(resultList, resultList.length + 1);
213214
//copy the values of the old contacted array to the new expanded one
214215
int position = 0;
215216
while (position < temp.length) {
@@ -238,43 +239,42 @@ public <M extends PageDataModel> M[] search(M[] searchList, String[] searchKeyWo
238239
* @param list the list to order sort for.
239240
* @param sortAlgorithm the sort algorithm either {@link UiPager#A_Z} or {@link UiPager#Z_A}.
240241
* @return the new sorted String in the shape of Collection List.
241-
* @throws Exception if process is interrupted or -1 is returned.
242242
* @apiNote you will need to loop over this list to provide the uiStates with new update.
243243
*/
244-
public <M extends PageDataModel> M[] sort(M[] list, int sortAlgorithm) throws Exception {
244+
public <M extends PageDataModel> M[] sort(M[] list, int sortAlgorithm) {
245245
//to apply the sort change as an external final change on a list copy (warning : ->Internal List change(positions or items count or items values) = Malicious Activity
246246
final M[] copy = Arrays.copyOf(list, list.length);
247-
M tempPointer;
248-
//main String List looping
249-
for (int i = 0; i < copy.length; i++) {
250-
//looping over the String again to compare each one String member var with the sequence of the String member vars after that item
251-
for(int j = i+1; j < copy.length; j++ ){
252-
//sort from A-Z ascendingly
253-
if(sortAlgorithm == A_Z){
254-
//compare 2 strings lexicographically based on their characters, if the (string object > the argument string) then compareTo returns 1
255-
if ( copy[i].getSortingData().toLowerCase().compareTo(copy[j].getSortingData().toLowerCase()) > 0 ){
256-
//then swap list[i] & list[j] because list[i] is after the list[k]
257-
//store the list[i] inside the tempPointer for later access
258-
tempPointer = copy[i];
259-
//get the list[i] after
260-
copy[i] = copy[j];
261-
//get the list[j] before
262-
copy[j] = tempPointer;
263-
}
264-
}else if(sortAlgorithm == Z_A){
265-
//compare 2 strings lexicographically based on their characters, if the (string object < the argument string) then compareTo returns -1
266-
if ( copy[i].getSortingData().toLowerCase().compareTo(copy[j].getSortingData().toLowerCase()) < 0){
267-
//then swap list[i] & list[j] because list[i] is before the list[k]
268-
//store the list[j] inside the tempPointer for later access
269-
tempPointer = copy[j];
270-
//get the list[j] before
271-
copy[j] = copy[i];
272-
//get the list[i] after
273-
copy[i] = tempPointer;
274-
}
275-
}
247+
M tempPointer;
248+
//main String List looping
249+
for (int i = 0; i < copy.length; i++) {
250+
//looping over the String again to compare each one String member var with the sequence of the String member vars after that item
251+
for(int j = i+1; j < copy.length; j++ ){
252+
//sort from A-Z ascendingly
253+
if(sortAlgorithm == A_Z){
254+
//compare 2 strings lexicographically based on their characters, if the (string object > the argument string) then compareTo returns 1
255+
if ( copy[i].getSortingData().toLowerCase().compareTo(copy[j].getSortingData().toLowerCase()) > 0 ){
256+
//then swap list[i] & list[j] because list[i] is after the list[k]
257+
//store the list[i] inside the tempPointer for later access
258+
tempPointer = copy[i];
259+
//get the list[i] after
260+
copy[i] = copy[j];
261+
//get the list[j] before
262+
copy[j] = tempPointer;
263+
}
264+
}else if(sortAlgorithm == Z_A){
265+
//compare 2 strings lexicographically based on their characters, if the (string object < the argument string) then compareTo returns -1
266+
if ( copy[i].getSortingData().toLowerCase().compareTo(copy[j].getSortingData().toLowerCase()) < 0){
267+
//then swap list[i] & list[j] because list[i] is before the list[k]
268+
//store the list[j] inside the tempPointer for later access
269+
tempPointer = copy[j];
270+
//get the list[j] before
271+
copy[j] = copy[i];
272+
//get the list[i] after
273+
copy[i] = tempPointer;
276274
}
277275
}
276+
}
277+
}
278278
return copy;
279279
}
280280
/**

0 commit comments

Comments
 (0)