Skip to content
This repository
Browse code

Added setting to exclude specified tags.

  • Loading branch information...
commit ddfba55648fd99cce07195b81b73308975905f7f 1 parent 11190d6
Henning Weiss hdweiss authored
2  res/values/strings.xml
@@ -153,6 +153,8 @@
153 153 <string name="preference_ubuntuone_path_summary">UbuntuOne path to index.org file</string>
154 154 <string name="preference_clear_db_dialog_title">Clear DB?</string>
155 155 <string name="preference_clear_db_dialog_message">Are you sure want to clear DB?</string>
  156 + <string name="preference_exclude_tags">Exclude tags inheritance</string>
  157 + <string name="preference_exclude_tags_summary">Tags separated by \":\" to exclude from inheritance.</string>
156 158 <string name="preference_combine_block_agenda_summary">Combines block agendas into one node, with separators. Needs resync of agenda file to take effect</string>
157 159 <string name="preference_combine_block_agenda_title">Combine block agendas</string>
158 160 <string name="preference_calendar">Calendar</string>
8 res/xml/preferences.xml
@@ -2,8 +2,7 @@
2 2 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
3 3
4 4 <PreferenceCategory android:title="@string/preference_synchronization" >
5   - <Preference
6   - android:title="@string/rerun_setup_wizard" >
  5 + <Preference android:title="@string/rerun_setup_wizard" >
7 6 <intent android:action="com.matburt.mobileorg.Settings.SETUP_WIZARD" />
8 7 </Preference>
9 8
@@ -57,6 +56,11 @@
57 56 android:entryValues="@array/viewRecursionLevelsVals"
58 57 android:key="viewRecursionMax"
59 58 android:title="@string/preference_recursion_level_title" />
  59 +
  60 + <EditTextPreference
  61 + android:key="excludeTagsInheritance"
  62 + android:summary="@string/preference_exclude_tags_summary"
  63 + android:title="@string/preference_exclude_tags" />
60 64 </PreferenceCategory>
61 65 <PreferenceCategory android:title="@string/preference_storage" >
62 66 <CheckBoxPreference
24 src/com/matburt/mobileorg/OrgData/OrgFileParser.java
@@ -4,6 +4,7 @@
4 4 import java.io.IOException;
5 5 import java.util.ArrayList;
6 6 import java.util.HashMap;
  7 +import java.util.HashSet;
7 8 import java.util.Stack;
8 9 import java.util.regex.Matcher;
9 10 import java.util.regex.Pattern;
@@ -28,6 +29,7 @@
28 29 private StringBuilder payload;
29 30 private OrgFile orgFile;
30 31 private OrgNodeParser orgNodeParser;
  32 + private HashSet<String> excludedTags;
31 33
32 34 public OrgFileParser(OrgDatabase db, ContentResolver resolver) {
33 35 this.db = db;
@@ -50,6 +52,8 @@ private void init(OrgFile orgFile) {
50 52
51 53 public void parse(OrgFile orgFile, BufferedReader breader, Context context) {
52 54 this.combineAgenda = OrgUtils.getCombineBlockAgendas(context);
  55 + this.excludedTags = OrgUtils.getExcludedTags(context);
  56 +
53 57 parse(orgFile, breader);
54 58 }
55 59
@@ -126,7 +130,25 @@ public ParseStack() {
126 130
127 131 public void add(int level, long nodeId, String tags) {
128 132 parseStack.push(new Pair<Integer, Long>(level, nodeId));
129   - tagStack.push(tags);
  133 + tagStack.push(stripTags(tags));
  134 + }
  135 +
  136 + private String stripTags(String tags) {
  137 + if (excludedTags == null || TextUtils.isEmpty(tags))
  138 + return tags;
  139 +
  140 + StringBuilder result = new StringBuilder();
  141 + for (String tag: tags.split(":")) {
  142 + if (excludedTags.contains(tag) == false) {
  143 + result.append(tag);
  144 + result.append(":");
  145 + }
  146 + }
  147 +
  148 + if(!TextUtils.isEmpty(result))
  149 + result.deleteCharAt(result.lastIndexOf(":"));
  150 +
  151 + return result.toString();
130 152 }
131 153
132 154 public void pop() {
17 src/com/matburt/mobileorg/util/OrgUtils.java
@@ -13,6 +13,7 @@
13 13 import java.util.ArrayList;
14 14 import java.util.Comparator;
15 15 import java.util.Date;
  16 +import java.util.HashSet;
16 17
17 18 import android.app.Activity;
18 19 import android.content.ContentResolver;
@@ -64,6 +65,22 @@ public static boolean isSyncConfigured(Context context) {
64 65 return true;
65 66 }
66 67
  68 + public static HashSet<String> getExcludedTags(Context context) {
  69 + String tags = PreferenceManager.getDefaultSharedPreferences(context).getString(
  70 + "excludeTagsInheritance", null);
  71 +
  72 + if (tags == null)
  73 + return null;
  74 +
  75 + HashSet<String> tagsSet = new HashSet<String>();
  76 + for (String tag: tags.split(":")) {
  77 + if(TextUtils.isEmpty(tag) == false)
  78 + tagsSet.add(tag);
  79 + }
  80 +
  81 + return tagsSet;
  82 + }
  83 +
67 84 public static boolean getCombineBlockAgendas(Context context) {
68 85 try {
69 86 return PreferenceManager.getDefaultSharedPreferences(context)

0 comments on commit ddfba55

Please sign in to comment.
Something went wrong with that request. Please try again.