FeatureList.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /**
  2. * Nextcloud Android client application
  3. *
  4. * @author Bartosz Przybylski
  5. * Copyright (C) 2015 Bartosz Przybylski
  6. * Copyright (C) 2015 ownCloud Inc.
  7. * Copyright (C) 2016 Nextcloud.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  11. * License as published by the Free Software Foundation; either
  12. * version 3 of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public
  20. * License along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. package com.owncloud.android.features;
  23. import android.os.Parcel;
  24. import android.os.Parcelable;
  25. import com.owncloud.android.MainApp;
  26. import com.owncloud.android.R;
  27. import com.owncloud.android.lib.common.utils.Log_OC;
  28. import java.util.LinkedList;
  29. import java.util.List;
  30. import java.util.regex.Pattern;
  31. /**
  32. * @author Bartosz Przybylski
  33. */
  34. public class FeatureList {
  35. private static final boolean SHOW_ON_FIRST_RUN = true;
  36. private static final String VERSION_1_0_0 = "1.0.0";
  37. private static final String BETA_VERSION_0 = "0";
  38. static final private FeatureItem featuresList[] = {
  39. // Basic features showed on first install
  40. new FeatureItem(R.drawable.what_new_instant_upload,
  41. R.string.welcome_feature_1_title, R.string.welcome_feature_1_text,
  42. VERSION_1_0_0, BETA_VERSION_0, SHOW_ON_FIRST_RUN),
  43. new FeatureItem(R.drawable.whats_new_files,
  44. R.string.welcome_feature_2_title, R.string.welcome_feature_2_text,
  45. VERSION_1_0_0, BETA_VERSION_0, SHOW_ON_FIRST_RUN),
  46. new FeatureItem(R.drawable.whats_new_share,
  47. R.string.welcome_feature_3_title, R.string.welcome_feature_3_text,
  48. VERSION_1_0_0, BETA_VERSION_0, SHOW_ON_FIRST_RUN),
  49. new FeatureItem(R.drawable.whats_new_accounts,
  50. R.string.welcome_feature_4_title, R.string.welcome_feature_4_text,
  51. VERSION_1_0_0, BETA_VERSION_0, SHOW_ON_FIRST_RUN),
  52. // Features introduced in certain point in time
  53. };
  54. static public FeatureItem[] get() {
  55. return featuresList;
  56. }
  57. static public FeatureItem[] getFiltered(final int lastSeenVersionCode, final boolean isFirstRun, boolean isBeta) {
  58. List<FeatureItem> features = new LinkedList<>();
  59. for (FeatureItem item : get()) {
  60. final int itemVersionCode = isBeta ? item.getBetaVersionNumber() : item.getVersionNumber();
  61. if (isFirstRun && item.shouldShowOnFirstRun()) {
  62. features.add(item);
  63. } else if (!isFirstRun && !item.shouldShowOnFirstRun() &&
  64. MainApp.getVersionCode() >= itemVersionCode &&
  65. lastSeenVersionCode < itemVersionCode) {
  66. features.add(item);
  67. }
  68. }
  69. return features.toArray(new FeatureItem[features.size()]);
  70. }
  71. static public class FeatureItem implements Parcelable {
  72. public static final int DO_NOT_SHOW = -1;
  73. private int image;
  74. private int titleText;
  75. private int contentText;
  76. private int versionNumber;
  77. private int betaVersion;
  78. private boolean showOnInitialRun;
  79. public FeatureItem(int image, int titleText, int contentText, String version, String betaVersion) {
  80. this(image, titleText, contentText, version, betaVersion, false);
  81. }
  82. public FeatureItem(int image, int titleText, int contentText, String version, String betaVersion, boolean showOnInitialRun) {
  83. this.image = image;
  84. this.titleText = titleText;
  85. this.contentText = contentText;
  86. this.versionNumber = versionCodeFromString(version);
  87. this.betaVersion = Integer.parseInt(betaVersion);
  88. this.showOnInitialRun = showOnInitialRun;
  89. }
  90. public boolean shouldShowImage() { return image != DO_NOT_SHOW; }
  91. public int getImage() { return image; }
  92. public boolean shouldShowTitleText() { return titleText != DO_NOT_SHOW; }
  93. public int getTitleText() { return titleText; }
  94. public boolean shouldShowContentText() { return contentText != DO_NOT_SHOW; }
  95. public int getContentText() { return contentText; }
  96. public int getVersionNumber() { return versionNumber; }
  97. public int getBetaVersionNumber() { return betaVersion; }
  98. public boolean shouldShowOnFirstRun() { return showOnInitialRun; }
  99. @Override
  100. public int describeContents() {
  101. return 0;
  102. }
  103. @Override
  104. public void writeToParcel(Parcel dest, int flags) {
  105. dest.writeInt(image);
  106. dest.writeInt(titleText);
  107. dest.writeInt(contentText);
  108. dest.writeInt(versionNumber);
  109. dest.writeInt(betaVersion);
  110. dest.writeByte((byte) (showOnInitialRun ? 1 : 0));
  111. }
  112. private FeatureItem(Parcel p) {
  113. image = p.readInt();
  114. titleText = p.readInt();
  115. contentText = p.readInt();
  116. versionNumber = p.readInt();
  117. betaVersion = p.readInt();
  118. showOnInitialRun = p.readByte() == 1;
  119. }
  120. public static final Parcelable.Creator CREATOR =
  121. new Parcelable.Creator() {
  122. @Override
  123. public Object createFromParcel(Parcel source) {
  124. return new FeatureItem(source);
  125. }
  126. @Override
  127. public Object[] newArray(int size) {
  128. return new FeatureItem[size];
  129. }
  130. };
  131. }
  132. private static int versionCodeFromString(String version) {
  133. String v[] = version.split(Pattern.quote("."));
  134. if (v.length != 3) {
  135. Log_OC.e("FeatureList", "Version string is incorrect " + version);
  136. return 0;
  137. }
  138. return Integer.parseInt(v[0])*(int)(10e6) +
  139. Integer.parseInt(v[1])*(int)(10e4) +
  140. Integer.parseInt(v[2])*100;
  141. }
  142. }