Skip to content

Commit

Permalink
DigitalCampus#560: Implemented actionBar functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
jjoseba committed Sep 7, 2016
1 parent 3344140 commit c3d1eb7
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 33 deletions.
Expand Up @@ -73,7 +73,6 @@ public class DownloadMediaActivity extends AppActivity implements DownloadMediaL
private DownloadMediaListAdapter dmla;
private DownloadBroadcastReceiver receiver;
Button downloadViaPCBtn;
private Button downloadAll;
private TextView emptyState;
private boolean isSortByCourse;
private TextView downloadSelected;
Expand Down Expand Up @@ -118,12 +117,19 @@ public void onItemCheckedStateChanged(ActionMode mode, int position, long id, bo
}else{
mediaSelected.remove(missingMedia.get(position));
}

int count = mediaSelected.size();
mode.setSubtitle(count == 1 ? count + " item selected" : count + " items selected");


}

@Override
public boolean onCreateActionMode(final ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.missing_media_sortby, menu);

onPrepareOptionsMenu(menu);

mode.setTitle("Download Media");

if (missingMediaContainer.getVisibility() != View.VISIBLE){
missingMediaContainer.setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -157,17 +163,36 @@ public void onClick(View view) {
}

@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {return false; }

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return false;
switch(item.getItemId()){
case R.id.menu_sort_by: {
if(isSortByCourse){
dmla.sortByFilename();
isSortByCourse = false;
item.setTitle(getString(R.string.menu_sort_by_course));
}else{
dmla.sortByCourse();
isSortByCourse = true;
item.setTitle(getString(R.string.menu_sort_by_filename));
}
invalidateOptionsMenu();
return true;
}
case R.id.menu_select_all:
for(int i= 0; i < mediaList.getAdapter().getCount(); i++){
mediaList.setItemChecked(i, true);
}
return true;
default: return true;
}
}

@Override
public void onDestroyActionMode(ActionMode mode) {
mediaSelected.clear();
hideDownloadMediaMessage();
}
});
Expand All @@ -176,20 +201,6 @@ public void onDestroyActionMode(ActionMode mode) {
downloadSelected = (TextView) this.findViewById(R.id.download_selected);
unselectAll = (TextView) this.findViewById(R.id.unselect_all);

downloadAll = (Button) this.findViewById(R.id.download_all);
downloadAll.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
DownloadMode mode = downloadAll.getText().equals("Download All") ? DownloadMode.DOWNLOAD_ALL : DownloadMode.STOP_ALL;
downloadAll.setText(downloadAll.getText().equals("Download All") ? "Stop All" : "Download All");
for(int i = 0; i < missingMedia.size(); i++){

Media mediaToDownload = missingMedia.get(i);
downloadMedia(mediaToDownload, mode);
}
}
});


downloadViaPCBtn = (Button) this.findViewById(R.id.download_media_via_pc_btn);
downloadViaPCBtn.setOnClickListener(new OnClickListener() {
Expand Down Expand Up @@ -283,6 +294,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
invalidateOptionsMenu();
return true;
}
case R.id.menu_select_all:
for(int i= 0; i < mediaList.getAdapter().getCount(); i++){
mediaList.setItemChecked(i, true);
}
return true;
case android.R.id.home: onBackPressed(); return true;
default: return super.onOptionsItemSelected(item);
}
Expand Down
Binary file added app/src/main/res/drawable-hdpi/ic_options.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/ic_options.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_options.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 0 additions & 7 deletions app/src/main/res/layout/activity_download_media.xml
Expand Up @@ -11,13 +11,6 @@
android:layout_alignParentBottom="true"
android:orientation="vertical">

<Button
android:id="@+id/download_all"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_gravity="center"
android:text="Download All" />

<Button
android:id="@+id/download_media_via_pc_btn"
android:layout_width="fill_parent"
Expand Down
19 changes: 14 additions & 5 deletions app/src/main/res/menu/missing_media_sortby.xml
Expand Up @@ -2,9 +2,18 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:oppiamobile="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_sort_by"
android:title=""/>
<item
android:id="@+id/menu_select_all"
android:title="@string/menu_select_all" />
android:title="Options"
android:icon="@drawable/ic_options"
oppiamobile:showAsAction="ifRoom">
<menu>
<item
android:id="@+id/menu_sort_by"
android:title=""/>
<item
android:id="@+id/menu_select_all"
android:title="@string/menu_select_all" />
</menu>
</item>


</menu>

0 comments on commit c3d1eb7

Please sign in to comment.