Skip to content

Commit

Permalink
resolve #69, #70, #71
Browse files Browse the repository at this point in the history
  • Loading branch information
valkriaine committed May 15, 2022
1 parent 96363c3 commit 567ba74
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 48 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId "com.factor.launcher"
minSdkVersion 22
targetSdkVersion 31
versionCode 41
versionName "0.71"
versionCode 42
versionName "0.72"

renderscriptTargetApi 31
renderscriptSupportModeEnabled true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ private Factor getFactorByPackage(String packageName)


//Tile ViewHolder
protected static class FactorsViewHolder extends RecyclerView.ViewHolder
public static class FactorsViewHolder extends RecyclerView.ViewHolder
{
public final ViewDataBinding binding;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
import android.appwidget.AppWidgetHostView;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.*;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
Expand All @@ -30,6 +27,7 @@
import androidx.appcompat.widget.SearchView;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.app.ActivityCompat;
import androidx.databinding.ViewDataBinding;
import androidx.dynamicanimation.animation.SpringAnimation;
import androidx.dynamicanimation.animation.SpringForce;
import androidx.fragment.app.Fragment;
Expand All @@ -44,6 +42,10 @@
import com.factor.launcher.FactorApplication;
import com.factor.launcher.R;
import com.factor.launcher.activities.SettingsActivity;
import com.factor.launcher.adapters.FactorsAdapter;
import com.factor.launcher.databinding.FactorLargeBinding;
import com.factor.launcher.databinding.FactorMediumBinding;
import com.factor.launcher.databinding.FactorSmallBinding;
import com.factor.launcher.databinding.FragmentHomeScreenBinding;
import com.factor.launcher.models.AppSettings;
import com.factor.launcher.models.Factor;
Expand Down Expand Up @@ -124,7 +126,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
}


//handle back button press
// handle back button press
@Override
public boolean onBackPressed()
{
Expand Down Expand Up @@ -165,6 +167,7 @@ else if (binding.homePager.getCurrentItem() == 0)
}


// home button press
@Override
public boolean onNewIntent()
{
Expand Down Expand Up @@ -226,6 +229,25 @@ public void onDestroyView()
removeWidget(appWidgetId);
e.printStackTrace();
}

// stop wave animations
for (int x = binding.tilesList.getChildCount(), i = 0; i < x; ++i)
{
FactorsAdapter.FactorsViewHolder holder = (FactorsAdapter.FactorsViewHolder) binding.tilesList.getChildViewHolder(binding.tilesList.getChildAt(i));
ViewDataBinding holderBinding = holder.binding;
if (holderBinding instanceof FactorSmallBinding)
{
((FactorSmallBinding) holderBinding).tile.getWaveView().stopAnimation();
}
if (holderBinding instanceof FactorMediumBinding)
{
((FactorMediumBinding) holderBinding).tile.getWaveView().stopAnimation();
}
if (holderBinding instanceof FactorLargeBinding)
{
((FactorLargeBinding) holderBinding).tile.getWaveView().stopAnimation();
}
}
}
}

Expand Down Expand Up @@ -279,9 +301,16 @@ public void onStart()

private void forceNotificationListener()
{

appListManager.clearAllNotifications();
if (notificationListenerIntent != null && getContext() != null)
{
ComponentName notificationComponent = new ComponentName(getContext().getApplicationContext(), NotificationListener.class);
PackageManager pm = getContext().getPackageManager();

pm.setComponentEnabledSetting(notificationComponent, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
pm.setComponentEnabledSetting(notificationComponent, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

try
{
getContext().startService(notificationListenerIntent);
Expand All @@ -291,6 +320,7 @@ private void forceNotificationListener()
e.printStackTrace();
}


}
}

Expand Down Expand Up @@ -530,6 +560,8 @@ public void onPageScrollStateChanged(int state) {}

binding.tilesList.setAdapter(appListManager.getFactorManager().adapter);
};
// debug
binding.tilesList.setItemViewCacheSize(40);

appListManager.getFactorManager().getFactorMutableLiveData().observe(getViewLifecycleOwner(), factorObserver);
binding.tilesList.setItemViewCacheSize(appListManager.getFactorManager().adapter.getItemCount());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ public void resumeAnimation() {
}
}

public void stopAnimation()
{
pauseAnimation();
onDetachedFromWindow();
}

@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,10 @@ protected void onDetachedFromWindow()






public WaveView getWaveView()
{
return waveView;
}


protected static class ShortcutsAdapter extends RecyclerView.Adapter<ShortcutsAdapter.ShortcutViewHolder>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public FactorMediumView(Context context, AttributeSet attrs, int defStyle) {
init();
}

public WaveView getWaveView()
{
return waveView;
}


private void init()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public FactorSmallView(Context context, AttributeSet attrs, int defStyle) {
init();
}

public WaveView getWaveView()
{
return waveView;
}

private void init()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

