Add splash activity

This commit is contained in:
Shinokuni 2019-05-22 11:16:11 +02:00
parent 86a6daaf5b
commit 4df3087691
8 changed files with 96 additions and 5 deletions

View File

@ -16,22 +16,23 @@
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
android:usesCleartextTraffic="true" android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning"> tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".activities.AccountTypeListActivity"> <activity
android:name=".activities.SplashActivity"
android:theme="@style/SplashTheme">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".activities.AddAccountActivity"> <activity android:name=".activities.AccountTypeListActivity" />
<activity android:name=".activities.AddAccountActivity" />
</activity>
<activity <activity
android:name=".activities.ManageFeedsActivity" android:name=".activities.ManageFeedsActivity"
android:parentActivityName=".activities.MainActivity" /> android:parentActivityName=".activities.MainActivity" />
<activity <activity
android:name=".activities.MainActivity" android:name=".activities.MainActivity"
android:theme="@style/AppTheme.NoActionBar"></activity> android:theme="@style/AppTheme.NoActionBar" />
<activity <activity
android:name=".activities.ItemActivity" android:name=".activities.ItemActivity"
android:parentActivityName=".activities.MainActivity" android:parentActivityName=".activities.MainActivity"

View File

@ -0,0 +1,52 @@
package com.readrops.app.activities;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProviders;
import com.readrops.app.R;
import com.readrops.app.viewmodels.AccountViewModel;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.observers.DisposableSingleObserver;
import io.reactivex.schedulers.Schedulers;
public class SplashActivity extends AppCompatActivity {
private AccountViewModel viewModel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
viewModel = ViewModelProviders.of(this).get(AccountViewModel.class);
viewModel.getAccountCount()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new DisposableSingleObserver<Integer>() {
@Override
public void onSuccess(Integer count) {
if (count > 0) {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
finish();
} else {
Intent intent = new Intent(getApplicationContext(), AccountTypeListActivity.class);
startActivity(intent);
finish();
}
}
@Override
public void onError(Throwable e) {
Toast.makeText(SplashActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
}

View File

@ -29,4 +29,10 @@ public interface AccountDao {
@Query("Update Account set current_account = 0 Where id Not In (:accountId)") @Query("Update Account set current_account = 0 Where id Not In (:accountId)")
void setCurrentAccountsToFalse(int accountId); void setCurrentAccountsToFalse(int accountId);
@Query("Select count(*) From Account Where account_type = :accounType")
Integer getAccountCountByType(int accounType);
@Query("Select count(*) From Account")
Integer getAccountCount();
} }

View File

@ -35,4 +35,12 @@ public class AccountViewModel extends AndroidViewModel {
}); });
} }
public Single<Integer> getAccountCountByAccountType(int accountTypeCode) {
return Single.create(emitter -> emitter.onSuccess(database.accountDao().getAccountCountByType(accountTypeCode)));
}
public Single<Integer> getAccountCount() {
return Single.create(emitter -> emitter.onSuccess(database.accountDao().getAccountCount()));
}
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/colorPrimary" />
<item android:gravity="center">
<bitmap
android:gravity="fill_horizontal|fill_vertical"
android:src="@drawable/logo" />
</item>
</layer-list>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.SplashActivity">
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -17,6 +17,10 @@
<item name="windowActionModeOverlay">true</item> <item name="windowActionModeOverlay">true</item>
</style> </style>
<style name="SplashTheme" parent="AppTheme.NoActionBar">
<item name="android:windowBackground">@drawable/splash_background</item>
</style>
<style name="TextAppearance.Design.CollapsingToolbar.Expanded.Custom" parent="TextAppearance.Design.CollapsingToolbar.Expanded"> <style name="TextAppearance.Design.CollapsingToolbar.Expanded.Custom" parent="TextAppearance.Design.CollapsingToolbar.Expanded">
<item name="android:textSize">12sp</item> <item name="android:textSize">12sp</item>
<item name="android:color">@color/colorBackground</item> <item name="android:color">@color/colorBackground</item>