From 1565e68be0fd5079260285bf6cc37853fcf0f64b Mon Sep 17 00:00:00 2001 From: A117870935 Date: Tue, 4 Apr 2023 17:18:40 +0530 Subject: [PATCH] Added splash screen. Signed-off-by: Andy Scherzinger --- app/src/main/AndroidManifest.xml | 17 ++++-- .../nextcloud/client/di/ComponentsModule.java | 5 ++ .../java/com/nmc/android/ui/SplashActivity.kt | 60 +++++++++++++++++++ .../owncloud/android/utils/StringUtils.java | 20 +++++++ .../drawable/ic_magentacloud_splash_logo.xml | 16 +++++ app/src/main/res/layout/activity_splash.xml | 37 ++++++++++++ app/src/main/res/values/dimens.xml | 34 +++++++++++ app/src/main/res/values/setup.xml | 2 + app/src/main/res/values/styles.xml | 2 +- 9 files changed, 187 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/com/nmc/android/ui/SplashActivity.kt create mode 100644 app/src/main/res/drawable/ic_magentacloud_splash_logo.xml create mode 100644 app/src/main/res/layout/activity_splash.xml create mode 100644 app/src/main/res/values/dimens.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a3c56aa3fc..afc5b2ed6d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -102,11 +102,6 @@ android:exported="true" android:launchMode="singleTop" android:theme="@style/Theme.ownCloud.Launcher"> - - - - - @@ -492,6 +487,18 @@ android:name="com.nextcloud.client.documentscan.DocumentScanActivity" android:exported="false" android:theme="@style/Theme.ownCloud.Toolbar" /> + + + + + + + + + diff --git a/app/src/main/java/com/nextcloud/client/di/ComponentsModule.java b/app/src/main/java/com/nextcloud/client/di/ComponentsModule.java index 9dd4315b3a..3b8484d6ea 100644 --- a/app/src/main/java/com/nextcloud/client/di/ComponentsModule.java +++ b/app/src/main/java/com/nextcloud/client/di/ComponentsModule.java @@ -36,6 +36,7 @@ import com.nextcloud.client.widget.DashboardWidgetService; import com.nextcloud.ui.ChooseAccountDialogFragment; import com.nextcloud.ui.SetStatusDialogFragment; import com.nextcloud.ui.fileactions.FileActionsBottomSheet; +import com.nmc.android.ui.SplashActivity; import com.owncloud.android.MainApp; import com.owncloud.android.authentication.AuthenticatorActivity; import com.owncloud.android.authentication.DeepLinkLoginActivity; @@ -466,4 +467,8 @@ abstract class ComponentsModule { @ContributesAndroidInjector abstract GroupfolderListFragment groupfolderListFragment(); + + @ContributesAndroidInjector + abstract SplashActivity splashActivity(); + } diff --git a/app/src/main/java/com/nmc/android/ui/SplashActivity.kt b/app/src/main/java/com/nmc/android/ui/SplashActivity.kt new file mode 100644 index 0000000000..fc3a333cfd --- /dev/null +++ b/app/src/main/java/com/nmc/android/ui/SplashActivity.kt @@ -0,0 +1,60 @@ +package com.nmc.android.ui + +import android.content.Intent +import android.os.Bundle +import android.os.Handler +import com.nextcloud.client.preferences.AppPreferences +import com.owncloud.android.R +import com.owncloud.android.authentication.AuthenticatorActivity +import com.owncloud.android.databinding.ActivitySplashBinding +import com.owncloud.android.ui.activity.BaseActivity +import com.owncloud.android.ui.activity.FileDisplayActivity +import com.owncloud.android.utils.StringUtils +import javax.inject.Inject + +class SplashActivity : BaseActivity() { + + companion object { + const val SPLASH_DURATION = 1500L + } + + private lateinit var binding : ActivitySplashBinding + + @Inject + lateinit var appPreferences: AppPreferences + + override fun onCreate(savedInstanceState: Bundle?) { + //flag to avoid redirection to AuthenticatorActivity + //as we need this activity to be shown + //Note: Should be kept before super() method + enableAccountHandling = false + super.onCreate(savedInstanceState) + + binding = ActivitySplashBinding.inflate(layoutInflater) + + setContentView(binding.root) + setSplashTitle() + scheduleSplashScreen() + } + + private fun setSplashTitle() { + val appName = resources.getString(R.string.app_name) + val textToBold = resources.getString(R.string.project_name) + binding.tvSplash.text = StringUtils.makeTextBold(appName, textToBold) + } + + private fun scheduleSplashScreen() { + Handler().postDelayed( + { + //if user is null then go to authenticator activity + if (!user.isPresent) { + startActivity(Intent(this, AuthenticatorActivity::class.java)) + } else { + startActivity(Intent(this, FileDisplayActivity::class.java)) + } + finish() + }, + SPLASH_DURATION + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/owncloud/android/utils/StringUtils.java b/app/src/main/java/com/owncloud/android/utils/StringUtils.java index 5c6871dcab..6ef498cdd3 100644 --- a/app/src/main/java/com/owncloud/android/utils/StringUtils.java +++ b/app/src/main/java/com/owncloud/android/utils/StringUtils.java @@ -21,6 +21,11 @@ package com.owncloud.android.utils; +import android.graphics.Typeface; +import android.text.Spannable; +import android.text.SpannableString; +import android.text.style.StyleSpan; + import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -77,4 +82,19 @@ public final class StringUtils { } return s; } + + /** + * make the passed text bold + * + * @param fullText actual text + * @param textToBold to be bold + * @return + */ + public static Spannable makeTextBold(String fullText, String textToBold) { + Spannable spannable = new SpannableString(fullText); + int indexStart = fullText.indexOf(textToBold); + int indexEnd = indexStart + textToBold.length(); + spannable.setSpan(new StyleSpan(Typeface.BOLD), indexStart, indexEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + return spannable; + } } diff --git a/app/src/main/res/drawable/ic_magentacloud_splash_logo.xml b/app/src/main/res/drawable/ic_magentacloud_splash_logo.xml new file mode 100644 index 0000000000..0abbc5ab08 --- /dev/null +++ b/app/src/main/res/drawable/ic_magentacloud_splash_logo.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_splash.xml b/app/src/main/res/layout/activity_splash.xml new file mode 100644 index 0000000000..cc28d729d3 --- /dev/null +++ b/app/src/main/res/layout/activity_splash.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000000..7c23544141 --- /dev/null +++ b/app/src/main/res/values/dimens.xml @@ -0,0 +1,34 @@ + + + 116dp + 4dp + 16dp + 24dp + 6dp + 14sp + 16sp + 18sp + 15sp + 15dp + 56dp + 86dp + 80dp + 11sp + 30dp + 55dp + 258dp + 17sp + 20dp + 160dp + 50dp + 150dp + 55dp + 48dp + 48dp + 24dp + 26dp + 20sp + 145dp + 1dp + 13sp + \ No newline at end of file diff --git a/app/src/main/res/values/setup.xml b/app/src/main/res/values/setup.xml index 71521eee85..b13a9141b5 100644 --- a/app/src/main/res/values/setup.xml +++ b/app/src/main/res/values/setup.xml @@ -6,6 +6,8 @@ Nextcloud + + Next nextcloud org.nextcloud com.nextcloud.android.providers.UsersAndGroupsSearchProvider diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index c95797f2b6..6980c58b47 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -284,7 +284,7 @@