Display a splash screen when the app starts.

This commit is contained in:
Alex Ning 2019-09-03 14:37:20 +08:00
parent 870b217174
commit 79726b9a08
15 changed files with 48 additions and 12 deletions

View File

@ -144,7 +144,7 @@
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBarWithTransparentStatusBar"> android:theme="@style/AppTheme.Launcher">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />

View File

@ -157,6 +157,8 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.AppTheme_NoActionBarWithTransparentStatusBar);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);

View File

@ -78,7 +78,7 @@ class PostDataSourceFactory extends DataSource.Factory {
@NonNull @NonNull
@Override @Override
public DataSource create() { public DataSource<String, Post> create() {
if(postType == PostDataSource.TYPE_FRONT_PAGE) { if(postType == PostDataSource.TYPE_FRONT_PAGE) {
postDataSource = new PostDataSource(retrofit, accessToken, locale, postType, sortType, postDataSource = new PostDataSource(retrofit, accessToken, locale, postType, sortType,
filter, nsfw); filter, nsfw);

View File

@ -450,10 +450,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
stopLazyMode(); stopLazyMode();
} }
mAdapter.setNetworkState(null);
mFetchPostInfoLinearLayout.setVisibility(View.GONE); mFetchPostInfoLinearLayout.setVisibility(View.GONE);
hasPost = false; hasPost = false;
mPostViewModel.refresh(); mPostViewModel.refresh();
mAdapter.setNetworkState(null);
} }
private void showErrorView(int stringResId) { private void showErrorView(int stringResId) {

View File

@ -23,7 +23,7 @@ public class PostViewModel extends ViewModel {
private LiveData<PagedList<Post>> posts; private LiveData<PagedList<Post>> posts;
private MutableLiveData<Boolean> nsfwLiveData; private MutableLiveData<Boolean> nsfwLiveData;
private MutableLiveData<String> sortTypeLiveData; private MutableLiveData<String> sortTypeLiveData;
private PostViewModel.NSFWAndSortTypeLiveData NSFWAndSortTypeLiveData; private NSFWAndSortTypeLiveData nsfwAndSortTypeLiveData;
public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, int postType, String sortType, public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, int postType, String sortType,
int filter, boolean nsfw) { int filter, boolean nsfw) {
@ -42,7 +42,7 @@ public class PostViewModel extends ViewModel {
sortTypeLiveData = new MutableLiveData<>(); sortTypeLiveData = new MutableLiveData<>();
sortTypeLiveData.postValue(sortType); sortTypeLiveData.postValue(sortType);
NSFWAndSortTypeLiveData = new NSFWAndSortTypeLiveData(nsfwLiveData, sortTypeLiveData); nsfwAndSortTypeLiveData = new NSFWAndSortTypeLiveData(nsfwLiveData, sortTypeLiveData);
PagedList.Config pagedListConfig = PagedList.Config pagedListConfig =
(new PagedList.Config.Builder()) (new PagedList.Config.Builder())
@ -50,7 +50,7 @@ public class PostViewModel extends ViewModel {
.setPageSize(25) .setPageSize(25)
.build(); .build();
posts = Transformations.switchMap(NSFWAndSortTypeLiveData, nsfwAndSort -> { posts = Transformations.switchMap(nsfwAndSortTypeLiveData, nsfwAndSort -> {
postDataSourceFactory.changeNSFWAndSortType(nsfwLiveData.getValue(), sortTypeLiveData.getValue()); postDataSourceFactory.changeNSFWAndSortType(nsfwLiveData.getValue(), sortTypeLiveData.getValue());
return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build(); return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
}); });
@ -73,7 +73,7 @@ public class PostViewModel extends ViewModel {
sortTypeLiveData = new MutableLiveData<>(); sortTypeLiveData = new MutableLiveData<>();
sortTypeLiveData.postValue(sortType); sortTypeLiveData.postValue(sortType);
NSFWAndSortTypeLiveData = new NSFWAndSortTypeLiveData(nsfwLiveData, sortTypeLiveData); nsfwAndSortTypeLiveData = new NSFWAndSortTypeLiveData(nsfwLiveData, sortTypeLiveData);
PagedList.Config pagedListConfig = PagedList.Config pagedListConfig =
(new PagedList.Config.Builder()) (new PagedList.Config.Builder())
@ -81,7 +81,7 @@ public class PostViewModel extends ViewModel {
.setPageSize(25) .setPageSize(25)
.build(); .build();
posts = Transformations.switchMap(NSFWAndSortTypeLiveData, nsfwAndSort -> { posts = Transformations.switchMap(nsfwAndSortTypeLiveData, nsfwAndSort -> {
postDataSourceFactory.changeNSFWAndSortType(nsfwLiveData.getValue(), sortTypeLiveData.getValue()); postDataSourceFactory.changeNSFWAndSortType(nsfwLiveData.getValue(), sortTypeLiveData.getValue());
return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build(); return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
}); });
@ -104,7 +104,7 @@ public class PostViewModel extends ViewModel {
sortTypeLiveData = new MutableLiveData<>(); sortTypeLiveData = new MutableLiveData<>();
sortTypeLiveData.postValue(sortType); sortTypeLiveData.postValue(sortType);
NSFWAndSortTypeLiveData = new NSFWAndSortTypeLiveData(nsfwLiveData, sortTypeLiveData); nsfwAndSortTypeLiveData = new NSFWAndSortTypeLiveData(nsfwLiveData, sortTypeLiveData);
PagedList.Config pagedListConfig = PagedList.Config pagedListConfig =
(new PagedList.Config.Builder()) (new PagedList.Config.Builder())
@ -112,7 +112,7 @@ public class PostViewModel extends ViewModel {
.setPageSize(25) .setPageSize(25)
.build(); .build();
posts = Transformations.switchMap(NSFWAndSortTypeLiveData, nsfwAndSort -> { posts = Transformations.switchMap(nsfwAndSortTypeLiveData, nsfwAndSort -> {
postDataSourceFactory.changeNSFWAndSortType(nsfwLiveData.getValue(), sortTypeLiveData.getValue()); postDataSourceFactory.changeNSFWAndSortType(nsfwLiveData.getValue(), sortTypeLiveData.getValue());
return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build(); return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
}); });
@ -135,7 +135,7 @@ public class PostViewModel extends ViewModel {
sortTypeLiveData = new MutableLiveData<>(); sortTypeLiveData = new MutableLiveData<>();
sortTypeLiveData.postValue(sortType); sortTypeLiveData.postValue(sortType);
NSFWAndSortTypeLiveData = new NSFWAndSortTypeLiveData(nsfwLiveData, sortTypeLiveData); nsfwAndSortTypeLiveData = new NSFWAndSortTypeLiveData(nsfwLiveData, sortTypeLiveData);
PagedList.Config pagedListConfig = PagedList.Config pagedListConfig =
(new PagedList.Config.Builder()) (new PagedList.Config.Builder())
@ -143,7 +143,7 @@ public class PostViewModel extends ViewModel {
.setPageSize(25) .setPageSize(25)
.build(); .build();
posts = Transformations.switchMap(NSFWAndSortTypeLiveData, nsfwAndSort -> { posts = Transformations.switchMap(nsfwAndSortTypeLiveData, nsfwAndSort -> {
postDataSourceFactory.changeNSFWAndSortType(nsfwLiveData.getValue(), sortTypeLiveData.getValue()); postDataSourceFactory.changeNSFWAndSortType(nsfwLiveData.getValue(), sortTypeLiveData.getValue());
return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build(); return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
}); });

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
<item android:drawable="@color/backgroundColor" />
<item>
<bitmap
android:src="@drawable/splash_icon"
android:gravity="center" />
</item>
</layer-list>

View File

@ -0,0 +1,8 @@
<resources>
<style name="AppTheme.Launcher" parent="@style/AppTheme.NoActionBarWithTransparentStatusBar">
<item name="android:windowBackground">@drawable/splash_screen</item>
<item name="android:navigationBarColor">@color/navBarColor</item>
</style>
</resources>

View File

@ -0,0 +1,10 @@
<resources>
<style name="AppTheme.Launcher" parent="@style/AppTheme.NoActionBarWithTransparentStatusBar">
<item name="android:windowBackground">@drawable/splash_screen</item>
<item name="android:navigationBarColor">@color/navBarColor</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:windowLightNavigationBar">true</item>
</style>
</resources>

View File

@ -10,6 +10,10 @@
<item name="android:textColorPrimary">@android:color/white</item> <item name="android:textColorPrimary">@android:color/white</item>
</style> </style>
<style name="AppTheme.Launcher" parent="@style/AppTheme.NoActionBarWithTransparentStatusBar">
<item name="android:windowBackground">@drawable/splash_screen</item>
</style>
<style name="AppTheme.NoActionBar"> <style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item> <item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item> <item name="windowNoTitle">true</item>