88package com.nextcloud.client.onboarding
99
1010import android.accounts.AccountManager
11+ import android.annotation.SuppressLint
1112import android.content.Intent
13+ import android.content.pm.ActivityInfo
1214import android.content.res.Configuration
1315import android.os.Bundle
14- import android.view.View
15- import android.view.ViewGroup
16- import android.widget.LinearLayout
16+ import android.view.ViewGroup.MarginLayoutParams
1717import androidx.activity.OnBackPressedCallback
1818import androidx.activity.result.ActivityResult
1919import androidx.activity.result.ActivityResultLauncher
@@ -24,14 +24,15 @@ import com.nextcloud.client.account.UserAccountManager
2424import com.nextcloud.client.appinfo.AppInfo
2525import com.nextcloud.client.di.Injectable
2626import com.nextcloud.client.preferences.AppPreferences
27+ import com.nmc.android.helper.OnBoardingPagerAdapter
28+ import com.nmc.android.helper.OnBoardingUtils.Companion.getOnBoardingItems
29+ import com.nmc.android.utils.DisplayUtils.isLandscapeOrientation
2730import com.owncloud.android.BuildConfig
2831import com.owncloud.android.R
2932import com.owncloud.android.authentication.AuthenticatorActivity
3033import com.owncloud.android.databinding.FirstRunActivityBinding
31- import com.owncloud.android.features.FeatureItem
3234import com.owncloud.android.ui.activity.BaseActivity
3335import com.owncloud.android.ui.activity.FileDisplayActivity
34- import com.owncloud.android.ui.adapter.FeaturesViewAdapter
3536import com.owncloud.android.utils.DisplayUtils
3637import com.owncloud.android.utils.theme.ViewThemeUtils
3738import javax.inject.Inject
@@ -66,25 +67,31 @@ class FirstRunActivity : BaseActivity(), ViewPager.OnPageChangeListener, Injecta
6667 private lateinit var binding: FirstRunActivityBinding
6768 private var defaultViewThemeUtils: ViewThemeUtils ? = null
6869
70+ private var selectedPosition = 0
71+
72+ @SuppressLint(" SourceLockedOrientationActivity" )
6973 override fun onCreate (savedInstanceState : Bundle ? ) {
7074 enableAccountHandling = false
7175
7276 super .onCreate(savedInstanceState)
7377
7478 applyDefaultTheme()
7579
80+ // NMC Customization
81+ // if device is not tablet then we have to lock it to Portrait mode
82+ // as we don't have images for that
83+ if (! com.nmc.android.utils.DisplayUtils .isTablet()) {
84+ requestedOrientation = ActivityInfo .SCREEN_ORIENTATION_PORTRAIT
85+ }
86+
7687 binding = FirstRunActivityBinding .inflate(layoutInflater)
7788 setContentView(binding.root)
7889
79- val isProviderOrOwnInstallationVisible = resources.getBoolean(R .bool.show_provider_or_own_installation)
80- setSlideshowSize(resources.configuration.orientation == Configuration .ORIENTATION_LANDSCAPE )
81-
8290 registerActivityResult()
8391 setupLoginButton()
84- setupSignupButton(isProviderOrOwnInstallationVisible)
85- setupHostOwnServerTextView(isProviderOrOwnInstallationVisible)
8692 deleteAccountAtFirstLaunch()
87- setupFeaturesViewAdapter()
93+ updateLoginButtonMargin()
94+ updateOnBoardingPager(selectedPosition)
8895 handleOnBackPressed()
8996 }
9097
@@ -123,57 +130,52 @@ class FirstRunActivity : BaseActivity(), ViewPager.OnPageChangeListener, Injecta
123130 val authenticatorActivityIntent = getAuthenticatorActivityIntent(false )
124131 activityResult?.launch(authenticatorActivityIntent)
125132 } else {
133+ preferences?.onBoardingComplete = true
126134 finish()
127135 }
128136 }
129137 }
130138
131- private fun setupSignupButton (isProviderOrOwnInstallationVisible : Boolean ) {
132- defaultViewThemeUtils?.material?.colorMaterialButtonOutlinedOnPrimary(binding.signup)
133- binding.signup.visibility = if (isProviderOrOwnInstallationVisible) View .VISIBLE else View .GONE
134- binding.signup.setOnClickListener {
135- val authenticatorActivityIntent = getAuthenticatorActivityIntent(true )
136-
137- if (intent.getBooleanExtra(EXTRA_ALLOW_CLOSE , false )) {
138- activityResult?.launch(authenticatorActivityIntent)
139- } else {
140- authenticatorActivityIntent.addFlags(Intent .FLAG_ACTIVITY_NEW_TASK )
141- startActivity(authenticatorActivityIntent)
142- }
143- }
144- }
145-
146139 private fun getAuthenticatorActivityIntent (extraUseProviderAsWebLogin : Boolean ): Intent {
147140 val intent = Intent (this , AuthenticatorActivity ::class .java)
148141 intent.putExtra(AuthenticatorActivity .EXTRA_USE_PROVIDER_AS_WEBLOGIN , extraUseProviderAsWebLogin)
149142 return intent
150143 }
151144
152- private fun setupHostOwnServerTextView (isProviderOrOwnInstallationVisible : Boolean ) {
153- defaultViewThemeUtils?.platform?.colorTextView(binding.hostOwnServer, ColorRole .ON_PRIMARY )
154- binding.hostOwnServer.visibility = if (isProviderOrOwnInstallationVisible) View .VISIBLE else View .GONE
155- if (isProviderOrOwnInstallationVisible) {
156- binding.hostOwnServer.setOnClickListener {
157- DisplayUtils .startLinkIntent(
158- this ,
159- R .string.url_server_install
160- )
161- }
162- }
163- }
164-
165145 // Sometimes, accounts are not deleted when you uninstall the application so we'll do it now
166146 private fun deleteAccountAtFirstLaunch () {
167147 if (onboarding?.isFirstRun == true ) {
168148 userAccountManager?.removeAllAccounts()
169149 }
170150 }
171151
172- @Suppress(" SpreadOperator" )
173- private fun setupFeaturesViewAdapter () {
174- val featuresViewAdapter = FeaturesViewAdapter (supportFragmentManager, * firstRun)
152+ private fun updateLoginButtonMargin () {
153+ if (isLandscapeOrientation()) {
154+ if (binding.login.layoutParams is MarginLayoutParams ) {
155+ (binding.login.layoutParams as MarginLayoutParams ).setMargins(
156+ 0 , 0 , 0 , resources.getDimensionPixelOffset(
157+ R .dimen.login_btn_bottom_margin_land
158+ )
159+ )
160+ binding.login.requestLayout()
161+ }
162+ } else {
163+ if (binding.login.layoutParams is MarginLayoutParams ) {
164+ (binding.login.layoutParams as MarginLayoutParams ).setMargins(
165+ 0 , 0 , 0 , resources.getDimensionPixelOffset(
166+ R .dimen.login_btn_bottom_margin
167+ )
168+ )
169+ binding.login.requestLayout()
170+ }
171+ }
172+ }
173+
174+ private fun updateOnBoardingPager (selectedPosition : Int ) {
175+ val featuresViewAdapter = OnBoardingPagerAdapter (this , getOnBoardingItems())
175176 binding.progressIndicator.setNumberOfSteps(featuresViewAdapter.count)
176177 binding.contentPanel.adapter = featuresViewAdapter
178+ binding.contentPanel.currentItem = selectedPosition
177179 binding.contentPanel.addOnPageChangeListener(this )
178180 }
179181
@@ -184,47 +186,27 @@ class FirstRunActivity : BaseActivity(), ViewPager.OnPageChangeListener, Injecta
184186 override fun handleOnBackPressed () {
185187 val isFromAddAccount = intent.getBooleanExtra(EXTRA_ALLOW_CLOSE , false )
186188
187- val destination: Intent = if (isFromAddAccount) {
188- Intent (applicationContext, FileDisplayActivity ::class .java)
189+ // NMC Customization -> Modified the condition for readability
190+ if (isFromAddAccount) {
191+ val destination = Intent (applicationContext, FileDisplayActivity ::class .java)
192+ destination.flags = Intent .FLAG_ACTIVITY_CLEAR_TOP
193+ startActivity(destination)
194+ finish()
189195 } else {
190- Intent (applicationContext, AuthenticatorActivity ::class .java)
191- }
192-
193- if (! isFromAddAccount) {
194- destination.putExtra(EXTRA_EXIT , true )
196+ // NMC Customization -> No redirection to AuthenticatorActivity is required
197+ // just close the app
198+ finishAffinity()
195199 }
196200
197- destination.flags = Intent .FLAG_ACTIVITY_CLEAR_TOP
198- startActivity(destination)
199- finish()
200201 }
201202 }
202203 )
203204 }
204205
205- private fun setSlideshowSize (isLandscape : Boolean ) {
206- val isProviderOrOwnInstallationVisible = resources.getBoolean(R .bool.show_provider_or_own_installation)
207- binding.buttonLayout.orientation = if (isLandscape) LinearLayout .HORIZONTAL else LinearLayout .VERTICAL
208-
209- val layoutParams: LinearLayout .LayoutParams = if (isProviderOrOwnInstallationVisible) {
210- LinearLayout .LayoutParams (
211- ViewGroup .LayoutParams .MATCH_PARENT ,
212- ViewGroup .LayoutParams .WRAP_CONTENT
213- )
214- } else {
215- @Suppress(" MagicNumber" )
216- LinearLayout .LayoutParams (
217- ViewGroup .LayoutParams .MATCH_PARENT ,
218- DisplayUtils .convertDpToPixel(if (isLandscape) 100f else 150f , this )
219- )
220- }
221-
222- binding.bottomLayout.layoutParams = layoutParams
223- }
224-
225206 override fun onConfigurationChanged (newConfig : Configuration ) {
226207 super .onConfigurationChanged(newConfig)
227- setSlideshowSize(newConfig.orientation == Configuration .ORIENTATION_LANDSCAPE )
208+ updateLoginButtonMargin()
209+ updateOnBoardingPager(selectedPosition)
228210 }
229211
230212 private fun onFinish () {
@@ -241,7 +223,11 @@ class FirstRunActivity : BaseActivity(), ViewPager.OnPageChangeListener, Injecta
241223 }
242224
243225 override fun onPageSelected (position : Int ) {
244- binding.progressIndicator.animateToStep(position + 1 )
226+ // -1 to position because this position doesn't start from 0
227+ selectedPosition = position - 1
228+
229+ // pass directly the position here because this position will doesn't start from 0
230+ binding.progressIndicator.animateToStep(position)
245231 }
246232
247233 override fun onPageScrollStateChanged (state : Int ) {
@@ -251,13 +237,5 @@ class FirstRunActivity : BaseActivity(), ViewPager.OnPageChangeListener, Injecta
251237 companion object {
252238 const val EXTRA_ALLOW_CLOSE = " ALLOW_CLOSE"
253239 const val EXTRA_EXIT = " EXIT"
254-
255- val firstRun: Array <FeatureItem >
256- get() = arrayOf(
257- FeatureItem (R .drawable.logo, R .string.first_run_1_text, R .string.empty, true , false ),
258- FeatureItem (R .drawable.first_run_files, R .string.first_run_2_text, R .string.empty, true , false ),
259- FeatureItem (R .drawable.first_run_groupware, R .string.first_run_3_text, R .string.empty, true , false ),
260- FeatureItem (R .drawable.first_run_talk, R .string.first_run_4_text, R .string.empty, true , false )
261- )
262240 }
263241}
0 commit comments