8
8
package com.nextcloud.client.onboarding
9
9
10
10
import android.accounts.AccountManager
11
+ import android.annotation.SuppressLint
11
12
import android.content.Intent
13
+ import android.content.pm.ActivityInfo
12
14
import android.content.res.Configuration
13
15
import android.os.Bundle
14
- import android.view.View
15
- import android.view.ViewGroup
16
- import android.widget.LinearLayout
16
+ import android.view.ViewGroup.MarginLayoutParams
17
17
import androidx.activity.OnBackPressedCallback
18
18
import androidx.activity.result.ActivityResult
19
19
import androidx.activity.result.ActivityResultLauncher
20
20
import androidx.activity.result.contract.ActivityResultContracts
21
- import androidx.viewpager2 .widget.ViewPager2
21
+ import androidx.viewpager .widget.ViewPager
22
22
import com.nextcloud.android.common.ui.theme.utils.ColorRole
23
23
import com.nextcloud.client.account.UserAccountManager
24
24
import com.nextcloud.client.appinfo.AppInfo
25
25
import com.nextcloud.client.di.Injectable
26
26
import 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
27
30
import com.owncloud.android.BuildConfig
28
31
import com.owncloud.android.R
29
32
import com.owncloud.android.authentication.AuthenticatorActivity
30
33
import com.owncloud.android.databinding.FirstRunActivityBinding
31
- import com.owncloud.android.features.FeatureItem
32
34
import com.owncloud.android.ui.activity.BaseActivity
33
35
import com.owncloud.android.ui.activity.FileDisplayActivity
34
- import com.owncloud.android.ui.adapter.FeaturesViewAdapter
35
36
import com.owncloud.android.utils.DisplayUtils
36
37
import com.owncloud.android.utils.theme.ViewThemeUtils
37
38
import javax.inject.Inject
38
39
39
40
/* *
40
41
* Activity displaying general feature after a fresh install.
41
42
*/
42
- class FirstRunActivity : BaseActivity (), Injectable {
43
+ class FirstRunActivity : BaseActivity (), ViewPager.OnPageChangeListener, Injectable {
43
44
44
45
@JvmField
45
46
@Inject
@@ -66,25 +67,31 @@ class FirstRunActivity : BaseActivity(), Injectable {
66
67
private lateinit var binding: FirstRunActivityBinding
67
68
private var defaultViewThemeUtils: ViewThemeUtils ? = null
68
69
70
+ private var selectedPosition = 0
71
+
72
+ @SuppressLint(" SourceLockedOrientationActivity" )
69
73
override fun onCreate (savedInstanceState : Bundle ? ) {
70
74
enableAccountHandling = false
71
75
72
76
super .onCreate(savedInstanceState)
73
77
74
78
applyDefaultTheme()
75
79
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
+
76
87
binding = FirstRunActivityBinding .inflate(layoutInflater)
77
88
setContentView(binding.root)
78
89
79
- val isProviderOrOwnInstallationVisible = resources.getBoolean(R .bool.show_provider_or_own_installation)
80
- setSlideshowSize(resources.configuration.orientation == Configuration .ORIENTATION_LANDSCAPE )
81
-
82
90
registerActivityResult()
83
91
setupLoginButton()
84
- setupSignupButton(isProviderOrOwnInstallationVisible)
85
- setupHostOwnServerTextView(isProviderOrOwnInstallationVisible)
86
92
deleteAccountAtFirstLaunch()
87
- setupFeaturesViewAdapter()
93
+ updateLoginButtonMargin()
94
+ updateOnBoardingPager(selectedPosition)
88
95
handleOnBackPressed()
89
96
}
90
97
@@ -123,62 +130,53 @@ class FirstRunActivity : BaseActivity(), Injectable {
123
130
val authenticatorActivityIntent = getAuthenticatorActivityIntent(false )
124
131
activityResult?.launch(authenticatorActivityIntent)
125
132
} else {
133
+ preferences?.onBoardingComplete = true
126
134
finish()
127
135
}
128
136
}
129
137
}
130
138
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
-
146
139
private fun getAuthenticatorActivityIntent (extraUseProviderAsWebLogin : Boolean ): Intent {
147
140
val intent = Intent (this , AuthenticatorActivity ::class .java)
148
141
intent.putExtra(AuthenticatorActivity .EXTRA_USE_PROVIDER_AS_WEBLOGIN , extraUseProviderAsWebLogin)
149
142
return intent
150
143
}
151
144
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
-
165
145
// Sometimes, accounts are not deleted when you uninstall the application so we'll do it now
166
146
private fun deleteAccountAtFirstLaunch () {
167
147
if (onboarding?.isFirstRun == true ) {
168
148
userAccountManager?.removeAllAccounts()
169
149
}
170
150
}
171
151
172
- @Suppress(" SpreadOperator" )
173
- private fun setupFeaturesViewAdapter () {
174
- val featuresViewAdapter = FeaturesViewAdapter (this , * firstRun)
175
- binding.progressIndicator.setNumberOfSteps(featuresViewAdapter.itemCount)
176
- binding.contentPanel.adapter = featuresViewAdapter
177
- binding.contentPanel.registerOnPageChangeCallback(object : ViewPager2 .OnPageChangeCallback () {
178
- override fun onPageSelected (position : Int ) {
179
- binding.progressIndicator.animateToStep(position + 1 )
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()
180
170
}
181
- })
171
+ }
172
+ }
173
+
174
+ private fun updateOnBoardingPager (selectedPosition : Int ) {
175
+ val featuresViewAdapter = OnBoardingPagerAdapter (this , getOnBoardingItems())
176
+ binding.progressIndicator.setNumberOfSteps(featuresViewAdapter.count)
177
+ binding.contentPanel.adapter = featuresViewAdapter
178
+ binding.contentPanel.currentItem = selectedPosition
179
+ binding.contentPanel.addOnPageChangeListener(this )
182
180
}
183
181
184
182
private fun handleOnBackPressed () {
@@ -188,47 +186,27 @@ class FirstRunActivity : BaseActivity(), Injectable {
188
186
override fun handleOnBackPressed () {
189
187
val isFromAddAccount = intent.getBooleanExtra(EXTRA_ALLOW_CLOSE , false )
190
188
191
- val destination: Intent = if (isFromAddAccount) {
192
- 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()
193
195
} else {
194
- Intent (applicationContext, AuthenticatorActivity ::class .java)
195
- }
196
-
197
- if (! isFromAddAccount) {
198
- destination.putExtra(EXTRA_EXIT , true )
196
+ // NMC Customization -> No redirection to AuthenticatorActivity is required
197
+ // just close the app
198
+ finishAffinity()
199
199
}
200
200
201
- destination.flags = Intent .FLAG_ACTIVITY_CLEAR_TOP
202
- startActivity(destination)
203
- finish()
204
201
}
205
202
}
206
203
)
207
204
}
208
205
209
- private fun setSlideshowSize (isLandscape : Boolean ) {
210
- val isProviderOrOwnInstallationVisible = resources.getBoolean(R .bool.show_provider_or_own_installation)
211
- binding.buttonLayout.orientation = if (isLandscape) LinearLayout .HORIZONTAL else LinearLayout .VERTICAL
212
-
213
- val layoutParams: LinearLayout .LayoutParams = if (isProviderOrOwnInstallationVisible) {
214
- LinearLayout .LayoutParams (
215
- ViewGroup .LayoutParams .MATCH_PARENT ,
216
- ViewGroup .LayoutParams .WRAP_CONTENT
217
- )
218
- } else {
219
- @Suppress(" MagicNumber" )
220
- LinearLayout .LayoutParams (
221
- ViewGroup .LayoutParams .MATCH_PARENT ,
222
- DisplayUtils .convertDpToPixel(if (isLandscape) 100f else 150f , this )
223
- )
224
- }
225
-
226
- binding.bottomLayout.layoutParams = layoutParams
227
- }
228
-
229
206
override fun onConfigurationChanged (newConfig : Configuration ) {
230
207
super .onConfigurationChanged(newConfig)
231
- setSlideshowSize(newConfig.orientation == Configuration .ORIENTATION_LANDSCAPE )
208
+ updateLoginButtonMargin()
209
+ updateOnBoardingPager(selectedPosition)
232
210
}
233
211
234
212
private fun onFinish () {
@@ -240,16 +218,24 @@ class FirstRunActivity : BaseActivity(), Injectable {
240
218
super .onStop()
241
219
}
242
220
221
+ override fun onPageScrolled (position : Int , positionOffset : Float , positionOffsetPixels : Int ) {
222
+ // unused but to be implemented due to abstract parent
223
+ }
224
+
225
+ override fun onPageSelected (position : Int ) {
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)
231
+ }
232
+
233
+ override fun onPageScrollStateChanged (state : Int ) {
234
+ // unused but to be implemented due to abstract parent
235
+ }
236
+
243
237
companion object {
244
238
const val EXTRA_ALLOW_CLOSE = " ALLOW_CLOSE"
245
239
const val EXTRA_EXIT = " EXIT"
246
-
247
- val firstRun: Array <FeatureItem >
248
- get() = arrayOf(
249
- FeatureItem (R .drawable.logo, R .string.first_run_1_text, R .string.empty, true , false ),
250
- FeatureItem (R .drawable.first_run_files, R .string.first_run_2_text, R .string.empty, true , false ),
251
- FeatureItem (R .drawable.first_run_groupware, R .string.first_run_3_text, R .string.empty, true , false ),
252
- FeatureItem (R .drawable.first_run_talk, R .string.first_run_4_text, R .string.empty, true , false )
253
- )
254
240
}
255
241
}
0 commit comments