]> git.ktnx.net Git - mobile-ledger.git/commitdiff
add splash on startup
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 5 Jul 2020 16:40:57 +0000 (19:40 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 5 Jul 2020 20:27:29 +0000 (20:27 +0000)
use the small delay to prepare as much as possible

there's still a bit of a flicker, so this needs more work to make it smooth

app/src/main/AndroidManifest.xml
app/src/main/java/net/ktnx/mobileledger/App.java
app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/SplashActivity.java [new file with mode: 0644]
app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListAdapter.java
app/src/main/res/layout/splash_activity_layout.xml [new file with mode: 0644]
app/src/main/res/values/strings.xml

index 85a211ef8b3b038fda23684c6777c23e253108fe..6a0c670981f9e581665bcd80b6301adc75f442b0 100644 (file)
         android:networkSecurityConfig="@xml/network_security_config"
         tools:ignore="GoogleAppIndexingWarning">
         <activity
         android:networkSecurityConfig="@xml/network_security_config"
         tools:ignore="GoogleAppIndexingWarning">
         <activity
-            android:name=".ui.activity.MainActivity"
+            android:name=".ui.activity.SplashActivity"
             android:label="@string/app_name">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
             android:label="@string/app_name">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
+        <activity
+            android:name=".ui.activity.MainActivity"
+            android:label="@string/app_name"></activity>
         <activity
             android:name=".ui.activity.NewTransactionActivity"
             android:label="@string/title_activity_new_transaction"
         <activity
             android:name=".ui.activity.NewTransactionActivity"
             android:label="@string/title_activity_new_transaction"
-            android:parentActivityName=".ui.activity.MainActivity">
-        </activity>
+            android:parentActivityName=".ui.activity.MainActivity"></activity>
         <activity
             android:name=".ui.activity.ProfileDetailActivity"
             android:label="@string/title_profile_details"
         <activity
             android:name=".ui.activity.ProfileDetailActivity"
             android:label="@string/title_profile_details"
index d6b1ffaf7afc784ebd41ccb5a1227bf2e1bb47ac..68f1b9c43c1e14f6f999c9edbfcf832839d539ce 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright © 2019 Damyan Ivanov.
+ * Copyright © 2020 Damyan Ivanov.
  * This file is part of MoLe.
  * MoLe is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
  * This file is part of MoLe.
  * MoLe is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
@@ -38,6 +38,7 @@ import java.util.Locale;
 public class App extends Application {
     public static App instance;
     private MobileLedgerDatabase dbHelper;
 public class App extends Application {
     public static App instance;
     private MobileLedgerDatabase dbHelper;
+    private boolean monthNamesPrepared = false;
     public static SQLiteDatabase getDatabase() {
         if (instance == null) throw new RuntimeException("Application not created yet");
 
     public static SQLiteDatabase getDatabase() {
         if (instance == null) throw new RuntimeException("Application not created yet");
 
@@ -48,7 +49,6 @@ public class App extends Application {
         Logger.debug("flow", "App onCreate()");
         instance = this;
         super.onCreate();
         Logger.debug("flow", "App onCreate()");
         instance = this;
         super.onCreate();
-        updateMonthNames();
         Data.refreshCurrencyData(Locale.getDefault());
         Authenticator.setDefault(new Authenticator() {
             @Override
         Data.refreshCurrencyData(Locale.getDefault());
         Authenticator.setDefault(new Authenticator() {
             @Override
@@ -75,20 +75,27 @@ public class App extends Application {
             }
         });
     }
             }
         });
     }
-    private void updateMonthNames() {
+    public static void prepareMonthNames() {
+        instance.prepareMonthNames(false);
+    }
+    private void prepareMonthNames(boolean force) {
+        if (force || monthNamesPrepared)
+            return;
         Resources rm = getResources();
         Globals.monthNames = rm.getStringArray(R.array.month_names);
         Resources rm = getResources();
         Globals.monthNames = rm.getStringArray(R.array.month_names);
+        monthNamesPrepared = true;
     }
     @Override
     public void onTerminate() {
         Logger.debug("flow", "App onTerminate()");
     }
     @Override
     public void onTerminate() {
         Logger.debug("flow", "App onTerminate()");
-        if (dbHelper != null) dbHelper.close();
+        if (dbHelper != null)
+            dbHelper.close();
         super.onTerminate();
     }
     @Override
     public void onConfigurationChanged(Configuration newConfig) {
         super.onConfigurationChanged(newConfig);
         super.onTerminate();
     }
     @Override
     public void onConfigurationChanged(Configuration newConfig) {
         super.onConfigurationChanged(newConfig);
-        updateMonthNames();
+        prepareMonthNames(true);
         Data.refreshCurrencyData(Locale.getDefault());
         Data.locale.setValue(Locale.getDefault());
     }
         Data.refreshCurrencyData(Locale.getDefault());
         Data.locale.setValue(Locale.getDefault());
     }
index 32122c6cd32b55e967e525f05461cd5a4d0940e0..21d658656632292d2e8d4aeee54e9709cb03bd88 100644 (file)
@@ -86,7 +86,7 @@ public final class MobileLedgerProfile {
     }
     // loads all profiles into Data.profiles
     // returns the profile with the given UUID
     }
     // loads all profiles into Data.profiles
     // returns the profile with the given UUID
-    public static MobileLedgerProfile loadAllFromDB(String currentProfileUUID) {
+    public static MobileLedgerProfile loadAllFromDB(@Nullable String currentProfileUUID) {
         MobileLedgerProfile result = null;
         ArrayList<MobileLedgerProfile> list = new ArrayList<>();
         SQLiteDatabase db = App.getDatabase();
         MobileLedgerProfile result = null;
         ArrayList<MobileLedgerProfile> list = new ArrayList<>();
         SQLiteDatabase db = App.getDatabase();
index cad021770fa25866bb17b1705a527606c0d30504..3cf5aa24edb93ee228e61ed0897c30936fb4c6d8 100644 (file)
@@ -69,6 +69,7 @@ import net.ktnx.mobileledger.ui.transaction_list.TransactionListViewModel;
 import net.ktnx.mobileledger.utils.Colors;
 import net.ktnx.mobileledger.utils.GetOptCallback;
 import net.ktnx.mobileledger.utils.LockHolder;
 import net.ktnx.mobileledger.utils.Colors;
 import net.ktnx.mobileledger.utils.GetOptCallback;
 import net.ktnx.mobileledger.utils.LockHolder;
+import net.ktnx.mobileledger.utils.Logger;
 import net.ktnx.mobileledger.utils.MLDB;
 
 import org.jetbrains.annotations.NotNull;
 import net.ktnx.mobileledger.utils.MLDB;
 
 import org.jetbrains.annotations.NotNull;
@@ -109,6 +110,8 @@ public class MainActivity extends ProfileThemedActivity {
     protected void onStart() {
         super.onStart();
 
     protected void onStart() {
         super.onStart();
 
+        Logger.debug("MainActivity", "onStart()");
+
         mViewPager.setCurrentItem(mCurrentPage, false);
     }
     @Override
         mViewPager.setCurrentItem(mCurrentPage, false);
     }
     @Override
@@ -152,8 +155,9 @@ public class MainActivity extends ProfileThemedActivity {
     }
     @Override
     protected void onCreate(Bundle savedInstanceState) {
     }
     @Override
     protected void onCreate(Bundle savedInstanceState) {
+        debug("MainActivity", "onCreate()/entry");
         super.onCreate(savedInstanceState);
         super.onCreate(savedInstanceState);
-        debug("flow", "MainActivity.onCreate()");
+        debug("MainActivity", "onCreate()/after super");
         setContentView(R.layout.activity_main);
 
         fab = findViewById(R.id.btn_add_transaction);
         setContentView(R.layout.activity_main);
 
         fab = findViewById(R.id.btn_add_transaction);
diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/SplashActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/SplashActivity.java
new file mode 100644 (file)
index 0000000..32b71d6
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright © 2020 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.ui.activity;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Handler;
+
+import androidx.annotation.Nullable;
+
+import net.ktnx.mobileledger.R;
+import net.ktnx.mobileledger.model.Data;
+import net.ktnx.mobileledger.model.MobileLedgerProfile;
+import net.ktnx.mobileledger.utils.MLDB;
+
+public class SplashActivity extends Activity {
+    @Override
+    protected void onCreate(@Nullable Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setTheme(R.style.AppTheme_default);
+        setContentView(R.layout.splash_activity_layout);
+    }
+    @Override
+    protected void onStart() {
+        super.onStart();
+
+        MobileLedgerProfile.loadAllFromDB(null);
+
+        String profileUUID = MLDB.getOption(MLDB.OPT_PROFILE_UUID, null);
+        MobileLedgerProfile startupProfile = Data.getProfile(profileUUID);
+        if (startupProfile != null)
+            Data.setCurrentProfile(startupProfile);
+
+        new Handler().postDelayed(() -> {
+            Intent intent = new Intent(this, MainActivity.class);
+            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION |
+                            Intent.FLAG_ACTIVITY_NEW_TASK);
+            startActivity(intent);
+            overridePendingTransition(R.anim.fade_in, R.anim.dummy);
+        }, 250);
+    }
+}
index 96de4b64a017501b4e7a842717e41def70768119..6179174f12e574fefe0f28113544bf5ad6770b87 100644 (file)
@@ -93,6 +93,7 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionRowH
                 if (item.isMonthShown()) {
                     GregorianCalendar cal = new GregorianCalendar(TimeZone.getDefault());
                     cal.setTime(date.toDate());
                 if (item.isMonthShown()) {
                     GregorianCalendar cal = new GregorianCalendar(TimeZone.getDefault());
                     cal.setTime(date.toDate());
+                    App.prepareMonthNames();
                     holder.tvDelimiterMonth.setText(
                             Globals.monthNames[cal.get(GregorianCalendar.MONTH)]);
                     holder.tvDelimiterMonth.setVisibility(View.VISIBLE);
                     holder.tvDelimiterMonth.setText(
                             Globals.monthNames[cal.get(GregorianCalendar.MONTH)]);
                     holder.tvDelimiterMonth.setVisibility(View.VISIBLE);
diff --git a/app/src/main/res/layout/splash_activity_layout.xml b/app/src/main/res/layout/splash_activity_layout.xml
new file mode 100644 (file)
index 0000000..69947d2
--- /dev/null
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+  ~ Copyright © 2020 Damyan Ivanov.
+  ~ This file is part of MoLe.
+  ~ MoLe is free software: you can distribute it and/or modify it
+  ~ under the term of the GNU General Public License as published by
+  ~ the Free Software Foundation, either version 3 of the License, or
+  ~ (at your opinion), any later version.
+  ~
+  ~ MoLe is distributed in the hope that it will be useful,
+  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+  ~ GNU General Public License terms for details.
+  ~
+  ~ You should have received a copy of the GNU General Public License
+  ~ along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+  -->
+
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:background="?colorPrimary"
+    >
+
+    <ImageView
+        android:id="@+id/icon"
+        android:layout_width="@android:dimen/thumbnail_width"
+        android:layout_height="@android:dimen/thumbnail_height"
+        android:contentDescription="@string/splash_icon_description"
+        android:src="@drawable/app_icon_transparent_bg"
+        android:tint="@android:color/white"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent"
+        app:srcCompat="@drawable/app_icon_transparent_bg"
+        />
+</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
index 715486a9ae065b248142750f5825361c134c0e1a..b12fff86fb27c3d665ed3323cce264709cbac098 100644 (file)
     <string name="show_comment_input_by_default">Show comment fields by default</string>
     <string name="filter_menu_title">Filter</string>
     <string name="go_to_date_menu_title">Go to date</string>
     <string name="show_comment_input_by_default">Show comment fields by default</string>
     <string name="filter_menu_title">Filter</string>
     <string name="go_to_date_menu_title">Go to date</string>
+    <string name="splash_icon_description">Main app icon</string>
 </resources>
 </resources>