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 { ...@@ -57,6 +57,11 @@ public class AppProvider {
*/ */
List<LauncherItem> mLauncherItems; 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. * Represents networkItems stored in database.
*/ */
...@@ -207,15 +212,15 @@ public class AppProvider { ...@@ -207,15 +212,15 @@ public class AppProvider {
private synchronized void handleAllProviderLoaded() { private synchronized void handleAllProviderLoaded() {
if (appsLoaded && shortcutsLoaded && databaseLoaded) { if (appsLoaded && shortcutsLoaded && databaseLoaded) {
if (mDatabaseItems == null || mDatabaseItems.size() <= 0) { if (mDatabaseItems == null || mDatabaseItems.size() <= 0) {
mLauncherItems = prepareDefaultLauncherItems(); allItems = prepareDefaultLauncherItems();
} else { } else {
mLauncherItems = prepareLauncherItems(); allItems = prepareLauncherItems();
} }
mAppsRepository.updateAppsRelay(mLauncherItems); mAppsRepository.updateAllAppsRelay(allItems);
} }
} }
private List<LauncherItem> prepareLauncherItems() { private AppsRepository.AllItems prepareLauncherItems() {
Log.d(TAG, "prepareLauncherItems() called"); Log.d(TAG, "prepareLauncherItems() called");
/* /*
...@@ -332,14 +337,15 @@ public class AppProvider { ...@@ -332,14 +337,15 @@ public class AppProvider {
Log.i(TAG, "prepareLauncherItems: " + mLauncherItem); Log.i(TAG, "prepareLauncherItems: " + mLauncherItem);
} }
applicationItems.removeAll(mDatabaseItems); applicationItems.removeAll(mDatabaseItems);
List<ApplicationItem> mutableList = new ArrayList<>(applicationItems); List<LauncherItem> mutableList = new ArrayList<>(applicationItems);
mutableList.sort((app1, app2) -> { mutableList.sort((app1, app2) -> {
Collator collator = Collator.getInstance(); Collator collator = Collator.getInstance();
return collator.compare(app1.title.toString(), app2.title.toString()); 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) { private boolean isAppOnSdcard(String packageName, UserHandle userHandle) {
...@@ -411,7 +417,7 @@ public class AppProvider { ...@@ -411,7 +417,7 @@ public class AppProvider {
return shortcutItem; return shortcutItem;
} }
private List<LauncherItem> prepareDefaultLauncherItems() { private AppsRepository.AllItems prepareDefaultLauncherItems() {
List<LauncherItem> mLauncherItems = new ArrayList<>(); List<LauncherItem> mLauncherItems = new ArrayList<>();
List<LauncherItem> pinnedItems = new ArrayList<>(); List<LauncherItem> pinnedItems = new ArrayList<>();
PackageManager pm = mContext.getPackageManager(); PackageManager pm = mContext.getPackageManager();
...@@ -454,7 +460,7 @@ public class AppProvider { ...@@ -454,7 +460,7 @@ public class AppProvider {
}); });
mLauncherItems.addAll(pinnedItems); mLauncherItems.addAll(pinnedItems);
return mLauncherItems; return new AppsRepository.AllItems(mLauncherItems, Collections.emptyList());
} }
public AppsRepository getAppsRepository() { public AppsRepository getAppsRepository() {
......
...@@ -3,17 +3,22 @@ package foundation.e.blisslauncher.features.launcher; ...@@ -3,17 +3,22 @@ package foundation.e.blisslauncher.features.launcher;
import com.jakewharton.rxrelay2.BehaviorRelay; import com.jakewharton.rxrelay2.BehaviorRelay;
import foundation.e.blisslauncher.core.database.model.LauncherItem; import foundation.e.blisslauncher.core.database.model.LauncherItem;
import java.util.List; import java.util.List;
public class AppsRepository { public class AppsRepository {
private static final String TAG = "AppsRepository"; private static final String TAG = "AppsRepository";
@Deprecated
private BehaviorRelay<List<LauncherItem>> appsRelay; private BehaviorRelay<List<LauncherItem>> appsRelay;
private BehaviorRelay<AllItems> allItems;
private static AppsRepository sAppsRepository; private static AppsRepository sAppsRepository;
private AppsRepository() { private AppsRepository() {
appsRelay = BehaviorRelay.create(); appsRelay = BehaviorRelay.create();
allItems = BehaviorRelay.create();
} }
public static AppsRepository getAppsRepository() { public static AppsRepository getAppsRepository() {
...@@ -25,13 +30,43 @@ public class AppsRepository { ...@@ -25,13 +30,43 @@ public class AppsRepository {
public void clearAll(){ public void clearAll(){
appsRelay = BehaviorRelay.create(); appsRelay = BehaviorRelay.create();
allItems = BehaviorRelay.create();
} }
public void updateAppsRelay(List<LauncherItem> launcherItems) { public void updateAppsRelay(List<LauncherItem> launcherItems) {
this.appsRelay.accept(launcherItems); this.appsRelay.accept(launcherItems);
} }
public void updateAllAppsRelay(AllItems allItems) {
this.allItems.accept(allItems);
}
public BehaviorRelay<List<LauncherItem>> getAppsRelay() { public BehaviorRelay<List<LauncherItem>> getAppsRelay() {
return appsRelay; 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 ...@@ -87,6 +87,7 @@ import foundation.e.blisslauncher.core.utils.IntegerArray
import foundation.e.blisslauncher.core.utils.ListUtil import foundation.e.blisslauncher.core.utils.ListUtil
import foundation.e.blisslauncher.core.utils.PackageUserKey import foundation.e.blisslauncher.core.utils.PackageUserKey
import foundation.e.blisslauncher.core.utils.UserHandle 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.Hotseat
import foundation.e.blisslauncher.features.launcher.SearchInputDisposableObserver import foundation.e.blisslauncher.features.launcher.SearchInputDisposableObserver
import foundation.e.blisslauncher.features.notification.DotInfo import foundation.e.blisslauncher.features.notification.DotInfo
...@@ -1109,12 +1110,12 @@ class TestActivity : BaseDraggingActivity(), AutoCompleteAdapter.OnSuggestionCli ...@@ -1109,12 +1110,12 @@ class TestActivity : BaseDraggingActivity(), AutoCompleteAdapter.OnSuggestionCli
BlissLauncher.getApplication(this) BlissLauncher.getApplication(this)
.appProvider .appProvider
.appsRepository .appsRepository
.appsRelay .allItemsRelay
.distinctUntilChanged() .distinctUntilChanged()
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribeWith(object : DisposableObserver<List<LauncherItem>>() { .subscribeWith(object : DisposableObserver<AppsRepository.AllItems>() {
override fun onNext(launcherItems: List<LauncherItem>) { override fun onNext(items: AppsRepository.AllItems) {
mainHandler.post { showApps(launcherItems) } mainHandler.post { showApps(items) }
} }
override fun onError(e: Throwable) { override fun onError(e: Throwable) {
...@@ -1126,14 +1127,15 @@ class TestActivity : BaseDraggingActivity(), AutoCompleteAdapter.OnSuggestionCli ...@@ -1126,14 +1127,15 @@ class TestActivity : BaseDraggingActivity(), AutoCompleteAdapter.OnSuggestionCli
) )
} }
private fun showApps(launcherItems: List<LauncherItem>) { private fun showApps(allItems: AppsRepository.AllItems) {
hotseat.resetLayout(false) hotseat.resetLayout(false)
val populatedItems = populateItemPositions(launcherItems) val populatedItems = populateItemPositions(allItems.items)
val orderedScreenIds = IntegerArray() val orderedScreenIds = IntegerArray()
orderedScreenIds.addAll(collectWorkspaceScreens(populatedItems)) orderedScreenIds.addAll(collectWorkspaceScreens(populatedItems))
workspace.removeAllWorkspaceScreens() workspace.removeAllWorkspaceScreens()
workspace.bindScreens(orderedScreenIds) workspace.bindScreens(orderedScreenIds)
workspace.bindItems(populatedItems, false) workspace.bindItems(populatedItems, false)
workspace.bindItemsAdded(allItems.newAddedItems)
} }
private fun populateItemPositions(launcherItems: List<LauncherItem>): List<LauncherItem> { 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