Skip to content

Commit

Permalink
Merge pull request #18 from MansiBhayade/testcases
Browse files Browse the repository at this point in the history
#7 PR - Feature - Sort by Author
  • Loading branch information
ukanth authored Jul 13, 2023
2 parents 1480125 + cda70bf commit e03c8db
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 12 deletions.
3 changes: 0 additions & 3 deletions app/src/main/java/dev/ukanth/iconmgr/Detail.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class Detail {
private final String mSubtitle;
private final Detail.Type mType;


private List<Icon> listIcons;

public Detail(@DrawableRes int icon, String title, String subtitle, @NonNull Detail.Type type) {
Expand Down Expand Up @@ -47,8 +46,6 @@ public Detail.Type getType() {
public void setTitle(String title) {
mTitle = title;
}


public List<Icon> getListIcons() {
return listIcons;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
ContentViewHolder contentViewHolder = (ContentViewHolder) holder;
int finalPosition = position - 1;
contentViewHolder.autoFitTitle.setText(mHomes.get(finalPosition).getTitle());

/* if (!BuildConfig.FULLFEATURE) {
float radius = contentViewHolder.autoFitTitle.getTextSize() / 3;
BlurMaskFilter filter = new BlurMaskFilter(radius, BlurMaskFilter.Blur.NORMAL);
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/java/dev/ukanth/iconmgr/IconAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ private void stats(Context ctx, IPObj currentItem) {
ctx.startActivity(intent);
}
}


private void openApp(Context ctx, IPObj currentItem) {
try {
if (currentItem != null && currentItem.getIconPkg() != null && !currentItem.getIconPkg().isEmpty()
Expand Down Expand Up @@ -253,6 +251,16 @@ public void onBindViewHolder(IconPackViewHolder personViewHolder, int i) {
builder.append(" " + Util.prettyFormat(new Date(System.currentTimeMillis() - obj.getInstallTime())));
}

if (Prefs.showAuthorName()){
if (Prefs.isTotalIcons() || Prefs.showSize() || Prefs.showPercentage() || Prefs.sortBy().equals("s1")){
builder.append(" - ");
}
isshown = true;
String authorName = Util.getAuthorName(ctx, obj.getIconPkg());
builder.append( authorName);
}


personViewHolder.ipackCount.setText(builder.toString());

if (!isshown) {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/dev/ukanth/iconmgr/IconAttr.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

public class IconAttr {

public long getSize() {
return size;
}
Expand Down Expand Up @@ -62,6 +63,8 @@ public void setFavorite(boolean favorite) {
private boolean purchased = false;
private boolean favorite = false;



@Override
public String toString() {
return new GsonBuilder().create().toJson(this, IconAttr.class);
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/dev/ukanth/iconmgr/IconPackManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public IPObj call() throws Exception {
attr.setDeleted(false);
obj.setMissed(ip.getMissingApps(obj.getIconPkg(), Util.getInstalledApps()).size());
attr.setSize(Util.getApkSize(obj.getIconPkg()));

obj.setAdditional(attr.toString());
ipObjDao.insert(obj);
sendIntent(pkgName);
Expand Down
16 changes: 13 additions & 3 deletions app/src/main/java/dev/ukanth/iconmgr/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ public boolean onCreateOptionsMenu(Menu menu) {
case "s2":
mainMenu.findItem(R.id.sort_count).setChecked(true);
break;
case "s5" :
mainMenu.findItem(R.id.author_name).setChecked(true);
}
});

Expand Down Expand Up @@ -445,6 +447,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
item.setChecked(true);
reload();
return true;
case R.id.author_name:
Prefs.sortBy("s5");
item.setChecked(true);
reload();
return true;
default:
return super.onOptionsItemSelected(item);
}
Expand All @@ -456,7 +463,8 @@ private void showIconSearch() {
}

private void reload() {
Collections.sort(iconPacksList, new PackageComparator());
PackageComparator packageComparator = new PackageComparator(MainActivity.this); // Pass the activity context here
Collections.sort(iconPacksList, packageComparator);
adapter = new IconAdapter(iconPacksList, installed);
recyclerView.setAdapter(adapter);
adapter.notifyDataSetChanged();
Expand Down Expand Up @@ -509,7 +517,9 @@ public boolean onQueryTextSubmit(String query) {
public boolean onQueryTextChange(String query) {
List<IPObj> filteredModelList = filter(query);

Collections.sort(new ArrayList(filteredModelList), new PackageComparator());
PackageComparator packageComparator = new PackageComparator(MainActivity.this); // Pass the activity context here
Collections.sort(new ArrayList<>(filteredModelList), packageComparator);


adapter = new IconAdapter(filteredModelList, installed);
recyclerView.setAdapter(adapter);
Expand Down Expand Up @@ -647,7 +657,7 @@ protected void onPostExecute(Void result) {
setTitle(getString(R.string.app_name) + " - #" + iconPacksList.size());
recyclerView.setVisibility(View.VISIBLE);
emptyView.setVisibility(View.GONE);
Collections.sort(iconPacksList, new PackageComparator());
Collections.sort(iconPacksList, new PackageComparator(MainActivity.this));
if (Prefs.useFavorite()) {
Collections.sort(iconPacksList, new Comparator<IPObj>() {
@Override
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/dev/ukanth/iconmgr/Prefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class Prefs {
public static final String PREVIEW = "preview_nonthemed";
public static final String ROOT_TASKER = "use_root_tasker";
public static final String SHOW_SIZE = "showpack_size";
public static final String SHOW_AUTHOR_NAME = "show_authorName";
public static final String SHOW_PERCENT = "showpack_percent";
public static final String LIST_COL = "preview_col";
public static final String IS_FIRST_TIME = "isFirstTime";
Expand Down Expand Up @@ -106,6 +107,11 @@ public static boolean isPS() {
return prefs.getBoolean(PS, false);
}

public static boolean showAuthorName() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(App.getContext());
return prefs.getBoolean(SHOW_AUTHOR_NAME,false);
}

public static boolean showPercentage() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(App.getContext());
return prefs.getBoolean(SHOW_PERCENT, false);
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/dev/ukanth/iconmgr/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;

import static dev.ukanth.iconmgr.Prefs.SHOW_PERCENT;
import static dev.ukanth.iconmgr.Prefs.SHOW_AUTHOR_NAME;
import static dev.ukanth.iconmgr.Prefs.SHOW_SIZE;
import static dev.ukanth.iconmgr.Prefs.THEME_RES_ID;
import static dev.ukanth.iconmgr.Prefs.TOTAL_ICONS;
Expand Down Expand Up @@ -181,15 +182,14 @@ public void onPause() {
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
}


@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
//seems like theme changed
if (key.equals(THEME_RES_ID)) {
getActivity().recreate();
//MainActivity.setReloadTheme(true);
}
if (key.equals(TOTAL_ICONS) || key.equals(SHOW_PERCENT) || key.equals(SHOW_SIZE)) {
if (key.equals(TOTAL_ICONS) || key.equals(SHOW_PERCENT) || key.equals(SHOW_SIZE) || key.equals(SHOW_AUTHOR_NAME)) {
MainActivity.setReloadApp(true);
}
}
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/java/dev/ukanth/iconmgr/util/PackageComparator.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@

public class PackageComparator implements Comparator<IPObj> {

private Context context;

public PackageComparator(Context context) {
this.context = context;
}

@Override
public int compare(IPObj o1, IPObj o2) {
public int compare( IPObj o1, IPObj o2) {
switch (Prefs.sortBy()) {
case "s0":
return String.CASE_INSENSITIVE_ORDER.compare(o1.getIconName(), o2.getIconName());
Expand All @@ -31,6 +37,10 @@ public int compare(IPObj o1, IPObj o2) {
return (o1Attr > o2Attr) ? -1 : (o1Attr < o2Attr) ? 1 : 0;
case "s4":
return (o2.getMissed() > o1.getMissed()) ? -1 : (o2.getMissed() < o1.getMissed()) ? 1 : 0;
case "s5":
String authorName1 = Util.getAuthorName(context, o1.getIconPkg());
String authorName2 = Util.getAuthorName(context, o2.getIconPkg());
return String.CASE_INSENSITIVE_ORDER.compare(authorName1, authorName2);
}
return 1;
}
Expand Down
51 changes: 51 additions & 0 deletions app/src/main/java/dev/ukanth/iconmgr/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.Signature;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.os.AsyncTask;
import android.os.Build;
import androidx.annotation.NonNull;
Expand All @@ -32,9 +34,14 @@
import org.ocpsoft.prettytime.TimeUnit;
import org.ocpsoft.prettytime.units.JustNow;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
Expand Down Expand Up @@ -69,6 +76,10 @@ public class Util {
public static final String TMP_FILE = ".temp";
private static final String TAG = "MICOPACK";

private static String authorName;



public static void updateFile(final String fileName, final String packageName, final String key, final String value, final Context ctx) {
Log.i(TAG, String.format("Read Preference - (%s)", fileName));

Expand Down Expand Up @@ -451,6 +462,46 @@ public static boolean isPackageExisted(Context context, String targetPackage) {
return true;
}


public static String getAuthorName(Context context, String targetPackage) {
PackageManager pm = context.getPackageManager();
try {
Signature[] sigs = context.getPackageManager().getPackageInfo(targetPackage, PackageManager.GET_SIGNATURES).signatures;
for (Signature sig : sigs)
{
/*
* Get the X.509 certificate.
*/
final byte[] rawCert = sig.toByteArray();
InputStream certStream = new ByteArrayInputStream(rawCert);

try {
CertificateFactory certFactory = CertificateFactory.getInstance("X509");
X509Certificate x509Cert = (X509Certificate) certFactory.generateCertificate(certStream);
String issuerDN = x509Cert.getIssuerDN().getName();
Log.i("DN", issuerDN);

String[] nameComponents = issuerDN.split(",");
for (String nameComponent : nameComponents) {
String[] keyValue = nameComponent.trim().split("=");
if (keyValue.length == 2 && keyValue[0].trim().equalsIgnoreCase("CN")) {
authorName = keyValue[1].trim();
return authorName;
}
}
}
catch (CertificateException e) {
Log.e("getAuthorName","CertificateException"+Log.getStackTraceString(e));
}
}
} catch (PackageManager.NameNotFoundException e) {
Log.e("getAuthorName","NameNotFoundException"+Log.getStackTraceString(e));
}
return null;
}



public static IPObj getRandomInstalledIconPack(IPObjDao ipObjDao) {

List<IPObj> list = ipObjDao.loadAll();
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/menu/main_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
android:title="@string/iconsize"
app:showAsAction="always"></item>

<item
android:id="@+id/author_name"
android:title="@string/authorname"
app:showAsAction="always"></item>

<item
android:id="@+id/sort_percent"
android:title="@string/iconpercent"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<string name="lastupdated">By last update</string>
<string name="iconcount">By icon count</string>
<string name="iconsize">By package size</string>
<string name="authorname">By Author Name</string>
<string name="iconpercent">By match percent</string>
<string name="total_icons">Show icon count</string>
<string name="show_notification">Notify on new icon pack install</string>
Expand Down Expand Up @@ -88,6 +89,7 @@
<string name="license_check_retry">Unable to check license, please try again in a few moments</string>
<string name="showsize">Show application size</string>
<string name="show_percent">Show Percentage</string>
<string name="show_authorname">Show Author Name</string>
<string name="forcereload">Rebuild list</string>
<string name="onlysupportedroot">Supported through root mode only</string>
<string name="action_random">Random</string>
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/xml/pref_general.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
android:key="show_favorites"
android:title="@string/show_favs" />

<SwitchPreference
android:defaultValue="false"
android:key="show_authorName"
android:title="@string/show_authorname" />

<SwitchPreference
android:defaultValue="false"
android:key="total_icons"
Expand Down

0 comments on commit e03c8db

Please sign in to comment.