|
21 | 21 | * You should have received a copy of the GNU Affero General Public |
22 | 22 | * License along with this program. If not, see <http://www.gnu.org/licenses/>. |
23 | 23 | */ |
24 | | -package com.nextcloud.client.onboarding; |
25 | | - |
26 | | -import android.os.Bundle; |
27 | | -import android.view.View; |
28 | | -import android.widget.Button; |
29 | | -import android.widget.ImageButton; |
30 | | -import android.widget.TextView; |
31 | | - |
32 | | -import com.google.android.material.button.MaterialButton; |
33 | | -import com.nextcloud.android.common.ui.theme.utils.ColorRole; |
34 | | -import com.nextcloud.client.appinfo.AppInfo; |
35 | | -import com.nextcloud.client.di.Injectable; |
36 | | -import com.nextcloud.client.preferences.AppPreferences; |
37 | | -import com.owncloud.android.BuildConfig; |
38 | | -import com.owncloud.android.R; |
39 | | -import com.owncloud.android.databinding.WhatsNewActivityBinding; |
40 | | -import com.owncloud.android.ui.adapter.FeaturesViewAdapter; |
41 | | -import com.owncloud.android.ui.adapter.FeaturesWebViewAdapter; |
42 | | -import com.owncloud.android.ui.whatsnew.ProgressIndicator; |
43 | | -import com.owncloud.android.utils.theme.ViewThemeUtils; |
44 | | - |
45 | | -import javax.inject.Inject; |
46 | | - |
47 | | -import androidx.fragment.app.FragmentActivity; |
48 | | -import androidx.viewpager.widget.ViewPager; |
| 24 | +package com.nextcloud.client.onboarding |
| 25 | + |
| 26 | +import android.os.Bundle |
| 27 | +import android.view.View |
| 28 | +import androidx.activity.OnBackPressedCallback |
| 29 | +import androidx.fragment.app.FragmentActivity |
| 30 | +import androidx.viewpager.widget.ViewPager |
| 31 | +import com.nextcloud.android.common.ui.theme.utils.ColorRole |
| 32 | +import com.nextcloud.client.appinfo.AppInfo |
| 33 | +import com.nextcloud.client.di.Injectable |
| 34 | +import com.nextcloud.client.preferences.AppPreferences |
| 35 | +import com.owncloud.android.BuildConfig |
| 36 | +import com.owncloud.android.R |
| 37 | +import com.owncloud.android.databinding.WhatsNewActivityBinding |
| 38 | +import com.owncloud.android.ui.adapter.FeaturesViewAdapter |
| 39 | +import com.owncloud.android.ui.adapter.FeaturesWebViewAdapter |
| 40 | +import com.owncloud.android.utils.theme.ViewThemeUtils |
| 41 | +import javax.inject.Inject |
49 | 42 |
|
50 | 43 | /** |
51 | 44 | * Activity displaying new features after an update. |
52 | 45 | */ |
53 | | -public class WhatsNewActivity extends FragmentActivity implements ViewPager.OnPageChangeListener, Injectable { |
54 | | - |
55 | | - @Inject AppPreferences preferences; |
56 | | - @Inject AppInfo appInfo; |
57 | | - @Inject OnboardingService onboarding; |
58 | | - @Inject ViewThemeUtils.Factory viewThemeUtilsFactory; |
59 | | - private ViewThemeUtils viewThemeUtils; |
60 | | - |
61 | | - private WhatsNewActivityBinding binding; |
62 | | - |
63 | | - @Override |
64 | | - protected void onCreate(Bundle savedInstanceState) { |
65 | | - super.onCreate(savedInstanceState); |
66 | | - binding = WhatsNewActivityBinding.inflate(getLayoutInflater()); |
67 | | - setContentView(binding.getRoot()); |
68 | | - |
69 | | - viewThemeUtils = viewThemeUtilsFactory.withPrimaryAsBackground(); |
70 | | - viewThemeUtils.platform.themeStatusBar(this, ColorRole.PRIMARY); |
71 | | - |
72 | | - |
73 | | - String[] urls = getResources().getStringArray(R.array.whatsnew_urls); |
74 | | - |
75 | | - boolean showWebView = urls.length > 0; |
76 | | - |
77 | | - if (showWebView) { |
78 | | - FeaturesWebViewAdapter featuresWebViewAdapter = new FeaturesWebViewAdapter(getSupportFragmentManager(), |
79 | | - urls); |
80 | | - binding.progressIndicator.setNumberOfSteps(featuresWebViewAdapter.getCount()); |
81 | | - binding.contentPanel.setAdapter(featuresWebViewAdapter); |
82 | | - } else { |
83 | | - FeaturesViewAdapter featuresViewAdapter = new FeaturesViewAdapter(getSupportFragmentManager(), |
84 | | - onboarding.getWhatsNew()); |
85 | | - binding.progressIndicator.setNumberOfSteps(featuresViewAdapter.getCount()); |
86 | | - binding.contentPanel.setAdapter(featuresViewAdapter); |
87 | | - } |
| 46 | +class WhatsNewActivity : FragmentActivity(), ViewPager.OnPageChangeListener, Injectable { |
88 | 47 |
|
89 | | - binding.contentPanel.addOnPageChangeListener(this); |
| 48 | + @JvmField |
| 49 | + @Inject |
| 50 | + var preferences: AppPreferences? = null |
90 | 51 |
|
91 | | - viewThemeUtils.platform.colorImageView(binding.forward, ColorRole.ON_PRIMARY); |
| 52 | + @JvmField |
| 53 | + @Inject |
| 54 | + var appInfo: AppInfo? = null |
92 | 55 |
|
93 | | - binding.forward.setOnClickListener(view -> { |
94 | | - if (binding.progressIndicator.hasNextStep()) { |
95 | | - binding.contentPanel.setCurrentItem(binding.contentPanel.getCurrentItem() + 1, true); |
96 | | - binding.progressIndicator.animateToStep(binding.contentPanel.getCurrentItem() + 1); |
97 | | - } else { |
98 | | - onFinish(); |
99 | | - finish(); |
100 | | - } |
101 | | - updateNextButtonIfNeeded(); |
102 | | - }); |
| 56 | + @JvmField |
| 57 | + @Inject |
| 58 | + var onboarding: OnboardingService? = null |
| 59 | + |
| 60 | + @JvmField |
| 61 | + @Inject |
| 62 | + var viewThemeUtilsFactory: ViewThemeUtils.Factory? = null |
103 | 63 |
|
104 | | - binding.forward.setBackground(null); |
| 64 | + private var viewThemeUtils: ViewThemeUtils? = null |
105 | 65 |
|
106 | | - viewThemeUtils.platform.colorTextView(binding.skip, ColorRole.ON_PRIMARY); |
107 | | - binding.skip.setOnClickListener(view -> { |
108 | | - onFinish(); |
109 | | - finish(); |
110 | | - }); |
| 66 | + private lateinit var binding: WhatsNewActivityBinding |
111 | 67 |
|
112 | | - viewThemeUtils.platform.colorTextView(binding.welcomeText, ColorRole.ON_PRIMARY); |
| 68 | + override fun onCreate(savedInstanceState: Bundle?) { |
| 69 | + super.onCreate(savedInstanceState) |
113 | 70 |
|
114 | | - if (showWebView) { |
115 | | - binding.welcomeText.setText(R.string.app_name); |
| 71 | + binding = WhatsNewActivityBinding.inflate(layoutInflater) |
| 72 | + setContentView(binding.root) |
| 73 | + |
| 74 | + viewThemeUtils = viewThemeUtilsFactory?.withPrimaryAsBackground() |
| 75 | + viewThemeUtils?.platform?.themeStatusBar(this, ColorRole.PRIMARY) |
| 76 | + |
| 77 | + val urls = resources.getStringArray(R.array.whatsnew_urls) |
| 78 | + val showWebView = urls.isNotEmpty() |
| 79 | + |
| 80 | + setupFeatureViewAdapter(showWebView, urls) |
| 81 | + binding.contentPanel.addOnPageChangeListener(this) |
| 82 | + setupForwardImageButton() |
| 83 | + setupSkipImageButton() |
| 84 | + setupWelcomeText(showWebView) |
| 85 | + updateNextButtonIfNeeded() |
| 86 | + handleOnBackPressed() |
| 87 | + } |
| 88 | + |
| 89 | + private fun setupFeatureViewAdapter(showWebView: Boolean, urls: Array<String>) { |
| 90 | + val adapter = if (showWebView) { |
| 91 | + FeaturesWebViewAdapter(supportFragmentManager, *urls) |
116 | 92 | } else { |
117 | | - binding.welcomeText.setText(String.format(getString(R.string.whats_new_title), appInfo.getVersionName())); |
| 93 | + onboarding?.let { |
| 94 | + FeaturesViewAdapter(supportFragmentManager, *it.whatsNew) |
| 95 | + } |
118 | 96 | } |
119 | 97 |
|
120 | | - updateNextButtonIfNeeded(); |
| 98 | + adapter?.let { |
| 99 | + binding.progressIndicator.setNumberOfSteps(it.count) |
| 100 | + binding.contentPanel.adapter = it |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + private fun setupForwardImageButton() { |
| 105 | + viewThemeUtils?.platform?.colorImageView(binding.forward, ColorRole.ON_PRIMARY) |
| 106 | + binding.forward.setOnClickListener { |
| 107 | + if (binding.progressIndicator.hasNextStep()) { |
| 108 | + binding.contentPanel.setCurrentItem(binding.contentPanel.currentItem + 1, true) |
| 109 | + binding.progressIndicator.animateToStep(binding.contentPanel.currentItem + 1) |
| 110 | + } else { |
| 111 | + onFinish() |
| 112 | + finish() |
| 113 | + } |
| 114 | + updateNextButtonIfNeeded() |
| 115 | + } |
| 116 | + binding.forward.background = null |
121 | 117 | } |
122 | 118 |
|
123 | | - @Override |
124 | | - public void onBackPressed() { |
125 | | - onFinish(); |
126 | | - super.onBackPressed(); |
| 119 | + private fun setupSkipImageButton() { |
| 120 | + viewThemeUtils?.platform?.colorTextView(binding.skip, ColorRole.ON_PRIMARY) |
| 121 | + binding.skip.setOnClickListener { |
| 122 | + onFinish() |
| 123 | + finish() |
| 124 | + } |
127 | 125 | } |
128 | 126 |
|
129 | | - private void updateNextButtonIfNeeded() { |
130 | | - if (!binding.progressIndicator.hasNextStep()) { |
131 | | - binding.forward.setImageResource(R.drawable.ic_ok); |
132 | | - binding.skip.setVisibility(View.INVISIBLE); |
| 127 | + private fun setupWelcomeText(showWebView: Boolean) { |
| 128 | + viewThemeUtils?.platform?.colorTextView(binding.welcomeText, ColorRole.ON_PRIMARY) |
| 129 | + binding.welcomeText.text = if (showWebView) { |
| 130 | + getString(R.string.app_name) |
133 | 131 | } else { |
134 | | - binding.forward.setImageResource(R.drawable.arrow_right); |
135 | | - binding.skip.setVisibility(View.VISIBLE); |
| 132 | + String.format(getString(R.string.whats_new_title), appInfo?.versionName) |
136 | 133 | } |
137 | 134 | } |
138 | 135 |
|
139 | | - private void onFinish() { |
140 | | - preferences.setLastSeenVersionCode(BuildConfig.VERSION_CODE); |
| 136 | + private fun handleOnBackPressed() { |
| 137 | + onBackPressedDispatcher.addCallback( |
| 138 | + this, |
| 139 | + object : OnBackPressedCallback(true) { |
| 140 | + override fun handleOnBackPressed() { |
| 141 | + onFinish() |
| 142 | + onBackPressedDispatcher.onBackPressed() |
| 143 | + } |
| 144 | + } |
| 145 | + ) |
141 | 146 | } |
142 | 147 |
|
143 | | - @Override |
144 | | - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { |
145 | | - // unused but to be implemented due to abstract parent |
| 148 | + private fun updateNextButtonIfNeeded() { |
| 149 | + val hasNextStep = binding.progressIndicator.hasNextStep() |
| 150 | + binding.forward.setImageResource(if (hasNextStep) R.drawable.arrow_right else R.drawable.ic_ok) |
| 151 | + binding.skip.visibility = if (hasNextStep) View.VISIBLE else View.INVISIBLE |
146 | 152 | } |
147 | 153 |
|
148 | | - @Override |
149 | | - public void onPageSelected(int position) { |
150 | | - binding.progressIndicator.animateToStep(position + 1); |
151 | | - updateNextButtonIfNeeded(); |
| 154 | + private fun onFinish() { |
| 155 | + preferences?.lastSeenVersionCode = BuildConfig.VERSION_CODE |
152 | 156 | } |
153 | 157 |
|
154 | | - @Override |
155 | | - public void onPageScrollStateChanged(int state) { |
156 | | - // unused but to be implemented due to abstract parent |
| 158 | + override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {} |
| 159 | + |
| 160 | + override fun onPageSelected(position: Int) { |
| 161 | + binding.progressIndicator.animateToStep(position + 1) |
| 162 | + updateNextButtonIfNeeded() |
157 | 163 | } |
158 | | -} |
159 | 164 |
|
| 165 | + override fun onPageScrollStateChanged(state: Int) {} |
| 166 | +} |
0 commit comments