public class AppListManager extends ViewModel
{
private static final String TAG = "AppListManager";
private static final String TAG = AppListManager.class.getSimpleName();

private boolean displayHidden = false;

Expand Down Expand Up @@ -66,6 +66,7 @@ public class AppListManager extends ViewModel

private IconPackManager.IconPack iconPack = null;

// todo: fallback to bitmap icon if drawable icon fails to load from icon pack
//constructor
public AppListManager(HomeScreenFragment fragment,
ViewGroup background,
Expand Down Expand Up @@ -201,8 +202,12 @@ private void loadApps(Boolean isSaved)
app.setShortCuts(getShortcutsFromApp(app));



app.setIcon(r.activityInfo.loadIcon(packageManager));
if (iconPack != null)
{
app.setIcon(iconPack.getDrawableIconForPackage(app.getPackageName(), r.activityInfo.loadIcon(packageManager)));
}
else
app.setIcon(r.activityInfo.loadIcon(packageManager));

userApps.add(app);
daoReference.insert(app);
Expand Down Expand Up @@ -478,13 +483,12 @@ public void updateApp(UserApp app)

if (iconPack != null)
{
appToUpdate.setIcon(iconPack.getDrawableIconForPackage(app.getPackageName(), packageManager.getApplicationIcon(app.getPackageName())));
userApps.get(position).setIcon(iconPack.getDrawableIconForPackage(app.getPackageName(), packageManager.getApplicationIcon(app.getPackageName())));
}
else
appToUpdate.setIcon(packageManager.getApplicationIcon(app.getPackageName()));
userApps.get(position).setIcon(packageManager.getApplicationIcon(app.getPackageName()));


userApps.get(position).setIcon(packageManager.getApplicationIcon(appToUpdate.getPackageName()));
userApps.get(position).setLabelOld((String) packageManager.getApplicationLabel(info));

//retrieve shortcuts on api 25 and higher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

public class FactorManager extends ViewModel
{
private static final String TAG = FactorManager.class.getSimpleName();
private final MutableLiveData<ArrayList<Factor>> factorMutableLiveData = new MutableLiveData<>();

private final ArrayList<Factor> userFactors = new ArrayList<>();
Expand Down Expand Up @@ -87,29 +88,10 @@ private void loadFactors()
userFactors.addAll(daoReference.getAll());
for (Factor f: userFactors)
{
try {
if (packageManager.getApplicationInfo(f.getPackageName(), 0).enabled)
{
Drawable icon;

if (iconPack != null)
{
icon = iconPack.getDrawableIconForPackage(f.getPackageName(), packageManager.getApplicationIcon(f.getPackageName()));
}
else
icon = appListManager.packageManager.getApplicationIcon(f.getPackageName());

f.setIcon(icon);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1)
f.setShortcuts(getShortcutsFromFactor(f));
}
loadIcon(f);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1)
f.setShortcuts(getShortcutsFromFactor(f));

} catch (PackageManager.NameNotFoundException | NullPointerException e)
{
Log.d("icon", "failed to load icon for " + f.getPackageName() + " " + e.getMessage());
daoReference.delete(f);
}
}
adapter.activity.runOnUiThread(adapter::notifyDataSetChanged);
}).start();
Expand All @@ -118,7 +100,6 @@ private void loadFactors()
//add recently used app
public void addToRecent(UserApp app)
{
Log.d("recent", "called");
if (!app.isHidden())
appListManager.recentAppsHost.add(app);
}
Expand All @@ -140,9 +121,6 @@ public void addToHome(UserApp app)
factor.setOrder(userFactors.indexOf(factor));
new Thread(() ->
{
Log.d("add", factor.getPackageName() + " index " + factor.getOrder());
Log.d("add", "number of Shortcuts: " + factor.getUserApp().getShortCuts().size());
Log.d("add", "Shortcuts: " + factor.getUserApp().getShortCuts());
daoReference.insert(factor);
adapter.addFactorBroadcast(userFactors.indexOf(factor));
adapter.activity.runOnUiThread(()-> adapter.notifyItemInserted(factor.getOrder()));
Expand Down Expand Up @@ -269,26 +247,31 @@ private ArrayList<Factor> getFactorsByPackage(UserApp app)
//retrieve the icon for a given factor
public void loadIcon(Factor factor)
{
Drawable icon = null;
try
{
Drawable icon;

if (packageManager.getApplicationInfo(factor.getPackageName(), 0).enabled)
{

// todo: fallback to bitmap icon
if (iconPack != null)
{
icon = iconPack.getDrawableIconForPackage(factor.getPackageName(), packageManager.getApplicationIcon(factor.getPackageName()));
}
else

if (icon == null)
icon = appListManager.packageManager.getApplicationIcon(factor.getPackageName());


factor.setIcon(icon);

}
}
catch (Exception e)
catch (PackageManager.NameNotFoundException | NullPointerException e)
{
e.printStackTrace();
new Thread(() -> daoReference.delete(factor)).start();
Log.d(TAG, "failed to load icon for " + factor.getPackageName() + " " + e.getMessage());
//removeFromHome(factor);
}
}

Expand Down

0 comments on commit 567ba74

Please sign in to comment.