|
@@ -21,139 +21,146 @@
|
|
|
* You should have received a copy of the GNU Affero General Public
|
|
|
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
*/
|
|
|
-package com.nextcloud.client.onboarding;
|
|
|
-
|
|
|
-import android.os.Bundle;
|
|
|
-import android.view.View;
|
|
|
-import android.widget.Button;
|
|
|
-import android.widget.ImageButton;
|
|
|
-import android.widget.TextView;
|
|
|
-
|
|
|
-import com.google.android.material.button.MaterialButton;
|
|
|
-import com.nextcloud.android.common.ui.theme.utils.ColorRole;
|
|
|
-import com.nextcloud.client.appinfo.AppInfo;
|
|
|
-import com.nextcloud.client.di.Injectable;
|
|
|
-import com.nextcloud.client.preferences.AppPreferences;
|
|
|
-import com.owncloud.android.BuildConfig;
|
|
|
-import com.owncloud.android.R;
|
|
|
-import com.owncloud.android.databinding.WhatsNewActivityBinding;
|
|
|
-import com.owncloud.android.ui.adapter.FeaturesViewAdapter;
|
|
|
-import com.owncloud.android.ui.adapter.FeaturesWebViewAdapter;
|
|
|
-import com.owncloud.android.ui.whatsnew.ProgressIndicator;
|
|
|
-import com.owncloud.android.utils.theme.ViewThemeUtils;
|
|
|
-
|
|
|
-import javax.inject.Inject;
|
|
|
-
|
|
|
-import androidx.fragment.app.FragmentActivity;
|
|
|
-import androidx.viewpager.widget.ViewPager;
|
|
|
+package com.nextcloud.client.onboarding
|
|
|
+
|
|
|
+import android.os.Bundle
|
|
|
+import android.view.View
|
|
|
+import androidx.activity.OnBackPressedCallback
|
|
|
+import androidx.fragment.app.FragmentActivity
|
|
|
+import androidx.viewpager.widget.ViewPager
|
|
|
+import com.nextcloud.android.common.ui.theme.utils.ColorRole
|
|
|
+import com.nextcloud.client.appinfo.AppInfo
|
|
|
+import com.nextcloud.client.di.Injectable
|
|
|
+import com.nextcloud.client.preferences.AppPreferences
|
|
|
+import com.owncloud.android.BuildConfig
|
|
|
+import com.owncloud.android.R
|
|
|
+import com.owncloud.android.databinding.WhatsNewActivityBinding
|
|
|
+import com.owncloud.android.ui.adapter.FeaturesViewAdapter
|
|
|
+import com.owncloud.android.ui.adapter.FeaturesWebViewAdapter
|
|
|
+import com.owncloud.android.utils.theme.ViewThemeUtils
|
|
|
+import javax.inject.Inject
|
|
|
|
|
|
/**
|
|
|
* Activity displaying new features after an update.
|
|
|
*/
|
|
|
-public class WhatsNewActivity extends FragmentActivity implements ViewPager.OnPageChangeListener, Injectable {
|
|
|
-
|
|
|
- @Inject AppPreferences preferences;
|
|
|
- @Inject AppInfo appInfo;
|
|
|
- @Inject OnboardingService onboarding;
|
|
|
- @Inject ViewThemeUtils.Factory viewThemeUtilsFactory;
|
|
|
- private ViewThemeUtils viewThemeUtils;
|
|
|
-
|
|
|
- private WhatsNewActivityBinding binding;
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onCreate(Bundle savedInstanceState) {
|
|
|
- super.onCreate(savedInstanceState);
|
|
|
- binding = WhatsNewActivityBinding.inflate(getLayoutInflater());
|
|
|
- setContentView(binding.getRoot());
|
|
|
-
|
|
|
- viewThemeUtils = viewThemeUtilsFactory.withPrimaryAsBackground();
|
|
|
- viewThemeUtils.platform.themeStatusBar(this, ColorRole.PRIMARY);
|
|
|
-
|
|
|
-
|
|
|
- String[] urls = getResources().getStringArray(R.array.whatsnew_urls);
|
|
|
-
|
|
|
- boolean showWebView = urls.length > 0;
|
|
|
-
|
|
|
- if (showWebView) {
|
|
|
- FeaturesWebViewAdapter featuresWebViewAdapter = new FeaturesWebViewAdapter(getSupportFragmentManager(),
|
|
|
- urls);
|
|
|
- binding.progressIndicator.setNumberOfSteps(featuresWebViewAdapter.getCount());
|
|
|
- binding.contentPanel.setAdapter(featuresWebViewAdapter);
|
|
|
- } else {
|
|
|
- FeaturesViewAdapter featuresViewAdapter = new FeaturesViewAdapter(getSupportFragmentManager(),
|
|
|
- onboarding.getWhatsNew());
|
|
|
- binding.progressIndicator.setNumberOfSteps(featuresViewAdapter.getCount());
|
|
|
- binding.contentPanel.setAdapter(featuresViewAdapter);
|
|
|
- }
|
|
|
+class WhatsNewActivity : FragmentActivity(), ViewPager.OnPageChangeListener, Injectable {
|
|
|
|
|
|
- binding.contentPanel.addOnPageChangeListener(this);
|
|
|
+ @JvmField
|
|
|
+ @Inject
|
|
|
+ var preferences: AppPreferences? = null
|
|
|
|
|
|
- viewThemeUtils.platform.colorImageView(binding.forward, ColorRole.ON_PRIMARY);
|
|
|
+ @JvmField
|
|
|
+ @Inject
|
|
|
+ var appInfo: AppInfo? = null
|
|
|
|
|
|
- binding.forward.setOnClickListener(view -> {
|
|
|
- if (binding.progressIndicator.hasNextStep()) {
|
|
|
- binding.contentPanel.setCurrentItem(binding.contentPanel.getCurrentItem() + 1, true);
|
|
|
- binding.progressIndicator.animateToStep(binding.contentPanel.getCurrentItem() + 1);
|
|
|
- } else {
|
|
|
- onFinish();
|
|
|
- finish();
|
|
|
- }
|
|
|
- updateNextButtonIfNeeded();
|
|
|
- });
|
|
|
+ @JvmField
|
|
|
+ @Inject
|
|
|
+ var onboarding: OnboardingService? = null
|
|
|
+
|
|
|
+ @JvmField
|
|
|
+ @Inject
|
|
|
+ var viewThemeUtilsFactory: ViewThemeUtils.Factory? = null
|
|
|
|
|
|
- binding.forward.setBackground(null);
|
|
|
+ private var viewThemeUtils: ViewThemeUtils? = null
|
|
|
|
|
|
- viewThemeUtils.platform.colorTextView(binding.skip, ColorRole.ON_PRIMARY);
|
|
|
- binding.skip.setOnClickListener(view -> {
|
|
|
- onFinish();
|
|
|
- finish();
|
|
|
- });
|
|
|
+ private lateinit var binding: WhatsNewActivityBinding
|
|
|
|
|
|
- viewThemeUtils.platform.colorTextView(binding.welcomeText, ColorRole.ON_PRIMARY);
|
|
|
+ override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
+ super.onCreate(savedInstanceState)
|
|
|
|
|
|
- if (showWebView) {
|
|
|
- binding.welcomeText.setText(R.string.app_name);
|
|
|
+ binding = WhatsNewActivityBinding.inflate(layoutInflater)
|
|
|
+ setContentView(binding.root)
|
|
|
+
|
|
|
+ viewThemeUtils = viewThemeUtilsFactory?.withPrimaryAsBackground()
|
|
|
+ viewThemeUtils?.platform?.themeStatusBar(this, ColorRole.PRIMARY)
|
|
|
+
|
|
|
+ val urls = resources.getStringArray(R.array.whatsnew_urls)
|
|
|
+ val showWebView = urls.isNotEmpty()
|
|
|
+
|
|
|
+ setupFeatureViewAdapter(showWebView, urls)
|
|
|
+ binding.contentPanel.addOnPageChangeListener(this)
|
|
|
+ setupForwardImageButton()
|
|
|
+ setupSkipImageButton()
|
|
|
+ setupWelcomeText(showWebView)
|
|
|
+ updateNextButtonIfNeeded()
|
|
|
+ handleOnBackPressed()
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun setupFeatureViewAdapter(showWebView: Boolean, urls: Array<String>) {
|
|
|
+ val adapter = if (showWebView) {
|
|
|
+ FeaturesWebViewAdapter(supportFragmentManager, *urls)
|
|
|
} else {
|
|
|
- binding.welcomeText.setText(String.format(getString(R.string.whats_new_title), appInfo.getVersionName()));
|
|
|
+ onboarding?.let {
|
|
|
+ FeaturesViewAdapter(supportFragmentManager, *it.whatsNew)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- updateNextButtonIfNeeded();
|
|
|
+ adapter?.let {
|
|
|
+ binding.progressIndicator.setNumberOfSteps(it.count)
|
|
|
+ binding.contentPanel.adapter = it
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun setupForwardImageButton() {
|
|
|
+ viewThemeUtils?.platform?.colorImageView(binding.forward, ColorRole.ON_PRIMARY)
|
|
|
+ binding.forward.setOnClickListener {
|
|
|
+ if (binding.progressIndicator.hasNextStep()) {
|
|
|
+ binding.contentPanel.setCurrentItem(binding.contentPanel.currentItem + 1, true)
|
|
|
+ binding.progressIndicator.animateToStep(binding.contentPanel.currentItem + 1)
|
|
|
+ } else {
|
|
|
+ onFinish()
|
|
|
+ finish()
|
|
|
+ }
|
|
|
+ updateNextButtonIfNeeded()
|
|
|
+ }
|
|
|
+ binding.forward.background = null
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void onBackPressed() {
|
|
|
- onFinish();
|
|
|
- super.onBackPressed();
|
|
|
+ private fun setupSkipImageButton() {
|
|
|
+ viewThemeUtils?.platform?.colorTextView(binding.skip, ColorRole.ON_PRIMARY)
|
|
|
+ binding.skip.setOnClickListener {
|
|
|
+ onFinish()
|
|
|
+ finish()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private void updateNextButtonIfNeeded() {
|
|
|
- if (!binding.progressIndicator.hasNextStep()) {
|
|
|
- binding.forward.setImageResource(R.drawable.ic_ok);
|
|
|
- binding.skip.setVisibility(View.INVISIBLE);
|
|
|
+ private fun setupWelcomeText(showWebView: Boolean) {
|
|
|
+ viewThemeUtils?.platform?.colorTextView(binding.welcomeText, ColorRole.ON_PRIMARY)
|
|
|
+ binding.welcomeText.text = if (showWebView) {
|
|
|
+ getString(R.string.app_name)
|
|
|
} else {
|
|
|
- binding.forward.setImageResource(R.drawable.arrow_right);
|
|
|
- binding.skip.setVisibility(View.VISIBLE);
|
|
|
+ String.format(getString(R.string.whats_new_title), appInfo?.versionName)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void onFinish() {
|
|
|
- preferences.setLastSeenVersionCode(BuildConfig.VERSION_CODE);
|
|
|
+ private fun handleOnBackPressed() {
|
|
|
+ onBackPressedDispatcher.addCallback(
|
|
|
+ this,
|
|
|
+ object : OnBackPressedCallback(true) {
|
|
|
+ override fun handleOnBackPressed() {
|
|
|
+ onFinish()
|
|
|
+ onBackPressedDispatcher.onBackPressed()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
|
|
- // unused but to be implemented due to abstract parent
|
|
|
+ private fun updateNextButtonIfNeeded() {
|
|
|
+ val hasNextStep = binding.progressIndicator.hasNextStep()
|
|
|
+ binding.forward.setImageResource(if (hasNextStep) R.drawable.arrow_right else R.drawable.ic_ok)
|
|
|
+ binding.skip.visibility = if (hasNextStep) View.VISIBLE else View.INVISIBLE
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void onPageSelected(int position) {
|
|
|
- binding.progressIndicator.animateToStep(position + 1);
|
|
|
- updateNextButtonIfNeeded();
|
|
|
+ private fun onFinish() {
|
|
|
+ preferences?.lastSeenVersionCode = BuildConfig.VERSION_CODE
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void onPageScrollStateChanged(int state) {
|
|
|
- // unused but to be implemented due to abstract parent
|
|
|
+ override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {}
|
|
|
+
|
|
|
+ override fun onPageSelected(position: Int) {
|
|
|
+ binding.progressIndicator.animateToStep(position + 1)
|
|
|
+ updateNextButtonIfNeeded()
|
|
|
}
|
|
|
-}
|
|
|
|
|
|
+ override fun onPageScrollStateChanged(state: Int) {}
|
|
|
+}
|