WhatsNewActivity.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Nextcloud Android client application
  3. *
  4. * @author Bartosz Przybylski
  5. * @author Chris Narkiewicz
  6. * Copyright (C) 2015 Bartosz Przybylski
  7. * Copyright (C) 2015 ownCloud Inc.
  8. * Copyright (C) 2016 Nextcloud.
  9. * Copyright (C) 2019 Chris Narkiewicz <hello@ezaquarii.com>
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  13. * License as published by the Free Software Foundation; either
  14. * version 3 of the License, or any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public
  22. * License along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. package com.nextcloud.client.onboarding;
  25. import android.os.Bundle;
  26. import android.view.View;
  27. import android.widget.Button;
  28. import android.widget.ImageButton;
  29. import android.widget.TextView;
  30. import com.nextcloud.client.appinfo.AppInfo;
  31. import com.nextcloud.client.di.Injectable;
  32. import com.nextcloud.client.preferences.AppPreferences;
  33. import com.owncloud.android.BuildConfig;
  34. import com.owncloud.android.R;
  35. import com.owncloud.android.ui.adapter.FeaturesViewAdapter;
  36. import com.owncloud.android.ui.adapter.FeaturesWebViewAdapter;
  37. import com.owncloud.android.ui.whatsnew.ProgressIndicator;
  38. import com.owncloud.android.utils.ThemeUtils;
  39. import javax.inject.Inject;
  40. import androidx.fragment.app.FragmentActivity;
  41. import androidx.viewpager.widget.ViewPager;
  42. /**
  43. * Activity displaying new features after an update.
  44. */
  45. public class WhatsNewActivity extends FragmentActivity implements ViewPager.OnPageChangeListener, Injectable {
  46. private ImageButton mForwardFinishButton;
  47. private Button mSkipButton;
  48. private ProgressIndicator mProgress;
  49. private ViewPager mPager;
  50. @Inject AppPreferences preferences;
  51. @Inject AppInfo appInfo;
  52. @Inject OnboardingService onboarding;
  53. @Override
  54. protected void onCreate(Bundle savedInstanceState) {
  55. super.onCreate(savedInstanceState);
  56. setContentView(R.layout.whats_new_activity);
  57. int fontColor = getResources().getColor(R.color.login_text_color);
  58. mProgress = findViewById(R.id.progressIndicator);
  59. mPager = findViewById(R.id.contentPanel);
  60. String[] urls = getResources().getStringArray(R.array.whatsnew_urls);
  61. boolean showWebView = urls.length > 0;
  62. if (showWebView) {
  63. FeaturesWebViewAdapter featuresWebViewAdapter = new FeaturesWebViewAdapter(getSupportFragmentManager(),
  64. urls);
  65. mProgress.setNumberOfSteps(featuresWebViewAdapter.getCount());
  66. mPager.setAdapter(featuresWebViewAdapter);
  67. } else {
  68. FeaturesViewAdapter featuresViewAdapter = new FeaturesViewAdapter(getSupportFragmentManager(),
  69. onboarding.getWhatsNew());
  70. mProgress.setNumberOfSteps(featuresViewAdapter.getCount());
  71. mPager.setAdapter(featuresViewAdapter);
  72. }
  73. mPager.addOnPageChangeListener(this);
  74. mForwardFinishButton = findViewById(R.id.forward);
  75. ThemeUtils.colorImageButton(mForwardFinishButton, fontColor);
  76. mForwardFinishButton.setOnClickListener(view -> {
  77. if (mProgress.hasNextStep()) {
  78. mPager.setCurrentItem(mPager.getCurrentItem() + 1, true);
  79. mProgress.animateToStep(mPager.getCurrentItem() + 1);
  80. } else {
  81. onFinish();
  82. finish();
  83. }
  84. updateNextButtonIfNeeded();
  85. });
  86. mForwardFinishButton.setBackground(null);
  87. mSkipButton = findViewById(R.id.skip);
  88. mSkipButton.setTextColor(fontColor);
  89. mSkipButton.setOnClickListener(view -> {
  90. onFinish();
  91. finish();
  92. });
  93. TextView tv = findViewById(R.id.welcomeText);
  94. if (showWebView) {
  95. tv.setText(R.string.app_name);
  96. } else {
  97. tv.setText(String.format(getString(R.string.whats_new_title), appInfo.getFormattedVersionCode()));
  98. }
  99. updateNextButtonIfNeeded();
  100. }
  101. @Override
  102. public void onBackPressed() {
  103. onFinish();
  104. super.onBackPressed();
  105. }
  106. private void updateNextButtonIfNeeded() {
  107. if (!mProgress.hasNextStep()) {
  108. mForwardFinishButton.setImageResource(R.drawable.ic_ok);
  109. mSkipButton.setVisibility(View.INVISIBLE);
  110. } else {
  111. mForwardFinishButton.setImageResource(R.drawable.arrow_right);
  112. mSkipButton.setVisibility(View.VISIBLE);
  113. }
  114. }
  115. private void onFinish() {
  116. preferences.setLastSeenVersionCode(BuildConfig.VERSION_CODE);
  117. }
  118. @Override
  119. public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
  120. // unused but to be implemented due to abstract parent
  121. }
  122. @Override
  123. public void onPageSelected(int position) {
  124. mProgress.animateToStep(position + 1);
  125. updateNextButtonIfNeeded();
  126. }
  127. @Override
  128. public void onPageScrollStateChanged(int state) {
  129. // unused but to be implemented due to abstract parent
  130. }
  131. }