Skip to content

Commit

Permalink
Added sort functionality in MainActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb-yun committed Jul 18, 2018
1 parent 01c1fc6 commit 229a8af
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 26 deletions.
5 changes: 2 additions & 3 deletions .idea/assetWizardSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 59 additions & 21 deletions app/src/main/java/com/cogentworks/overwidget/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import com.woxthebox.draglistview.swipe.ListSwipeItem;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class MainActivity extends AppCompatActivity {

Expand Down Expand Up @@ -251,6 +253,10 @@ public boolean onPrepareOptionsMenu(Menu menu) {
.getBoolean(SettingsActivity.PREF_DARK_THEME, false);
checkable.setChecked(isDark);

MenuItem sort = menu.findItem(R.id.sort);
if (isDark)
sort.setIcon(R.drawable.ic_sort);

return true;
}

Expand All @@ -275,44 +281,76 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.settings:
startActivityForResult(new Intent(this, SettingsActivity.class), REQUEST_EXIT);
return true;
/*case R.id.sort:
ItemAdapter listAdapter = new ItemAdapter(mItemArray, R.layout.list_item, R.id.layout_main, true);
mDragListView.setAdapter(listAdapter, true);
return true;*/
case R.id.sort:
sortItemsDialog();
return true;
default:
return false;
}
}

/*private void sortItemsDialog() {
private static int lastSortItem;

private void sortItemsDialog() {
if (!isBusy) {
AlertDialog dialog = new AlertDialog.Builder(this)
.setTitle("Sort by")
.setSingleChoiceItems(R.)
.setPositiveButton("Add", new DialogInterface.OnClickListener() {
.setSingleChoiceItems(R.array.sort_array, lastSortItem, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
EditText editText = dialogView.findViewById(R.id.config_battletag);
String battleTag = String.valueOf(editText.getText());
Spinner platformSpinner = dialogView.findViewById(R.id.platform_spinner);
String platform = platformSpinner.getSelectedItem().toString();
Spinner regionSpinner = dialogView.findViewById(R.id.region_spinner);
String region = regionSpinner.getSelectedItem().toString();
if (!dbHelper.getList("BattleTag").contains(battleTag)) {
Toast.makeText(findViewById(R.id.swiperefresh).getContext(), "Adding player...", Toast.LENGTH_SHORT).show();
AddProfileTask addTask = new AddProfileTask(context, battleTag, platform, region);
addTask.execute();
} else {
Snackbar.make(findViewById(R.id.layout_main), "Player already added to list", Snackbar.LENGTH_SHORT).show();
ArrayList<Profile> itemList = dbHelper.getList();
Comparator<Profile> comparator;
switch (which) {
case 0: // Name
comparator = new Comparator<Profile>() {
@Override
public int compare(Profile o1, Profile o2) {
return o1.BattleTag.compareTo(o2.BattleTag);
}
};
break;
case 1: // SR
comparator = new Comparator<Profile>() {
@Override
public int compare(Profile o1, Profile o2) {
int compRank1 = 0;
if (!o1.CompRank.equals(""))
compRank1 = Integer.parseInt(o1.CompRank);
int compRank2 = 0;
if (!o2.CompRank.equals(""))
compRank2 = Integer.parseInt(o2.CompRank);
return compRank2 - compRank1;
}
};
break;
case 2: // Level
comparator = new Comparator<Profile>() {
@Override
public int compare(Profile o1, Profile o2) {
int level1 = Integer.parseInt(o1.Level) + Integer.parseInt(o1.Prestige) * 100;
int level2 = Integer.parseInt(o2.Level) + Integer.parseInt(o2.Prestige) * 100;
return level2 - level1;
}
};
break;
default:
return;
}
Collections.sort(itemList, comparator);

ItemAdapter listAdapter = new ItemAdapter(itemList, R.layout.list_item, R.id.layout_main, true);
mDragListView.setAdapter(listAdapter, true);

dbHelper.setList(itemList);
lastSortItem = which;
dialog.dismiss();
}
})
.setNegativeButton("Cancel", null)
.create();
dialog.show();
}
}*/
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_sort.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M3,18h6v-2L3,16v2zM3,6v2h18L21,6L3,6zM3,13h12v-2L3,11v2z"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_sort_black.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M3,18h6v-2L3,16v2zM3,6v2h18L21,6L3,6zM3,13h12v-2L3,11v2z"/>
</vector>
6 changes: 4 additions & 2 deletions app/src/main/res/menu/menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
android:title="Blackwatch"
android:checkable="true" />

<!--<item
<item
android:id="@+id/sort"
android:title="Sort" />-->
android:title="Sort"
android:icon="@drawable/ic_sort_black"
app:showAsAction="always"/>
</menu>
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
<item>Overbuff</item>
<item>Master Overwatch</item>
</string-array>
<string-array name="sort_array">
<item>Name</item>
<item>SR</item>
<item>Level</item>
</string-array>
<string name="title_activity_main">OverWidget</string>
<string name="title_activity_settings">Settings</string>

Expand Down

0 comments on commit 229a8af

Please sign in to comment.