Use MainActivity as a single instance to open item on sync result notification click

This commit is contained in:
Shinokuni 2020-03-08 22:09:24 +01:00
parent b2a51825e2
commit 1b99d93739
4 changed files with 27 additions and 9 deletions

View File

@ -59,6 +59,7 @@
<activity
android:name=".activities.MainActivity"
android:label="@string/articles"
android:launchMode="singleTask"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activities.ItemActivity"
@ -67,7 +68,6 @@
<activity
android:name=".activities.AddFeedActivity"
android:label="@string/add_feed_title"
android:launchMode="singleTop"
android:parentActivityName=".activities.MainActivity">
<intent-filter android:label="@string/new_feed">
<action android:name="android.intent.action.SEND" />

View File

@ -225,15 +225,25 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
savedInstanceState.clear();
}
});
if (getIntent().hasExtra(ITEM_ID) && getIntent().hasExtra(IMAGE_URL)) {
Intent intent = new Intent(this, ItemActivity.class);
intent.putExtras(getIntent());
startActivity(intent);
}
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (intent.hasExtra(ITEM_ID) && intent.hasExtra(IMAGE_URL)) {
Intent itemIntent = new Intent(this, ItemActivity.class);
itemIntent.putExtras(intent);
startActivity(itemIntent);
viewModel.setItemReadState(intent.getIntExtra(ITEM_ID, 0), true, true)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnError(throwable -> Utils.showSnackbar(rootLayout, throwable.getMessage()))
.subscribe();
}
}
private void handleDrawerClick(IDrawerItem drawerItem) {
if (drawerItem instanceof PrimaryDrawerItem) {

View File

@ -109,7 +109,11 @@ public abstract class ARepository<T> {
}
public Completable setItemReadState(Item item, boolean read) {
return database.itemDao().setReadState(item.getId(), read, !item.isReadChanged());
return setItemReadState(item.getId(), read, !item.isReadChanged());
}
public Completable setItemReadState(int itemId, boolean read, boolean readChanged) {
return database.itemDao().setReadState(itemId, read, readChanged);
}
public Completable setAllItemsReadState(boolean read) {

View File

@ -219,6 +219,10 @@ public class MainViewModel extends AndroidViewModel {
return repository.setItemReadState(itemWithFeed.getItem(), read);
}
public Completable setItemReadState(int itemId, boolean read, boolean readChanged) {
return repository.setItemReadState(itemId, read, readChanged);
}
public Completable setItemsReadState(List<ItemWithFeed> items, boolean read) {
List<Completable> completableList = new ArrayList<>();