]> git.ktnx.net Git - mobile-ledger.git/blob - app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java
new: go to a date from transaction list
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / model / MobileLedgerProfile.java
1 /*
2  * Copyright © 2020 Damyan Ivanov.
3  * This file is part of MoLe.
4  * MoLe is free software: you can distribute it and/or modify it
5  * under the term of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your opinion), any later version.
8  *
9  * MoLe is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License terms for details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
16  */
17
18 package net.ktnx.mobileledger.model;
19
20 import android.content.res.Resources;
21 import android.database.Cursor;
22 import android.database.sqlite.SQLiteDatabase;
23 import android.util.SparseArray;
24
25 import androidx.annotation.NonNull;
26 import androidx.annotation.Nullable;
27
28 import net.ktnx.mobileledger.App;
29 import net.ktnx.mobileledger.R;
30 import net.ktnx.mobileledger.async.DbOpQueue;
31 import net.ktnx.mobileledger.async.SendTransactionTask;
32 import net.ktnx.mobileledger.utils.MLDB;
33 import net.ktnx.mobileledger.utils.Misc;
34
35 import java.util.ArrayList;
36 import java.util.Calendar;
37 import java.util.Date;
38 import java.util.List;
39 import java.util.Locale;
40 import java.util.UUID;
41
42 import static net.ktnx.mobileledger.utils.Logger.debug;
43
44 public final class MobileLedgerProfile {
45     // N.B. when adding new fields, update the copy-constructor below
46     private String uuid;
47     private String name;
48     private boolean permitPosting;
49     private boolean showCommentsByDefault;
50     private boolean showCommodityByDefault;
51     private String defaultCommodity;
52     private String preferredAccountsFilter;
53     private String url;
54     private boolean authEnabled;
55     private String authUserName;
56     private String authPassword;
57     private int themeHue;
58     private int orderNo = -1;
59     // N.B. when adding new fields, update the copy-constructor below
60     private FutureDates futureDates = FutureDates.None;
61     private SendTransactionTask.API apiVersion = SendTransactionTask.API.auto;
62     private Calendar firstTransactionDate;
63     private Calendar lastTransactionDate;
64     public MobileLedgerProfile() {
65         this.uuid = String.valueOf(UUID.randomUUID());
66     }
67     public MobileLedgerProfile(String uuid) {
68         this.uuid = uuid;
69     }
70     public MobileLedgerProfile(MobileLedgerProfile origin) {
71         uuid = origin.uuid;
72         name = origin.name;
73         permitPosting = origin.permitPosting;
74         showCommentsByDefault = origin.showCommentsByDefault;
75         showCommodityByDefault = origin.showCommodityByDefault;
76         preferredAccountsFilter = origin.preferredAccountsFilter;
77         url = origin.url;
78         authEnabled = origin.authEnabled;
79         authUserName = origin.authUserName;
80         authPassword = origin.authPassword;
81         themeHue = origin.themeHue;
82         orderNo = origin.orderNo;
83         futureDates = origin.futureDates;
84         apiVersion = origin.apiVersion;
85         defaultCommodity = origin.defaultCommodity;
86     }
87     // loads all profiles into Data.profiles
88     // returns the profile with the given UUID
89     public static MobileLedgerProfile loadAllFromDB(String currentProfileUUID) {
90         MobileLedgerProfile result = null;
91         ArrayList<MobileLedgerProfile> list = new ArrayList<>();
92         SQLiteDatabase db = App.getDatabase();
93         try (Cursor cursor = db.rawQuery("SELECT uuid, name, url, use_authentication, auth_user, " +
94                                          "auth_password, permit_posting, theme, order_no, " +
95                                          "preferred_accounts_filter, future_dates, api_version, " +
96                                          "show_commodity_by_default, default_commodity, " +
97                                          "show_comments_by_default FROM " +
98                                          "profiles order by order_no", null))
99         {
100             while (cursor.moveToNext()) {
101                 MobileLedgerProfile item = new MobileLedgerProfile(cursor.getString(0));
102                 item.setName(cursor.getString(1));
103                 item.setUrl(cursor.getString(2));
104                 item.setAuthEnabled(cursor.getInt(3) == 1);
105                 item.setAuthUserName(cursor.getString(4));
106                 item.setAuthPassword(cursor.getString(5));
107                 item.setPostingPermitted(cursor.getInt(6) == 1);
108                 item.setThemeId(cursor.getInt(7));
109                 item.orderNo = cursor.getInt(8);
110                 item.setPreferredAccountsFilter(cursor.getString(9));
111                 item.setFutureDates(cursor.getInt(10));
112                 item.setApiVersion(cursor.getInt(11));
113                 item.setShowCommodityByDefault(cursor.getInt(12) == 1);
114                 item.setDefaultCommodity(cursor.getString(13));
115                 item.setShowCommentsByDefault(cursor.getInt(14) == 1);
116                 list.add(item);
117                 if (item.getUuid()
118                         .equals(currentProfileUUID))
119                     result = item;
120             }
121         }
122         Data.profiles.setValue(list);
123         return result;
124     }
125     public static void storeProfilesOrder() {
126         SQLiteDatabase db = App.getDatabase();
127         db.beginTransactionNonExclusive();
128         try {
129             int orderNo = 0;
130             for (MobileLedgerProfile p : Data.profiles.getValue()) {
131                 db.execSQL("update profiles set order_no=? where uuid=?",
132                         new Object[]{orderNo, p.getUuid()});
133                 p.orderNo = orderNo;
134                 orderNo++;
135             }
136             db.setTransactionSuccessful();
137         }
138         finally {
139             db.endTransaction();
140         }
141     }
142     public boolean getShowCommentsByDefault() {
143         return showCommentsByDefault;
144     }
145     public void setShowCommentsByDefault(boolean newValue) {
146         this.showCommentsByDefault = newValue;
147     }
148     public boolean getShowCommodityByDefault() {
149         return showCommodityByDefault;
150     }
151     public void setShowCommodityByDefault(boolean showCommodityByDefault) {
152         this.showCommodityByDefault = showCommodityByDefault;
153     }
154     public String getDefaultCommodity() {
155         return defaultCommodity;
156     }
157     public void setDefaultCommodity(String defaultCommodity) {
158         this.defaultCommodity = defaultCommodity;
159     }
160     public void setDefaultCommodity(CharSequence defaultCommodity) {
161         if (defaultCommodity == null)
162             this.defaultCommodity = null;
163         else
164             this.defaultCommodity = String.valueOf(defaultCommodity);
165     }
166     public SendTransactionTask.API getApiVersion() {
167         return apiVersion;
168     }
169     public void setApiVersion(SendTransactionTask.API apiVersion) {
170         this.apiVersion = apiVersion;
171     }
172     public void setApiVersion(int apiVersion) {
173         this.apiVersion = SendTransactionTask.API.valueOf(apiVersion);
174     }
175     public FutureDates getFutureDates() {
176         return futureDates;
177     }
178     public void setFutureDates(int anInt) {
179         futureDates = FutureDates.valueOf(anInt);
180     }
181     public void setFutureDates(FutureDates futureDates) {
182         this.futureDates = futureDates;
183     }
184     public String getPreferredAccountsFilter() {
185         return preferredAccountsFilter;
186     }
187     public void setPreferredAccountsFilter(String preferredAccountsFilter) {
188         this.preferredAccountsFilter = preferredAccountsFilter;
189     }
190     public void setPreferredAccountsFilter(CharSequence preferredAccountsFilter) {
191         setPreferredAccountsFilter(String.valueOf(preferredAccountsFilter));
192     }
193     public boolean isPostingPermitted() {
194         return permitPosting;
195     }
196     public void setPostingPermitted(boolean permitPosting) {
197         this.permitPosting = permitPosting;
198     }
199     public String getUuid() {
200         return uuid;
201     }
202     public String getName() {
203         return name;
204     }
205     public void setName(CharSequence text) {
206         setName(String.valueOf(text));
207     }
208     public void setName(String name) {
209         this.name = name;
210     }
211     public String getUrl() {
212         return url;
213     }
214     public void setUrl(CharSequence text) {
215         setUrl(String.valueOf(text));
216     }
217     public void setUrl(String url) {
218         this.url = url;
219     }
220     public boolean isAuthEnabled() {
221         return authEnabled;
222     }
223     public void setAuthEnabled(boolean authEnabled) {
224         this.authEnabled = authEnabled;
225     }
226     public String getAuthUserName() {
227         return authUserName;
228     }
229     public void setAuthUserName(CharSequence text) {
230         setAuthUserName(String.valueOf(text));
231     }
232     public void setAuthUserName(String authUserName) {
233         this.authUserName = authUserName;
234     }
235     public String getAuthPassword() {
236         return authPassword;
237     }
238     public void setAuthPassword(CharSequence text) {
239         setAuthPassword(String.valueOf(text));
240     }
241     public void setAuthPassword(String authPassword) {
242         this.authPassword = authPassword;
243     }
244     public void storeInDB() {
245         SQLiteDatabase db = App.getDatabase();
246         db.beginTransactionNonExclusive();
247         try {
248 //            debug("profiles", String.format("Storing profile in DB: uuid=%s, name=%s, " +
249 //                                            "url=%s, permit_posting=%s, authEnabled=%s, " +
250 //                                            "themeHue=%d", uuid, name, url,
251 //                    permitPosting ? "TRUE" : "FALSE", authEnabled ? "TRUE" : "FALSE", themeHue));
252             db.execSQL("REPLACE INTO profiles(uuid, name, permit_posting, url, " +
253                        "use_authentication, auth_user, auth_password, theme, order_no, " +
254                        "preferred_accounts_filter, future_dates, api_version, " +
255                        "show_commodity_by_default, default_commodity, show_comments_by_default) " +
256                        "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
257                     new Object[]{uuid, name, permitPosting, url, authEnabled,
258                                  authEnabled ? authUserName : null,
259                                  authEnabled ? authPassword : null, themeHue, orderNo,
260                                  preferredAccountsFilter, futureDates.toInt(), apiVersion.toInt(),
261                                  showCommodityByDefault, defaultCommodity, showCommentsByDefault
262                     });
263             db.setTransactionSuccessful();
264         }
265         finally {
266             db.endTransaction();
267         }
268     }
269     public void storeAccount(SQLiteDatabase db, LedgerAccount acc) {
270         // replace into is a bad idea because it would reset hidden to its default value
271         // we like the default, but for new accounts only
272         db.execSQL("update accounts set level = ?, keep = 1, hidden=?, expanded=? " +
273                    "where profile=? and name = ?",
274                 new Object[]{acc.getLevel(), acc.isHiddenByStar(), acc.isExpanded(), uuid,
275                              acc.getName()
276                 });
277         db.execSQL("insert into accounts(profile, name, name_upper, parent_name, level, hidden, " +
278                    "expanded, keep) " + "select ?,?,?,?,?,?,?,1 where (select changes() = 0)",
279                 new Object[]{uuid, acc.getName(), acc.getName().toUpperCase(), acc.getParentName(),
280                              acc.getLevel(), acc.isHiddenByStar(), acc.isExpanded()
281                 });
282 //        debug("accounts", String.format("Stored account '%s' in DB [%s]", acc.getName(), uuid));
283     }
284     public void storeAccountValue(SQLiteDatabase db, String name, String currency, Float amount) {
285         db.execSQL("replace into account_values(profile, account, " +
286                    "currency, value, keep) values(?, ?, ?, ?, 1);",
287                 new Object[]{uuid, name, Misc.emptyIsNull(currency), amount});
288     }
289     public void storeTransaction(SQLiteDatabase db, LedgerTransaction tr) {
290         tr.fillDataHash();
291         db.execSQL("DELETE from transactions WHERE profile=? and id=?",
292                 new Object[]{uuid, tr.getId()});
293         db.execSQL("DELETE from transaction_accounts WHERE profile = ? and transaction_id=?",
294                 new Object[]{uuid, tr.getId()});
295
296         db.execSQL(
297                 "INSERT INTO transactions(profile, id, year, month, day, description, "+
298                 "comment, data_hash, keep) " +
299                 "values(?,?,?,?,?,?,?,?,1)",
300                 new Object[]{uuid, tr.getId(), tr.getDate().year, tr.getDate().month,
301                              tr.getDate().day, tr.getDescription(),
302                              tr.getComment(), tr.getDataHash()
303                 });
304
305         for (LedgerTransactionAccount item : tr.getAccounts()) {
306             db.execSQL("INSERT INTO transaction_accounts(profile, transaction_id, " +
307                        "account_name, amount, currency, comment) values(?, ?, ?, ?, ?, ?)",
308                     new Object[]{uuid, tr.getId(), item.getAccountName(), item.getAmount(),
309                                  Misc.nullIsEmpty(item.getCurrency()), item.getComment()
310                     });
311         }
312 //        debug("profile", String.format("Transaction %d stored", tr.getId()));
313     }
314     public String getOption(String name, String default_value) {
315         SQLiteDatabase db = App.getDatabase();
316         try (Cursor cursor = db.rawQuery("select value from options where profile = ? and name=?",
317                 new String[]{uuid, name}))
318         {
319             if (cursor.moveToFirst()) {
320                 String result = cursor.getString(0);
321
322                 if (result == null) {
323                     debug("profile", "returning default value for " + name);
324                     result = default_value;
325                 }
326                 else
327                     debug("profile", String.format("option %s=%s", name, result));
328
329                 return result;
330             }
331             else
332                 return default_value;
333         }
334         catch (Exception e) {
335             debug("db", "returning default value for " + name, e);
336             return default_value;
337         }
338     }
339     public long getLongOption(String name, long default_value) {
340         long longResult;
341         String result = getOption(name, "");
342         if ((result == null) || result.isEmpty()) {
343             debug("profile", String.format("Returning default value for option %s", name));
344             longResult = default_value;
345         }
346         else {
347             try {
348                 longResult = Long.parseLong(result);
349                 debug("profile", String.format("option %s=%s", name, result));
350             }
351             catch (Exception e) {
352                 debug("profile", String.format("Returning default value for option %s", name), e);
353                 longResult = default_value;
354             }
355         }
356
357         return longResult;
358     }
359     public void setOption(String name, String value) {
360         debug("profile", String.format("setting option %s=%s", name, value));
361         DbOpQueue.add("insert or replace into options(profile, name, value) values(?, ?, ?);",
362                 new String[]{uuid, name, value});
363     }
364     public void setLongOption(String name, long value) {
365         setOption(name, String.valueOf(value));
366     }
367     public void removeFromDB() {
368         SQLiteDatabase db = App.getDatabase();
369         debug("db", String.format("removing profile %s from DB", uuid));
370         db.beginTransactionNonExclusive();
371         try {
372             Object[] uuid_param = new Object[]{uuid};
373             db.execSQL("delete from profiles where uuid=?", uuid_param);
374             db.execSQL("delete from accounts where profile=?", uuid_param);
375             db.execSQL("delete from account_values where profile=?", uuid_param);
376             db.execSQL("delete from transactions where profile=?", uuid_param);
377             db.execSQL("delete from transaction_accounts where profile=?", uuid_param);
378             db.execSQL("delete from options where profile=?", uuid_param);
379             db.setTransactionSuccessful();
380         }
381         finally {
382             db.endTransaction();
383         }
384     }
385     @NonNull
386     public LedgerAccount loadAccount(String name) {
387         SQLiteDatabase db = App.getDatabase();
388         return loadAccount(db, name);
389     }
390     @Nullable
391     public LedgerAccount tryLoadAccount(String acct_name) {
392         SQLiteDatabase db = App.getDatabase();
393         return tryLoadAccount(db, acct_name);
394     }
395     @NonNull
396     public LedgerAccount loadAccount(SQLiteDatabase db, String accName) {
397         LedgerAccount acc = tryLoadAccount(db, accName);
398
399         if (acc == null)
400             throw new RuntimeException("Unable to load account with name " + accName);
401
402         return acc;
403     }
404     @Nullable
405     public LedgerAccount tryLoadAccount(SQLiteDatabase db, String accName) {
406         try (Cursor cursor = db.rawQuery(
407                 "SELECT a.hidden, a.expanded, (select 1 from accounts a2 " +
408                 "where a2.profile = a.profile and a2.name like a.name||':%' limit 1) " +
409                 "FROM accounts a WHERE a.profile = ? and a.name=?", new String[]{uuid, accName}))
410         {
411             if (cursor.moveToFirst()) {
412                 LedgerAccount acc = new LedgerAccount(accName);
413                 acc.setHiddenByStar(cursor.getInt(0) == 1);
414                 acc.setExpanded(cursor.getInt(1) == 1);
415                 acc.setHasSubAccounts(cursor.getInt(2) == 1);
416
417                 try (Cursor c2 = db.rawQuery(
418                         "SELECT value, currency FROM account_values WHERE profile = ? " +
419                         "AND account = ?", new String[]{uuid, accName}))
420                 {
421                     while (c2.moveToNext()) {
422                         acc.addAmount(c2.getFloat(0), c2.getString(1));
423                     }
424                 }
425
426                 return acc;
427             }
428             return null;
429         }
430     }
431     public LedgerTransaction loadTransaction(int transactionId) {
432         LedgerTransaction tr = new LedgerTransaction(transactionId, this.uuid);
433         tr.loadData(App.getDatabase());
434
435         return tr;
436     }
437     public int getThemeHue() {
438 //        debug("profile", String.format("Profile.getThemeHue() returning %d", themeHue));
439         return this.themeHue;
440     }
441     public void setThemeHue(Object o) {
442         setThemeId(Integer.parseInt(String.valueOf(o)));
443     }
444     public void setThemeId(int themeHue) {
445 //        debug("profile", String.format("Profile.setThemeHue(%d) called", themeHue));
446         this.themeHue = themeHue;
447     }
448     public void markTransactionsAsNotPresent(SQLiteDatabase db) {
449         db.execSQL("UPDATE transactions set keep=0 where profile=?", new String[]{uuid});
450
451     }
452     public void markAccountsAsNotPresent(SQLiteDatabase db) {
453         db.execSQL("update account_values set keep=0 where profile=?;", new String[]{uuid});
454         db.execSQL("update accounts set keep=0 where profile=?;", new String[]{uuid});
455
456     }
457     public void deleteNotPresentAccounts(SQLiteDatabase db) {
458         db.execSQL("delete from account_values where keep=0 and profile=?", new String[]{uuid});
459         db.execSQL("delete from accounts where keep=0 and profile=?", new String[]{uuid});
460     }
461     public void markTransactionAsPresent(SQLiteDatabase db, LedgerTransaction transaction) {
462         db.execSQL("UPDATE transactions SET keep = 1 WHERE profile = ? and id=?",
463                 new Object[]{uuid, transaction.getId()
464                 });
465     }
466     public void markTransactionsBeforeTransactionAsPresent(SQLiteDatabase db,
467                                                            LedgerTransaction transaction) {
468         db.execSQL("UPDATE transactions SET keep=1 WHERE profile = ? and id < ?",
469                 new Object[]{uuid, transaction.getId()
470                 });
471
472     }
473     public void deleteNotPresentTransactions(SQLiteDatabase db) {
474         db.execSQL("DELETE FROM transactions WHERE profile=? AND keep = 0", new String[]{uuid});
475     }
476     public void setLastUpdateStamp() {
477         debug("db", "Updating transaction value stamp");
478         Date now = new Date();
479         setLongOption(MLDB.OPT_LAST_SCRAPE, now.getTime());
480         Data.lastUpdateDate.postValue(now);
481     }
482     public List<LedgerAccount> loadChildAccountsOf(LedgerAccount acc) {
483         List<LedgerAccount> result = new ArrayList<>();
484         SQLiteDatabase db = App.getDatabase();
485         try (Cursor c = db.rawQuery(
486                 "SELECT a.name FROM accounts a WHERE a.profile = ? and a.name like ?||':%'",
487                 new String[]{uuid, acc.getName()}))
488         {
489             while (c.moveToNext()) {
490                 LedgerAccount a = loadAccount(db, c.getString(0));
491                 result.add(a);
492             }
493         }
494
495         return result;
496     }
497     public List<LedgerAccount> loadVisibleChildAccountsOf(LedgerAccount acc) {
498         List<LedgerAccount> result = new ArrayList<>();
499         ArrayList<LedgerAccount> visibleList = new ArrayList<>();
500         visibleList.add(acc);
501
502         SQLiteDatabase db = App.getDatabase();
503         try (Cursor c = db.rawQuery(
504                 "SELECT a.name FROM accounts a WHERE a.profile = ? and a.name like ?||':%'",
505                 new String[]{uuid, acc.getName()}))
506         {
507             while (c.moveToNext()) {
508                 LedgerAccount a = loadAccount(db, c.getString(0));
509                 if (a.isVisible(visibleList)) {
510                     result.add(a);
511                     visibleList.add(a);
512                 }
513             }
514         }
515
516         return result;
517     }
518     public void wipeAllData() {
519         SQLiteDatabase db = App.getDatabase();
520         db.beginTransaction();
521         try {
522             String[] pUuid = new String[]{uuid};
523             db.execSQL("delete from options where profile=?", pUuid);
524             db.execSQL("delete from accounts where profile=?", pUuid);
525             db.execSQL("delete from account_values where profile=?", pUuid);
526             db.execSQL("delete from transactions where profile=?", pUuid);
527             db.execSQL("delete from transaction_accounts where profile=?", pUuid);
528             db.setTransactionSuccessful();
529             debug("wipe", String.format(Locale.ENGLISH, "Profile %s wiped out", pUuid[0]));
530         }
531         finally {
532             db.endTransaction();
533         }
534     }
535     public List<Currency> getCurrencies() {
536         SQLiteDatabase db = App.getDatabase();
537
538         ArrayList<Currency> result = new ArrayList<>();
539
540         try (Cursor c = db.rawQuery("SELECT c.id, c.name, c.position, c.has_gap FROM currencies c",
541                 new String[]{}))
542         {
543             while (c.moveToNext()) {
544                 Currency currency = new Currency(c.getInt(0), c.getString(1),
545                         Currency.Position.valueOf(c.getInt(2)), c.getInt(3) == 1);
546                 result.add(currency);
547             }
548         }
549
550         return result;
551     }
552     Currency loadCurrencyByName(String name) {
553         SQLiteDatabase db = App.getDatabase();
554         Currency result = tryLoadCurrencyByName(db, name);
555         if (result == null)
556             throw new RuntimeException(String.format("Unable to load currency '%s'", name));
557         return result;
558     }
559     private Currency tryLoadCurrencyByName(SQLiteDatabase db, String name) {
560         try (Cursor cursor = db.rawQuery(
561                 "SELECT c.id, c.name, c.position, c.has_gap FROM currencies c WHERE c.name=?",
562                 new String[]{name}))
563         {
564             if (cursor.moveToFirst()) {
565                 return new Currency(cursor.getInt(0), cursor.getString(1),
566                         Currency.Position.valueOf(cursor.getInt(2)), cursor.getInt(3) == 1);
567             }
568             return null;
569         }
570     }
571     public Calendar getFirstTransactionDate() {
572         return firstTransactionDate;
573     }
574     public Calendar getLastTransactionDate() {
575         return lastTransactionDate;
576     }
577     public enum FutureDates {
578         None(0), OneWeek(7), TwoWeeks(14), OneMonth(30), TwoMonths(60), ThreeMonths(90),
579         SixMonths(180), OneYear(365), All(-1);
580         private static SparseArray<FutureDates> map = new SparseArray<>();
581
582         static {
583             for (FutureDates item : FutureDates.values()) {
584                 map.put(item.value, item);
585             }
586         }
587
588         private int value;
589         FutureDates(int value) {
590             this.value = value;
591         }
592         public static FutureDates valueOf(int i) {
593             return map.get(i, None);
594         }
595         public int toInt() {
596             return this.value;
597         }
598         public String getText(Resources resources) {
599             switch (value) {
600                 case 7:
601                     return resources.getString(R.string.future_dates_7);
602                 case 14:
603                     return resources.getString(R.string.future_dates_14);
604                 case 30:
605                     return resources.getString(R.string.future_dates_30);
606                 case 60:
607                     return resources.getString(R.string.future_dates_60);
608                 case 90:
609                     return resources.getString(R.string.future_dates_90);
610                 case 180:
611                     return resources.getString(R.string.future_dates_180);
612                 case 365:
613                     return resources.getString(R.string.future_dates_365);
614                 case -1:
615                     return resources.getString(R.string.future_dates_all);
616                 default:
617                     return resources.getString(R.string.future_dates_none);
618             }
619         }
620     }
621 }