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