mirror of
https://github.com/whyorean/AuroraStore.git
synced 2026-06-19 13:08:59 -04:00
SearchHistory : Resolve bugs
1. Package name being populated to search view when an app is queried 2. Search history was not save when an app was queried
This commit is contained in:
@@ -46,6 +46,7 @@ import com.aurora.store.HistoryItemTouchHelper;
|
||||
import com.aurora.store.R;
|
||||
import com.aurora.store.activity.DetailsActivity;
|
||||
import com.aurora.store.adapter.SearchHistoryAdapter;
|
||||
import com.aurora.store.utility.PackageUtil;
|
||||
import com.aurora.store.utility.PrefUtil;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -127,8 +128,14 @@ public class SearchFragment extends BaseFragment implements BaseFragment.EventLi
|
||||
public boolean onSuggestionClick(int position) {
|
||||
Cursor cursor = searchView.getSuggestionsAdapter().getCursor();
|
||||
cursor.moveToPosition(position);
|
||||
String suggestion = cursor.getString(2);
|
||||
searchView.setQuery(suggestion, true);
|
||||
if (position == 0) {
|
||||
searchView.setQuery(cursor.getString(2), true);
|
||||
searchView.setQuery(cursor.getString(1), false);
|
||||
PackageUtil.addToPseudoPackageMap(context,
|
||||
cursor.getString(2),
|
||||
cursor.getString(1));
|
||||
} else
|
||||
searchView.setQuery(cursor.getString(1), true);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
@@ -137,16 +144,21 @@ public class SearchFragment extends BaseFragment implements BaseFragment.EventLi
|
||||
private void setQuery(String query) {
|
||||
if (looksLikeAPackageId(query)) {
|
||||
context.startActivity(DetailsActivity.getDetailsIntent(getContext(), query));
|
||||
saveQuery(PackageUtil.getAppLabel(context, query));
|
||||
} else {
|
||||
String mDatedQuery = query
|
||||
.concat(":")
|
||||
.concat(new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault())
|
||||
.format(new Date()));
|
||||
setQueryToPref(mDatedQuery);
|
||||
getQueriedApps(query);
|
||||
saveQuery(query);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveQuery(String query) {
|
||||
String mDatedQuery = query
|
||||
.concat(":")
|
||||
.concat(new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault())
|
||||
.format(new Date()));
|
||||
setQueryToPref(mDatedQuery);
|
||||
}
|
||||
|
||||
private void setQueryToPref(String query) {
|
||||
mQueryList = PrefUtil.getListString(context, Constants.RECENT_HISTORY);
|
||||
mQueryList.add(0, query);
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.aurora.store.model.App;
|
||||
@@ -77,14 +78,14 @@ public class PackageUtil {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@NonNull
|
||||
public static String getAppLabel(Context c, String packageName) {
|
||||
try {
|
||||
PackageManager pm = c.getPackageManager();
|
||||
ApplicationInfo appInfo = pm.getApplicationInfo(packageName, 0);
|
||||
return pm.getApplicationLabel(appInfo).toString();
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user