WhatsNewActivity.java 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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.ui.activity;
  23. import android.content.Context;
  24. import android.content.Intent;
  25. import android.os.Build;
  26. import android.os.Bundle;
  27. import android.support.v4.app.FragmentActivity;
  28. import android.support.v4.view.ViewPager;
  29. import android.view.View;
  30. import android.widget.Button;
  31. import android.widget.ImageButton;
  32. import android.widget.TextView;
  33. import com.owncloud.android.MainApp;
  34. import com.owncloud.android.R;
  35. import com.owncloud.android.authentication.AccountUtils;
  36. import com.owncloud.android.db.PreferenceManager;
  37. import com.owncloud.android.features.FeatureItem;
  38. import com.owncloud.android.ui.adapter.FeaturesViewAdapter;
  39. import com.owncloud.android.ui.adapter.FeaturesWebViewAdapter;
  40. import com.owncloud.android.ui.whatsnew.ProgressIndicator;
  41. import com.owncloud.android.utils.ThemeUtils;
  42. /**
  43. * Activity displaying new features after an update.
  44. */
  45. public class WhatsNewActivity extends FragmentActivity implements ViewPager.OnPageChangeListener {
  46. private ImageButton mForwardFinishButton;
  47. private Button mSkipButton;
  48. private ProgressIndicator mProgress;
  49. private ViewPager mPager;
  50. @Override
  51. protected void onCreate(Bundle savedInstanceState) {
  52. super.onCreate(savedInstanceState);
  53. setContentView(R.layout.whats_new_activity);
  54. int fontColor = getResources().getColor(R.color.login_text_color);
  55. mProgress = findViewById(R.id.progressIndicator);
  56. mPager = findViewById(R.id.contentPanel);
  57. String[] urls = getResources().getStringArray(R.array.whatsnew_urls);
  58. boolean showWebView = urls.length > 0;
  59. if (showWebView) {
  60. FeaturesWebViewAdapter featuresWebViewAdapter = new FeaturesWebViewAdapter(getSupportFragmentManager(),
  61. urls);
  62. mProgress.setNumberOfSteps(featuresWebViewAdapter.getCount());
  63. mPager.setAdapter(featuresWebViewAdapter);
  64. } else {
  65. FeaturesViewAdapter featuresViewAdapter = new FeaturesViewAdapter(getSupportFragmentManager(),
  66. getWhatsNew(this));
  67. mProgress.setNumberOfSteps(featuresViewAdapter.getCount());
  68. mPager.setAdapter(featuresViewAdapter);
  69. }
  70. mPager.addOnPageChangeListener(this);
  71. mForwardFinishButton = findViewById(R.id.forward);
  72. ThemeUtils.colorImageButton(mForwardFinishButton, fontColor);
  73. mForwardFinishButton.setOnClickListener(view -> {
  74. if (mProgress.hasNextStep()) {
  75. mPager.setCurrentItem(mPager.getCurrentItem() + 1, true);
  76. mProgress.animateToStep(mPager.getCurrentItem() + 1);
  77. } else {
  78. onFinish();
  79. finish();
  80. }
  81. updateNextButtonIfNeeded();
  82. });
  83. if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
  84. mForwardFinishButton.setBackground(null);
  85. } else {
  86. mForwardFinishButton.setBackgroundDrawable(null);
  87. }
  88. mSkipButton = findViewById(R.id.skip);
  89. mSkipButton.setTextColor(fontColor);
  90. mSkipButton.setOnClickListener(view -> {
  91. onFinish();
  92. finish();
  93. });
  94. TextView tv = findViewById(R.id.welcomeText);
  95. if (showWebView) {
  96. tv.setText(R.string.app_name);
  97. } else {
  98. tv.setText(String.format(getString(R.string.whats_new_title), MainApp.getVersionName()));
  99. }
  100. updateNextButtonIfNeeded();
  101. }
  102. @Override
  103. public void onBackPressed() {
  104. onFinish();
  105. super.onBackPressed();
  106. }
  107. private void updateNextButtonIfNeeded() {
  108. if (!mProgress.hasNextStep()) {
  109. mForwardFinishButton.setImageResource(R.drawable.ic_done_white);
  110. mSkipButton.setVisibility(View.INVISIBLE);
  111. } else {
  112. mForwardFinishButton.setImageResource(R.drawable.arrow_right);
  113. mSkipButton.setVisibility(View.VISIBLE);
  114. }
  115. }
  116. private void onFinish() {
  117. PreferenceManager.setLastSeenVersionCode(this, MainApp.getVersionCode());
  118. }
  119. public static void runIfNeeded(Context context) {
  120. if (!context.getResources().getBoolean(R.bool.show_whats_new)
  121. || context instanceof WhatsNewActivity) {
  122. return;
  123. }
  124. if (shouldShow(context)) {
  125. context.startActivity(new Intent(context, WhatsNewActivity.class));
  126. }
  127. }
  128. private static boolean shouldShow(Context context) {
  129. return !(context instanceof PassCodeActivity) && getWhatsNew(context).length > 0;
  130. }
  131. @Override
  132. public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
  133. // unused but to be implemented due to abstract parent
  134. }
  135. @Override
  136. public void onPageSelected(int position) {
  137. mProgress.animateToStep(position + 1);
  138. updateNextButtonIfNeeded();
  139. }
  140. @Override
  141. public void onPageScrollStateChanged(int state) {
  142. // unused but to be implemented due to abstract parent
  143. }
  144. static private boolean isFirstRun(Context context) {
  145. return AccountUtils.getCurrentOwnCloudAccount(context) == null;
  146. }
  147. static private FeatureItem[] getWhatsNew(Context context) {
  148. int itemVersionCode = 30030000;
  149. if (!isFirstRun(context) && MainApp.getVersionCode() >= itemVersionCode
  150. && PreferenceManager.getLastSeenVersionCode(context) < itemVersionCode) {
  151. return new FeatureItem[]{new FeatureItem(R.drawable.whats_new_device_credentials,
  152. R.string.whats_new_device_credentials_title, R.string.whats_new_device_credentials_content,
  153. false, false)};
  154. } else {
  155. return new FeatureItem[0];
  156. }
  157. }
  158. }