Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d13159f2 authored by Amit Kumar's avatar Amit Kumar 💻
Browse files

Fix folder pager issue

parent 10dac382
Loading
Loading
Loading
Loading
Loading
+49 −4
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.view.accessibility.AccessibilityEvent
import android.view.inputmethod.EditorInfo
import android.widget.TextView
import android.widget.TextView.OnEditorActionListener
import androidx.viewpager.widget.ViewPager
import foundation.e.blisslauncher.R
import foundation.e.blisslauncher.core.database.model.FolderItem
import foundation.e.blisslauncher.core.database.model.LauncherItem
@@ -127,7 +128,7 @@ class Folder @JvmOverloads constructor(
    fun startDrag(v: View, options: DragOptions): Boolean {
        val tag = v.tag
        if (tag is LauncherItem) {
            val item: LauncherItem = tag as LauncherItem
            val item: LauncherItem = tag
            mEmptyCellRank = item.cell
            mCurrentDragView = v
            dragController!!.addDragListener(this)
@@ -264,6 +265,7 @@ class Folder @JvmOverloads constructor(
    }

    override fun onAdd(item: LauncherItem) {
        // mContent.adapter?.notifyDataSetChanged()
    }

    override fun onTitleChanged(title: CharSequence?) {}
@@ -291,7 +293,9 @@ class Folder @JvmOverloads constructor(
    }

    override fun onItemsChanged(animate: Boolean) {
        mContent.adapter?.notifyDataSetChanged()
        updateTextViewFocus()
        invalidate()
    }

    override fun onDragStart(dragObject: DropTarget.DragObject, options: DragOptions) {
@@ -380,6 +384,21 @@ class Folder @JvmOverloads constructor(
        val mDeviceProfile: VariantDeviceProfile = launcher.deviceProfile
        mContent.adapter =
            FolderPagerAdapter(context, mInfo.items, mDeviceProfile)
        mContent.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {
            }

            override fun onPageSelected(position: Int) {
                updateTextViewFocus()
            }

            override fun onPageScrollStateChanged(state: Int) {
            }
        })
        // We use same size for height and width as we want to look it like square
        val height =
            mDeviceProfile.cellHeightPx * 3 + resources.getDimensionPixelSize(R.dimen.folder_padding)
@@ -389,8 +408,6 @@ class Folder @JvmOverloads constructor(
            (mDeviceProfile.cellHeightPx + mDeviceProfile.iconDrawablePaddingPx * 2) * 3 + resources.getDimensionPixelSize(
                R.dimen.folder_padding
            ) * 2
        mPageIndicator.setViewPager(mContent)

        // In case any children didn't come across during loading, clean up the folder accordingly
        folderIcon?.post {
            if (getItemCount() <= 1) {
@@ -452,7 +469,17 @@ class Folder @JvmOverloads constructor(
        // Just verify that the folder hasn't already been added to the DragLayer.
        // There was a one-off crash where the folder had a parent already.
        if (parent == null) {
            dragLayer.addView(this, BaseDragLayer.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
            mContent.adapter =
                FolderPagerAdapter(context, mInfo.items, launcher.deviceProfile)
            mPageIndicator.setViewPager(mContent)

            dragLayer.addView(
                this,
                BaseDragLayer.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT
                )
            )
        } else {
            Log.e(
                TAG,
@@ -471,6 +498,7 @@ class Folder @JvmOverloads constructor(
        // dropping. One resulting issue is that replaceFolderWithFinalItem() can be called twice.
        mDeleteFolderOnDropCompleted = false
        // centerAboutIcon()
        Log.i(TAG, "animateOpen: " + mContent.getItemCount() + " " + mInfo.items.size)
        val anim: AnimatorSet = FolderAnimationManager(this, true /* isOpening */).animator
        anim.play(ObjectAnimator.ofFloat(launcher.getLauncherPagedView(), View.ALPHA, 0f))
            .with(ObjectAnimator.ofFloat(launcher.hotseat, View.ALPHA, 0f))
@@ -614,6 +642,23 @@ class Folder @JvmOverloads constructor(
    var mOnExitAlarmListener: OnAlarmListener = OnAlarmListener { completeDragExit() }

    override fun onDropCompleted(target: View?, d: DropTarget.DragObject?, success: Boolean) {
        if (success) {
            if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon && target !== this) {
                replaceFolderWithFinalItem()
            }
        } else {
            // The drag failed, we need to return the item to the folder
            mContent.adapter?.notifyDataSetChanged()
        }

        mDeleteFolderOnDropCompleted = false
        mDragInProgress = false
        mItemAddedBackToSelfViaIcon = false
        mCurrentDragView = null

        // Reordering may have occured, and we need to save the new item locations. We do this once
        // at the end to prevent unnecessary database operations.
        launcher.getLauncherPagedView().updateDatabase()
    }

    override fun onBackPressed(): Boolean {
+45 −43
Original line number Diff line number Diff line
@@ -333,7 +333,10 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
            LauncherItem launcherItem = launcherItems.get(i);
            View appView;
            if (launcherItem.itemType == Constants.ITEM_TYPE_FOLDER) {
                FolderIcon folderIcon = FolderIcon.Companion.fromXml(R.layout.folder_icon, getScreenWithId(launcherItem.screenId), (FolderItem) launcherItem);
                FolderIcon folderIcon = FolderIcon.Companion.fromXml(R.layout.folder_icon,
                    getScreenWithId(launcherItem.screenId),
                    (FolderItem) launcherItem
                );
                folderIcon.applyFromFolderItem((FolderItem) launcherItem);
                appView = folderIcon;
            } else {
@@ -1899,52 +1902,51 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
            LauncherItem sourceItem = (LauncherItem) newView.getTag();
            LauncherItem destItem = (LauncherItem) targetView.getTag();

            Rect folderLocation = new Rect();
            // if the drag started here, we need to remove it from the workspace
            if (!external) {
                getParentCellLayoutForView(mDragInfo.getCell()).removeView(mDragInfo.getCell());
            }
            targetView.clearAnimation();
            target.removeView(targetView);
            FolderItem fi = new FolderItem();

            final FolderItem fi = new FolderItem();
            fi.title = getResources().getString(R.string.untitled);
            fi.id = String.valueOf(System.currentTimeMillis());
            fi.items = new ArrayList<>();
            fi.container = destItem.container;
            fi.screenId = destItem.screenId;
            fi.cell = destItem.cell;

            // Create the view
            FolderIcon newFolder = FolderIcon.Companion.fromXml(R.layout.folder_icon, target, fi);
            addInScreen(newFolder, fi);
            // Force measure the new folder icon
            CellLayout parent = getParentCellLayoutForView(newFolder);
            parent.measureChild(newFolder);
            sourceItem.container = Long.parseLong(fi.id);
            destItem.container = Long.parseLong(fi.id);
            sourceItem.screenId = -1;
            destItem.screenId = -1;
            sourceItem.cell = fi.items.size();
            fi.items.add(sourceItem);
            destItem.cell = fi.items.size();
            fi.items.add(destItem);
            Drawable folderIcon = new GraphicsUtil(getContext()).generateFolderIcon(getContext(),
                sourceItem.icon, destItem.icon
            );
            fi.icon = folderIcon;
            fi.container = container;
            fi.screenId = screenId;
            fi.cell = targetCell[1] * mLauncher.getDeviceProfile().getInv()
                .getNumColumns() + targetCell[0];
            FolderIcon folderView = (FolderIcon) LayoutInflater.from(getContext())
                .inflate(R.layout.folder_icon, null, false);
            folderView.applyFromShortcutItem(fi);
            folderView.setOnClickListener(ItemClickHandler.INSTANCE);
            folderView.setOnLongClickListener(ItemLongClickListener.INSTANCE_WORKSPACE);
            fi.addListener(folderView);
            addInScreen(folderView, fi);
            // if the drag started here, we need to remove it from the workspace
            if (!external) {
                getParentCellLayoutForView(mDragInfo.getCell()).removeView(mDragInfo.getCell());
            }
            //Add animation here.
            dragView.remove();
            destItem.cell = 0;
            sourceItem.cell = 1;
            newFolder.addItem(destItem);
            newFolder.addItem(sourceItem);

            updateDatabase(getWorkspaceAndHotseatCellLayouts());

            // Clear drag view
            dragView.remove();
            dragView = null;
            invalidate();
            post(() -> {
                if (fi.cell % 2 == 0) {
                    folderView
                    newFolder
                        .startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.wobble));
                } else {
                    folderView.startAnimation(AnimationUtils
                    newFolder.startAnimation(AnimationUtils
                        .loadAnimation(getContext(), R.anim.wobble_reverse));
                }
                folderView.applyUninstallIconState(false);
                newFolder.applyUninstallIconState(false);
            });
            return true;
        }
@@ -1965,16 +1967,12 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
        if (!mAddToExistingFolderOnDrop) return false;
        mAddToExistingFolderOnDrop = false;

        if ((dropOverView instanceof IconTextView) && (dropOverView
            .getTag() instanceof FolderItem)) {
            FolderItem fi = (FolderItem) dropOverView.getTag();
            LauncherItem sourceItem = (LauncherItem) newView.getTag();
            sourceItem.container = Long.parseLong(fi.id);
            sourceItem.screenId = -1;
            sourceItem.cell = fi.items.size();
            fi.items.add(sourceItem);
            fi.icon = new GraphicsUtil(getContext()).generateFolderIcon(getContext(), fi);
            ((IconTextView) dropOverView).applyFromShortcutItem(fi);
        if (dropOverView instanceof FolderIcon) {
            FolderIcon folderIcon = (FolderIcon) dropOverView;
            if (folderIcon.acceptDrop()) {
                LauncherItem item = d.dragInfo;
                folderIcon.addItem(item);
            }
            // if the drag started here, we need to remove it from the workspace
            if (!external) {
                getParentCellLayoutForView(mDragInfo.getCell()).removeView(mDragInfo.getCell());
@@ -2298,6 +2296,10 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
        return alarmPending;
    }

    public boolean isWobbling() {
        return wobbleExpireAlarm.alarmPending();
    }

    @Override
    public boolean acceptDrop(DragObject dragObject) {
        CellLayout dropTargetLayout = mDropToLayout;
+23 −0
Original line number Diff line number Diff line
@@ -2,7 +2,9 @@ package foundation.e.blisslauncher.core.database.model;


import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import foundation.e.blisslauncher.core.Utilities;
import foundation.e.blisslauncher.core.utils.Constants;

import java.util.ArrayList;
@@ -50,6 +52,27 @@ public class FolderItem extends LauncherItem {
        }
    }

    /**
     * Add an app or shortcut
     *
     * @param item
     */
    public void add(LauncherItem item, boolean animate) {
        add(item, items.size(), animate);
    }

    /**
     * Add an app or shortcut for a specified rank.
     */
    public void add(LauncherItem item, int rank, boolean animate) {
        rank = Utilities.boundToRange(rank, 0, items.size());
        items.add(rank, item);
        for (int i = 0; i < listeners.size(); i++) {
            listeners.get(i).onAdd(item);
        }
        itemsChanged(animate);
    }

    public interface FolderListener {
        void onAdd(LauncherItem item);
        void onTitleChanged(CharSequence title);
+4 −0
Original line number Diff line number Diff line
@@ -53,6 +53,10 @@ public class ItemClickHandler {
            return;
        }*/

        if (launcher.getLauncherPagedView().isWobbling()) {
            return;
        }

        if(v instanceof IconTextView) {
            boolean result = ((IconTextView) v).tryToHandleUninstallClick(launcher);
            if(result) return;
+14 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ import android.view.ViewGroup
import foundation.e.blisslauncher.core.customviews.Folder
import foundation.e.blisslauncher.core.database.model.FolderItem
import foundation.e.blisslauncher.core.database.model.LauncherItem
import foundation.e.blisslauncher.core.touch.ItemClickHandler
import foundation.e.blisslauncher.core.utils.GraphicsUtil
import foundation.e.blisslauncher.features.notification.FolderDotInfo
import foundation.e.blisslauncher.features.test.IconTextView
@@ -34,6 +35,7 @@ class FolderIcon @JvmOverloads constructor(
            val icon = LayoutInflater.from(group.context)
                .inflate(resId, group, false) as FolderIcon
            icon.tag = folderInfo
            icon.setOnClickListener(ItemClickHandler.INSTANCE)
            icon.folderItem = folderInfo
            val folder = Folder.fromXml(icon.launcher).apply {
                this.dragController = launcher.dragController
@@ -105,4 +107,16 @@ class FolderIcon @JvmOverloads constructor(
    fun removeListeners() {
        folderItem.removeListener(this)
    }

    fun acceptDrop(): Boolean {
        return !(folder?.isDestroyed() ?: true)
    }

    fun addItem(item: LauncherItem) {
        addItem(item, true)
    }

    fun addItem(item: LauncherItem?, animate: Boolean) {
        folderItem.add(item, animate)
    }
}
Loading