Merge pull request #1661 from mfietz/issue/1652-opml-select
OPML Import: Select/deselect toggle
This commit is contained in:
commit
987aef38fc
|
@ -2,23 +2,22 @@ package de.danoeh.antennapod.activity;
|
|||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.util.SparseBooleanArray;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.core.opml.OpmlElement;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.core.opml.OpmlElement;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
|
||||
/**
|
||||
* Displays the feeds that the OPML-Importer has read and lets the user choose
|
||||
* which feeds he wants to import.
|
||||
|
@ -33,6 +32,9 @@ public class OpmlFeedChooserActivity extends ActionBarActivity {
|
|||
private ListView feedlist;
|
||||
private ArrayAdapter<String> listAdapter;
|
||||
|
||||
private MenuItem selectAll;
|
||||
private MenuItem deselectAll;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
setTheme(UserPreferences.getTheme());
|
||||
|
@ -44,45 +46,54 @@ public class OpmlFeedChooserActivity extends ActionBarActivity {
|
|||
feedlist = (ListView) findViewById(R.id.feedlist);
|
||||
|
||||
feedlist.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
||||
listAdapter = new ArrayAdapter<String>(this,
|
||||
listAdapter = new ArrayAdapter<>(this,
|
||||
android.R.layout.simple_list_item_multiple_choice,
|
||||
getTitleList());
|
||||
|
||||
feedlist.setAdapter(listAdapter);
|
||||
|
||||
butCancel.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
feedlist.setOnItemClickListener((parent, view, position, id) -> {
|
||||
SparseBooleanArray checked = feedlist.getCheckedItemPositions();
|
||||
int checkedCount = 0;
|
||||
for (int i = 0; i < checked.size(); i++) {
|
||||
if (checked.valueAt(i)) {
|
||||
checkedCount++;
|
||||
}
|
||||
}
|
||||
if(checkedCount == listAdapter.getCount()) {
|
||||
selectAll.setVisible(false);
|
||||
deselectAll.setVisible(true);
|
||||
} else {
|
||||
deselectAll.setVisible(false);
|
||||
selectAll.setVisible(true);
|
||||
}
|
||||
});
|
||||
|
||||
butConfirm.setOnClickListener(new OnClickListener() {
|
||||
butCancel.setOnClickListener(v -> {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
});
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent();
|
||||
SparseBooleanArray checked = feedlist.getCheckedItemPositions();
|
||||
butConfirm.setOnClickListener(v -> {
|
||||
Intent intent = new Intent();
|
||||
SparseBooleanArray checked = feedlist.getCheckedItemPositions();
|
||||
|
||||
int checkedCount = 0;
|
||||
// Get number of checked items
|
||||
for (int i = 0; i < checked.size(); i++) {
|
||||
if (checked.valueAt(i)) {
|
||||
checkedCount++;
|
||||
}
|
||||
int checkedCount = 0;
|
||||
// Get number of checked items
|
||||
for (int i = 0; i < checked.size(); i++) {
|
||||
if (checked.valueAt(i)) {
|
||||
checkedCount++;
|
||||
}
|
||||
int[] selection = new int[checkedCount];
|
||||
for (int i = 0, collected = 0; collected < checkedCount; i++) {
|
||||
if (checked.valueAt(i)) {
|
||||
selection[collected] = checked.keyAt(i);
|
||||
collected++;
|
||||
}
|
||||
}
|
||||
intent.putExtra(EXTRA_SELECTED_ITEMS, selection);
|
||||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
}
|
||||
int[] selection = new int[checkedCount];
|
||||
for (int i = 0, collected = 0; collected < checkedCount; i++) {
|
||||
if (checked.valueAt(i)) {
|
||||
selection[collected] = checked.keyAt(i);
|
||||
collected++;
|
||||
}
|
||||
}
|
||||
intent.putExtra(EXTRA_SELECTED_ITEMS, selection);
|
||||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
});
|
||||
|
||||
}
|
||||
|
@ -93,7 +104,6 @@ public class OpmlFeedChooserActivity extends ActionBarActivity {
|
|||
for (OpmlElement element : OpmlImportHolder.getReadElements()) {
|
||||
result.add(element.getText());
|
||||
}
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -101,13 +111,11 @@ public class OpmlFeedChooserActivity extends ActionBarActivity {
|
|||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
super.onCreateOptionsMenu(menu);
|
||||
MenuItemCompat.setShowAsAction(menu.add(Menu.NONE, R.id.select_all_item, Menu.NONE,
|
||||
R.string.select_all_label),
|
||||
MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
|
||||
|
||||
MenuItemCompat.setShowAsAction(menu.add(Menu.NONE, R.id.deselect_all_item, Menu.NONE,
|
||||
R.string.deselect_all_label),
|
||||
MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.opml_selection_options, menu);
|
||||
selectAll = menu.findItem(R.id.select_all_item);
|
||||
deselectAll = menu.findItem(R.id.deselect_all_item);
|
||||
deselectAll.setVisible(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -115,10 +123,14 @@ public class OpmlFeedChooserActivity extends ActionBarActivity {
|
|||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.select_all_item:
|
||||
selectAll.setVisible(false);
|
||||
selectAllItems(true);
|
||||
deselectAll.setVisible(true);
|
||||
return true;
|
||||
case R.id.deselect_all_item:
|
||||
deselectAll.setVisible(false);
|
||||
selectAllItems(false);
|
||||
selectAll.setVisible(true);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:custom="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@id/select_all_item"
|
||||
android:icon="?attr/ic_check_box_outline"
|
||||
android:title="@string/select_all_label"
|
||||
custom:showAsAction="ifRoom">
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@id/deselect_all_item"
|
||||
android:icon="?attr/ic_check_box"
|
||||
android:title="@string/deselect_all_label"
|
||||
custom:showAsAction="ifRoom">
|
||||
</item>
|
||||
|
||||
</menu>
|
Loading…
Reference in New Issue