Commit 5f61f4fa authored by Amit Kumar's avatar Amit Kumar 💻
Browse files

Add icons at first empty space always

parent cadd6987
Pipeline #156979 passed with stage
in 9 minutes and 14 seconds
......@@ -57,6 +57,11 @@ public class AppProvider {
*/
List<LauncherItem> mLauncherItems;
/**
* Represents all items including the ones which are added when launcher is not running.
*/
AppsRepository.AllItems allItems;
/**
* Represents networkItems stored in database.
*/
......@@ -207,15 +212,15 @@ public class AppProvider {
private synchronized void handleAllProviderLoaded() {
if (appsLoaded && shortcutsLoaded && databaseLoaded) {
if (mDatabaseItems == null || mDatabaseItems.size() <= 0) {
mLauncherItems = prepareDefaultLauncherItems();
allItems = prepareDefaultLauncherItems();
} else {
mLauncherItems = prepareLauncherItems();
allItems = prepareLauncherItems();
}
mAppsRepository.updateAppsRelay(mLauncherItems);
mAppsRepository.updateAllAppsRelay(allItems);
}
}
private List<LauncherItem> prepareLauncherItems() {
private AppsRepository.AllItems prepareLauncherItems() {
Log.d(TAG, "prepareLauncherItems() called");
/*
......@@ -332,14 +337,15 @@ public class AppProvider {
Log.i(TAG, "prepareLauncherItems: " + mLauncherItem);
}
applicationItems.removeAll(mDatabaseItems);
List<ApplicationItem> mutableList = new ArrayList<>(applicationItems);
List<LauncherItem> mutableList = new ArrayList<>(applicationItems);
mutableList.sort((app1, app2) -> {
Collator collator = Collator.getInstance();
return collator.compare(app1.title.toString(), app2.title.toString());
});
mLauncherItems.addAll(mutableList);
return mLauncherItems;
return new AppsRepository.AllItems(mLauncherItems, mutableList);
}
private boolean isAppOnSdcard(String packageName, UserHandle userHandle) {
......@@ -411,7 +417,7 @@ public class AppProvider {
return shortcutItem;
}
private List<LauncherItem> prepareDefaultLauncherItems() {
private AppsRepository.AllItems prepareDefaultLauncherItems() {
List<LauncherItem> mLauncherItems = new ArrayList<>();
List<LauncherItem> pinnedItems = new ArrayList<>();
PackageManager pm = mContext.getPackageManager();
......@@ -454,7 +460,7 @@ public class AppProvider {
});
mLauncherItems.addAll(pinnedItems);
return mLauncherItems;
return new AppsRepository.AllItems(mLauncherItems, Collections.emptyList());
}
public AppsRepository getAppsRepository() {
......
......@@ -3,17 +3,22 @@ package foundation.e.blisslauncher.features.launcher;
import com.jakewharton.rxrelay2.BehaviorRelay;
import foundation.e.blisslauncher.core.database.model.LauncherItem;
import java.util.List;
public class AppsRepository {
private static final String TAG = "AppsRepository";
@Deprecated
private BehaviorRelay<List<LauncherItem>> appsRelay;
private BehaviorRelay<AllItems> allItems;
private static AppsRepository sAppsRepository;
private AppsRepository() {
appsRelay = BehaviorRelay.create();
allItems = BehaviorRelay.create();
}
public static AppsRepository getAppsRepository() {
......@@ -25,13 +30,43 @@ public class AppsRepository {
public void clearAll(){
appsRelay = BehaviorRelay.create();
allItems = BehaviorRelay.create();
}
public void updateAppsRelay(List<LauncherItem> launcherItems) {
this.appsRelay.accept(launcherItems);
}
public void updateAllAppsRelay(AllItems allItems) {
this.allItems.accept(allItems);
}
public BehaviorRelay<List<LauncherItem>> getAppsRelay() {
return appsRelay;
}
}
public BehaviorRelay<AllItems> getAllItemsRelay() {
return allItems;
}
public static class AllItems {
private final List<LauncherItem> items;
private final List<LauncherItem> newAddedItems;
public AllItems(
List<LauncherItem> items,
List<LauncherItem> newAddedItems
) {
this.items = items;
this.newAddedItems = newAddedItems;
}
public List<LauncherItem> getItems() {
return items;
}
public List<LauncherItem> getNewAddedItems() {
return newAddedItems;
}
}
}
\ No newline at end of file
......@@ -87,6 +87,7 @@ import foundation.e.blisslauncher.core.utils.IntegerArray
import foundation.e.blisslauncher.core.utils.ListUtil
import foundation.e.blisslauncher.core.utils.PackageUserKey
import foundation.e.blisslauncher.core.utils.UserHandle
import foundation.e.blisslauncher.features.launcher.AppsRepository
import foundation.e.blisslauncher.features.launcher.Hotseat
import foundation.e.blisslauncher.features.launcher.SearchInputDisposableObserver
import foundation.e.blisslauncher.features.notification.DotInfo
......@@ -1109,12 +1110,12 @@ class TestActivity : BaseDraggingActivity(), AutoCompleteAdapter.OnSuggestionCli
BlissLauncher.getApplication(this)
.appProvider
.appsRepository
.appsRelay
.allItemsRelay
.distinctUntilChanged()
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(object : DisposableObserver<List<LauncherItem>>() {
override fun onNext(launcherItems: List<LauncherItem>) {
mainHandler.post { showApps(launcherItems) }
.subscribeWith(object : DisposableObserver<AppsRepository.AllItems>() {
override fun onNext(items: AppsRepository.AllItems) {
mainHandler.post { showApps(items) }
}
override fun onError(e: Throwable) {
......@@ -1126,14 +1127,15 @@ class TestActivity : BaseDraggingActivity(), AutoCompleteAdapter.OnSuggestionCli
)
}
private fun showApps(launcherItems: List<LauncherItem>) {
private fun showApps(allItems: AppsRepository.AllItems) {
hotseat.resetLayout(false)
val populatedItems = populateItemPositions(launcherItems)
val populatedItems = populateItemPositions(allItems.items)
val orderedScreenIds = IntegerArray()
orderedScreenIds.addAll(collectWorkspaceScreens(populatedItems))
workspace.removeAllWorkspaceScreens()
workspace.bindScreens(orderedScreenIds)
workspace.bindItems(populatedItems, false)
workspace.bindItemsAdded(allItems.newAddedItems)
}
private fun populateItemPositions(launcherItems: List<LauncherItem>): List<LauncherItem> {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment