Set the current account at the top of the list in Add Feed Activity

This commit is contained in:
Shinokuni 2020-07-11 16:09:19 +02:00
parent a8764e91f5
commit cad3b6f59b
2 changed files with 17 additions and 2 deletions

View File

@ -25,8 +25,6 @@ import com.mikepenz.fastadapter.commons.utils.DiffCallback;
import com.mikepenz.fastadapter.commons.utils.FastAdapterDiffUtil;
import com.readrops.app.R;
import com.readrops.app.adapters.AccountArrayAdapter;
import com.readrops.readropsdb.entities.Feed;
import com.readrops.readropsdb.entities.account.Account;
import com.readrops.app.databinding.ActivityAddFeedBinding;
import com.readrops.app.utils.FeedInsertionResult;
import com.readrops.app.utils.ParsingResult;
@ -34,14 +32,18 @@ import com.readrops.app.utils.ReadropsItemTouchCallback;
import com.readrops.app.utils.SharedPreferencesManager;
import com.readrops.app.utils.Utils;
import com.readrops.app.viewmodels.AddFeedsViewModel;
import com.readrops.readropsdb.entities.Feed;
import com.readrops.readropsdb.entities.account.Account;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.observers.DisposableSingleObserver;
import io.reactivex.schedulers.Schedulers;
import static com.readrops.app.utils.ReadropsKeys.ACCOUNT_ID;
import static com.readrops.app.utils.ReadropsKeys.FEEDS;
public class AddFeedActivity extends AppCompatActivity implements View.OnClickListener {
@ -125,6 +127,18 @@ public class AddFeedActivity extends AppCompatActivity implements View.OnClickLi
binding.addFeedInsertedResultsRecyclerview.setLayoutManager(layoutManager1);
viewModel.getAccounts().observe(this, accounts -> {
// set the current account at the top of the list
int currentAccountId = getIntent().getIntExtra(ACCOUNT_ID, 1);
Collections.sort(accounts, (o1, o2) -> {
if (o1.getId() == currentAccountId) {
return -1;
} else if (o2.getId() == currentAccountId) {
return 1;
} else {
return 0;
}
});
arrayAdapter = new AccountArrayAdapter(this, accounts);
arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

View File

@ -554,6 +554,7 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
public void openAddFeedActivity(View view) {
Intent intent = new Intent(this, AddFeedActivity.class);
intent.putExtra(ACCOUNT_ID, viewModel.getCurrentAccount().getId());
startActivityForResult(intent, ADD_FEED_REQUEST);
}