diff options
Diffstat (limited to 'app/src/main/java/de')
6 files changed, 154 insertions, 29 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/DirectoryChooserActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/DirectoryChooserActivity.java index 559fa0574..fcd2680fa 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/DirectoryChooserActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/DirectoryChooserActivity.java @@ -5,7 +5,6 @@ import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; -import android.os.Environment; import android.os.FileObserver; import android.support.v4.app.NavUtils; import android.support.v7.app.ActionBarActivity; @@ -15,17 +14,24 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; -import android.widget.*; +import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; -import de.danoeh.antennapod.BuildConfig; -import de.danoeh.antennapod.R; -import de.danoeh.antennapod.core.preferences.UserPreferences; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.ImageButton; +import android.widget.ListView; +import android.widget.TextView; +import android.widget.Toast; import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import de.danoeh.antennapod.BuildConfig; +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.core.preferences.UserPreferences; + /** * Let's the user choose a directory on the storage device. The selected folder * will be sent back to the starting activity as an activity result. @@ -37,6 +43,7 @@ public class DirectoryChooserActivity extends ActionBarActivity { public static final String RESULT_SELECTED_DIR = "selected_dir"; public static final int RESULT_CODE_DIR_SELECTED = 1; + public static final String NON_EMPTY_DIRECTORY_WARNING = "warn_non_empty_directory"; private Button butConfirm; private Button butCancel; @@ -52,6 +59,8 @@ public class DirectoryChooserActivity extends ActionBarActivity { private FileObserver fileObserver; + private boolean warnNonEmptyDirectory = false; + @Override protected void onCreate(Bundle savedInstanceState) { setTheme(UserPreferences.getTheme()); @@ -65,15 +74,18 @@ public class DirectoryChooserActivity extends ActionBarActivity { txtvSelectedFolder = (TextView) findViewById(R.id.txtvSelectedFolder); listDirectories = (ListView) findViewById(R.id.directory_list); - butConfirm.setOnClickListener(new OnClickListener() { + if(getIntent().getExtras() != null) { + warnNonEmptyDirectory = getIntent().getExtras().getBoolean(NON_EMPTY_DIRECTORY_WARNING, false); + } + butConfirm.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (isValidFile(selectedDir)) { - if (selectedDir.list().length == 0) { - returnSelectedFolder(); + if(warnNonEmptyDirectory && selectedDir.list().length > 0) { + showNonEmptyDirectoryWarning(); } else { - showNonEmptyDirectoryWarning(); + returnSelectedFolder(); } } } @@ -145,7 +157,7 @@ public class DirectoryChooserActivity extends ActionBarActivity { listDirectoriesAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, filenames); listDirectories.setAdapter(listDirectoriesAdapter); - changeDirectory(Environment.getExternalStorageDirectory()); + changeDirectory(UserPreferences.getDataFolder(this, null)); } /** diff --git a/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportFromPathActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportFromPathActivity.java index 162a8f2e5..07fa6d21d 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportFromPathActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportFromPathActivity.java @@ -2,6 +2,7 @@ package de.danoeh.antennapod.activity; import android.app.AlertDialog; import android.content.DialogInterface; +import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.Menu; @@ -11,20 +12,26 @@ import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStreamReader; +import java.io.Reader; + import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.util.LangUtils; import de.danoeh.antennapod.core.util.StorageUtils; -import java.io.*; - /** * Lets the user start the OPML-import process from a path */ public class OpmlImportFromPathActivity extends OpmlImportBaseActivity { private static final String TAG = "OpmlImportFromPathActivity"; private TextView txtvPath; + private Button butChoose; private Button butStart; private String importPath; @@ -36,9 +43,20 @@ public class OpmlImportFromPathActivity extends OpmlImportBaseActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(true); setContentView(R.layout.opml_import); + butChoose = (Button)findViewById(R.id.butChoosePath); txtvPath = (TextView) findViewById(R.id.txtvPath); butStart = (Button) findViewById(R.id.butStartImport); + butChoose.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + startActivityForResult( + new Intent(OpmlImportFromPathActivity.this, + DirectoryChooserActivity.class), + DirectoryChooserActivity.RESULT_CODE_DIR_SELECTED + ); + } + }); butStart.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { @@ -46,13 +64,13 @@ public class OpmlImportFromPathActivity extends OpmlImportBaseActivity { } }); + setImportPath(); } @Override protected void onResume() { super.onResume(); StorageUtils.checkStorageAvailability(this); - setImportPath(); } /** @@ -167,5 +185,18 @@ public class OpmlImportFromPathActivity extends OpmlImportBaseActivity { dialog.create().show(); } + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + Log.d(TAG, "activity result: " + requestCode + " " + resultCode); + if (requestCode == DirectoryChooserActivity.RESULT_CODE_DIR_SELECTED) { + if (resultCode == DirectoryChooserActivity.RESULT_CODE_DIR_SELECTED) { + String dir = data + .getStringExtra(DirectoryChooserActivity.RESULT_SELECTED_DIR); + Log.d(TAG, dir); + txtvPath.setText(dir); + importPath = dir.toString(); + } + } + } } diff --git a/app/src/main/java/de/danoeh/antennapod/asynctask/OpmlExportWorker.java b/app/src/main/java/de/danoeh/antennapod/asynctask/OpmlExportWorker.java index 6bba956a6..68e144b40 100644 --- a/app/src/main/java/de/danoeh/antennapod/asynctask/OpmlExportWorker.java +++ b/app/src/main/java/de/danoeh/antennapod/asynctask/OpmlExportWorker.java @@ -24,10 +24,10 @@ import de.danoeh.antennapod.core.util.LangUtils; */ public class OpmlExportWorker extends AsyncTask<Void, Void, Void> { private static final String TAG = "OpmlExportWorker"; - private static final String DEFAULT_OUTPUT_NAME = "antennapod-feeds.opml"; + public static final String DEFAULT_OUTPUT_NAME = "antennapod-feeds.opml"; public static final String EXPORT_DIR = "export/"; - private Context context; + private final Context context; private File output; private ProgressDialog progDialog; diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/DownloadLogFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/DownloadLogFragment.java index c40fce351..0f6f7d53c 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/DownloadLogFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/DownloadLogFragment.java @@ -1,25 +1,35 @@ package de.danoeh.antennapod.fragment; import android.content.Context; +import android.content.res.TypedArray; import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.ListFragment; +import android.support.v4.view.MenuItemCompat; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.widget.ListView; +import java.util.List; + import de.danoeh.antennapod.R; import de.danoeh.antennapod.adapter.DownloadLogAdapter; import de.danoeh.antennapod.core.feed.EventDistributor; import de.danoeh.antennapod.core.service.download.DownloadStatus; import de.danoeh.antennapod.core.storage.DBReader; - -import java.util.List; +import de.danoeh.antennapod.core.storage.DBWriter; +import de.danoeh.antennapod.menuhandler.MenuItemUtils; +import de.danoeh.antennapod.menuhandler.NavDrawerActivity; /** * Shows the download log */ public class DownloadLogFragment extends ListFragment { + private static final String TAG = "DownloadLogFragment"; + private List<DownloadStatus> downloadLog; private DownloadLogAdapter adapter; @@ -29,6 +39,7 @@ public class DownloadLogFragment extends ListFragment { @Override public void onStart() { super.onStart(); + setHasOptionsMenu(true); EventDistributor.getInstance().register(contentUpdate); startItemLoader(); } @@ -63,7 +74,7 @@ public class DownloadLogFragment extends ListFragment { } setListShown(true); adapter.notifyDataSetChanged(); - + getActivity().supportInvalidateOptionsMenu(); } private DownloadLogAdapter.ItemAccess itemAccess = new DownloadLogAdapter.ItemAccess() { @@ -105,6 +116,41 @@ public class DownloadLogFragment extends ListFragment { } } + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + super.onCreateOptionsMenu(menu, inflater); + if (itemsLoaded && !MenuItemUtils.isActivityDrawerOpen((NavDrawerActivity) getActivity())) { + MenuItem clearHistory = menu.add(Menu.NONE, R.id.clear_history_item, Menu.CATEGORY_CONTAINER, R.string.clear_history_label); + MenuItemCompat.setShowAsAction(clearHistory, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); + TypedArray drawables = getActivity().obtainStyledAttributes(new int[]{R.attr.content_discard}); + clearHistory.setIcon(drawables.getDrawable(0)); + drawables.recycle(); + } + } + + @Override + public void onPrepareOptionsMenu(Menu menu) { + super.onPrepareOptionsMenu(menu); + if (itemsLoaded && !MenuItemUtils.isActivityDrawerOpen((NavDrawerActivity) getActivity())) { + menu.findItem(R.id.clear_history_item).setVisible(downloadLog != null && !downloadLog.isEmpty()); + } + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (!super.onOptionsItemSelected(item)) { + switch (item.getItemId()) { + case R.id.clear_history_item: + DBWriter.clearDownloadLog(getActivity()); + return true; + default: + return false; + } + } else { + return true; + } + } + private class ItemLoader extends AsyncTask<Void, Void, List<DownloadStatus>> { @Override diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java index ca8543b4c..bc00562aa 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java @@ -2,8 +2,8 @@ package de.danoeh.antennapod.fragment; import android.app.Activity; import android.content.Context; +import android.content.SharedPreferences; import android.os.AsyncTask; -import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.support.v4.app.Fragment; @@ -65,6 +65,10 @@ public class QueueFragment extends Fragment { private boolean viewsCreated = false; private boolean isUpdatingFeeds = false; + private static final String PREFS = "QueueFragment"; + private static final String PREF_KEY_LIST_TOP = "list_top"; + private static final String PREF_KEY_LIST_SELECTION = "list_selection"; + private AtomicReference<Activity> activity = new AtomicReference<Activity>(); private DownloadObserver downloadObserver = null; @@ -103,6 +107,18 @@ public class QueueFragment extends Fragment { } @Override + public void onPause() { + super.onPause(); + SharedPreferences prefs = getActivity().getSharedPreferences(PREFS, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = prefs.edit(); + View v = listView.getChildAt(0); + int top = (v == null) ? 0 : (v.getTop() - listView.getPaddingTop()); + editor.putInt(PREF_KEY_LIST_SELECTION, listView.getFirstVisiblePosition()); + editor.putInt(PREF_KEY_LIST_TOP, top); + editor.commit(); + } + + @Override public void onStop() { super.onStop(); EventDistributor.getInstance().unregister(contentUpdate); @@ -313,6 +329,11 @@ public class QueueFragment extends Fragment { } listAdapter.notifyDataSetChanged(); + SharedPreferences prefs = getActivity().getSharedPreferences(PREFS, Context.MODE_PRIVATE); + int listSelection = prefs.getInt(PREF_KEY_LIST_SELECTION, 0); + int top = prefs.getInt(PREF_KEY_LIST_TOP, 0); + listView.setSelectionFromTop(listSelection, top); + // we need to refresh the options menu because it sometimes // needs data that may have just been loaded. getActivity().supportInvalidateOptionsMenu(); diff --git a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java index ffac05321..b608a0919 100644 --- a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java +++ b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java @@ -61,6 +61,8 @@ public class PreferenceController { public static final String PREF_EXPANDED_NOTIFICATION = "prefExpandNotify"; private static final String PREF_PERSISTENT_NOTIFICATION = "prefPersistNotify"; + private static final int REQUEST_CHOOSE_DATA_DIR = 1; + private static final int REQUEST_CHOOSE_OMPL_EXPORT_DIR = 2; private final PreferenceUI ui; @@ -150,9 +152,12 @@ public class PreferenceController { @Override public boolean onPreferenceClick(Preference preference) { - new OpmlExportWorker(activity) - .executeAsync(); - + Intent intent = new Intent(activity, + DirectoryChooserActivity.class); + intent.putExtra(DirectoryChooserActivity.NON_EMPTY_DIRECTORY_WARNING, false); + activity.startActivityForResult(intent, + REQUEST_CHOOSE_OMPL_EXPORT_DIR + ); return true; } } @@ -163,10 +168,11 @@ public class PreferenceController { @Override public boolean onPreferenceClick(Preference preference) { - activity.startActivityForResult( - new Intent(activity, - DirectoryChooserActivity.class), - DirectoryChooserActivity.RESULT_CODE_DIR_SELECTED + Intent intent = new Intent(activity, + DirectoryChooserActivity.class); + intent.putExtra(DirectoryChooserActivity.NON_EMPTY_DIRECTORY_WARNING, true); + activity.startActivityForResult(intent, + REQUEST_CHOOSE_DATA_DIR ); return true; } @@ -311,9 +317,18 @@ public class PreferenceController { if (resultCode == DirectoryChooserActivity.RESULT_CODE_DIR_SELECTED) { String dir = data .getStringExtra(DirectoryChooserActivity.RESULT_SELECTED_DIR); - if (BuildConfig.DEBUG) - Log.d(TAG, "Setting data folder"); - UserPreferences.setDataFolder(dir); + switch(requestCode) { + case REQUEST_CHOOSE_DATA_DIR: + if (BuildConfig.DEBUG) + Log.d(TAG, "Setting data folder"); + UserPreferences.setDataFolder(dir); + break; + case REQUEST_CHOOSE_OMPL_EXPORT_DIR: + File path = new File(dir, OpmlExportWorker.DEFAULT_OUTPUT_NAME); + new OpmlExportWorker(ui.getActivity(), path) + .executeAsync(); + break; + } } } |