diff options
author | Camil Staps | 2015-05-21 15:59:09 +0200 |
---|---|---|
committer | Camil Staps | 2015-05-21 15:59:09 +0200 |
commit | 5b33d7bc3be0384d2cd62882d1fe42832a270b33 (patch) | |
tree | 70dca40709efed263d51f292c5b0faac11764375 /app/src/main/java/org | |
parent | Fix saving filters; remove keywords (diff) |
Rotation fixes & more
Diffstat (limited to 'app/src/main/java/org')
4 files changed, 114 insertions, 11 deletions
diff --git a/app/src/main/java/org/rssin/android/FilterSettingsActivity.java b/app/src/main/java/org/rssin/android/FilterSettingsActivity.java index f498e8e..8d59a3b 100644 --- a/app/src/main/java/org/rssin/android/FilterSettingsActivity.java +++ b/app/src/main/java/org/rssin/android/FilterSettingsActivity.java @@ -7,6 +7,7 @@ import android.app.DialogFragment; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; +import android.content.pm.ActivityInfo; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.util.Log; @@ -15,6 +16,7 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.view.WindowManager; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.EditText; @@ -125,8 +127,12 @@ public class FilterSettingsActivity extends ActionBarActivity { /** * Open dialog to edit title + * For the moment, we temporarily disable rotating because we can't get it working otherwise. + * @todo make rotating possible */ public void openTitleDialog() { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR); + AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Title"); @@ -134,8 +140,10 @@ public class FilterSettingsActivity extends ActionBarActivity { final EditText input = new EditText(this); input.setText(filter.getTitle()); + input.setFocusable(true); + input.requestFocus(); - alert + AlertDialog dialog = alert .setView(input) .setPositiveButton(getResources().getString(R.string.button_apply), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { @@ -147,10 +155,25 @@ public class FilterSettingsActivity extends ActionBarActivity { } catch (IOException e) { Toast.makeText(getBaseContext(), getResources().getString(R.string.error_save_filters), Toast.LENGTH_SHORT).show(); } + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); + } + }) + .setNegativeButton(getResources().getString(R.string.button_cancel), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); } }) - .setNegativeButton(getResources().getString(R.string.button_cancel), null) - .show(); + .setOnCancelListener(new DialogInterface.OnCancelListener() { + @Override + public void onCancel(DialogInterface dialog) { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); + } + }) + .create(); + + dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); + dialog.show(); } /** diff --git a/app/src/main/java/org/rssin/android/FiltersActivity.java b/app/src/main/java/org/rssin/android/FiltersActivity.java index fd569be..b7de210 100644 --- a/app/src/main/java/org/rssin/android/FiltersActivity.java +++ b/app/src/main/java/org/rssin/android/FiltersActivity.java @@ -1,16 +1,23 @@ package org.rssin.android; import android.app.Activity; +import android.app.AlertDialog; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; +import android.content.pm.ActivityInfo; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.view.WindowManager; import android.widget.AdapterView; import android.widget.ArrayAdapter; +import android.widget.EditText; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; @@ -69,6 +76,24 @@ public class FiltersActivity extends ActionBarActivity { setupListeners(); } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.menu_filters, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + + if (id == R.id.filters_action_add) { + openAddDialog(); + return true; + } + + return super.onOptionsItemSelected(item); + } + /** * Setup listeners for the list items */ @@ -84,9 +109,7 @@ public class FiltersActivity extends ActionBarActivity { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Filter item = (Filter) parent.getItemAtPosition(position); - Intent intent = new Intent(getApplicationContext(), FilterSettingsActivity.class); - intent.putExtra("filter", item.hashCode()); - startActivity(intent); + openFilterSettings(item); return true; } }; @@ -96,6 +119,63 @@ public class FiltersActivity extends ActionBarActivity { } /** + * Open dialog to create new filter + * For the moment, we temporarily disable rotating because we can't get it working otherwise. + * @todo make rotating possible + */ + public void openAddDialog() { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR); + + AlertDialog.Builder alert = new AlertDialog.Builder(this); + + alert.setTitle("Add filter"); + alert.setMessage("Title:"); + + final EditText input = new EditText(this); + input.setFocusable(true); + input.requestFocus(); + + AlertDialog dialog = alert + .setView(input) + .setPositiveButton(getResources().getString(R.string.button_apply), new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int whichButton) { + String value = input.getText().toString(); + try { + Filter f = new Filter(value); + filtersList.getFilters().add(f); + filtersList.save(); + openFilterSettings(f); + } catch (IOException e) { + Toast.makeText(getBaseContext(), getResources().getString(R.string.error_save_filters), Toast.LENGTH_SHORT).show(); + } + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); + } + }) + .setNegativeButton(getResources().getString(R.string.button_cancel), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); + } + }) + .setOnCancelListener(new DialogInterface.OnCancelListener() { + @Override + public void onCancel(DialogInterface dialog) { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); + } + }) + .create(); + + dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); + dialog.show(); + } + + public void openFilterSettings(Filter f) { + Intent intent = new Intent(getApplicationContext(), FilterSettingsActivity.class); + intent.putExtra("filter", f.hashCode()); + startActivity(intent); + } + + /** * Custom ArrayAdapter to display filters with our own menu item */ private static class FilterAdapter extends ArrayAdapter<Filter> { diff --git a/app/src/main/java/org/rssin/rssin/Filter.java b/app/src/main/java/org/rssin/rssin/Filter.java index c7915aa..271b67d 100755 --- a/app/src/main/java/org/rssin/rssin/Filter.java +++ b/app/src/main/java/org/rssin/rssin/Filter.java @@ -30,7 +30,7 @@ public class Filter implements Serializable { } public Filter(String title) { - this.title = title; + setTitle(title); feeds = new ArrayList<>(); keywords = new ArrayList<>(); } @@ -38,13 +38,13 @@ public class Filter implements Serializable { public Filter(String title, List<Keyword> keywords) { this.feeds = new ArrayList<>(); this.keywords = keywords; - this.title = title; + setTitle(title); } public Filter(String title, List<Keyword> keywords, List<Feed> feeds) { this.feeds = feeds; this.keywords = keywords; - this.title = title; + setTitle(title); } public List<Feed> getFeeds() { @@ -73,7 +73,7 @@ public class Filter implements Serializable { } public void setTitle(String title) { - this.title = title; + this.title = title.trim(); } public FeedSorter getSorter() { diff --git a/app/src/main/java/org/rssin/rssin/Keyword.java b/app/src/main/java/org/rssin/rssin/Keyword.java index 2ea1012..9b5adfb 100644 --- a/app/src/main/java/org/rssin/rssin/Keyword.java +++ b/app/src/main/java/org/rssin/rssin/Keyword.java @@ -16,7 +16,7 @@ public class Keyword implements Serializable { private final String keyword; public Keyword(String keyword) { - this.keyword = keyword; + this.keyword = keyword.trim(); } public String getKeyword() { |