Skip to content

Commit

Permalink
Merge pull request #2 from mark99i/dev
Browse files Browse the repository at this point in the history
Added explicit cache switch
  • Loading branch information
mark99i authored Mar 12, 2022
2 parents c028b29 + fcb4e78 commit 2a158f1
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 17 deletions.
6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "ru.mark99.appsearcher"
minSdk 26
targetSdk 31
versionCode 4
versionName "1.5"
versionCode 5
versionName "1.6"

project.archivesBaseName = "AppSearcher.v" + defaultConfig.versionName
project.ext.set("archivesBaseName", "AppSearcher.v" + defaultConfig.versionName)
Expand All @@ -33,7 +33,9 @@ dependencies {
implementation 'androidx.room:room-runtime:2.4.2'
annotationProcessor 'androidx.room:room-compiler:2.4.2'

implementation 'com.github.GrenderG:Toasty:1.5.2'
implementation 'com.github.ybq:Android-SpinKit:1.4.0'

implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
Expand Down
Binary file removed app/release/AppSearcher.v1.5-release.apk
Binary file not shown.
Binary file added app/release/AppSearcher.v1.6-release.apk
Binary file not shown.
6 changes: 3 additions & 3 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 4,
"versionName": "1.5",
"outputFile": "AppSearcher.v1.5-release.apk"
"versionCode": 5,
"versionName": "1.6",
"outputFile": "AppSearcher.v1.6-release.apk"
}
],
"elementType": "File"
Expand Down
38 changes: 30 additions & 8 deletions app/src/main/java/ru/mark99/appsearcher/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
Expand All @@ -29,6 +28,8 @@
import java.util.ArrayList;
import java.util.Arrays;

import es.dmoral.toasty.Toasty;

public class MainActivity extends AppCompatActivity {

SharedPreferences sharedPreferences;
Expand All @@ -40,6 +41,7 @@ public class MainActivity extends AppCompatActivity {
SwitchMaterial recentlyAppVisible;
SwitchMaterial useGoogle;
SwitchMaterial useContacts;
SwitchMaterial useCache;
LinearLayoutCompat recentlyAppsLayout;
ArrayList<ItemInList> fullInstalledApps;
ArrayList<ItemInList> filteredInstalledApps;
Expand Down Expand Up @@ -69,6 +71,7 @@ protected void onCreate(Bundle savedInstanceState) {
recentlyAppsLayout = findViewById(R.id.main_recently_apps_layout);
loadingPB = findViewById(R.id.main_loading_progress_bar);
useContacts = findViewById(R.id.main_load_contacts);
useCache = findViewById(R.id.main_use_cache);

fastStartAppsIV = new ArrayList<>(Arrays.asList(
findViewById(R.id.main_fast_start1),
Expand All @@ -95,6 +98,7 @@ protected void onCreate(Bundle savedInstanceState) {
systemAppVisible.setChecked(sharedPreferences.getBoolean("showSystem", false));
recentlyAppVisible.setChecked(sharedPreferences.getBoolean("showRecentlyApps", true));
useGoogle.setChecked(sharedPreferences.getBoolean("useGoogle", false));
useCache.setChecked(sharedPreferences.getBoolean("useCache", true));
useContacts.setChecked(
sharedPreferences.getBoolean("useContacts", false) &&
checkSelfPermission(Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED);
Expand Down Expand Up @@ -123,6 +127,7 @@ public void afterTextChanged(Editable editable) {
systemAppVisible.setOnCheckedChangeListener((compoundButton, b) -> onSwitchesChanged(true));
recentlyAppVisible.setOnCheckedChangeListener((compoundButton, b) -> onSwitchesChanged(false));
useGoogle.setOnCheckedChangeListener((compoundButton, b) -> onSwitchesChanged(false));
useCache.setOnCheckedChangeListener((compoundButton, b) -> onSwitchesChanged(true));
useContacts.setOnCheckedChangeListener((compoundButton, b) -> checkAndRequestContactsPermissions());

new Thread(this::loadInstalledAppsAsync).start();
Expand Down Expand Up @@ -150,9 +155,13 @@ private void onSwitchesChanged(boolean needReload) {
editor.putBoolean("showRecentlyApps", recentlyAppVisible.isChecked());
editor.putBoolean("useGoogle", useGoogle.isChecked());
editor.putBoolean("useContacts", useContacts.isChecked());
editor.putBoolean("useCache", useCache.isChecked());
editor.apply();
recentlyAppsLayout.setVisibility(recentlyAppVisible.isChecked() ? View.VISIBLE : View.GONE);
if (needReload) reloadCache();

if (!useCache.isChecked() && useContacts.isChecked())
Toasty.warning(this, "Using contacts search without using the cache can take a long time", Toasty.LENGTH_LONG).show();
}

private void onInputTextChanged(){
Expand Down Expand Up @@ -190,7 +199,7 @@ private void onInputTextChanged(){
private void onItemInListClick(ItemInList item){
switch (item.type){
case SearchInInternet:
searchQuery(this, textInput.getText().toString(), sharedPreferences.getBoolean("useGoogle", false));
searchQuery(this, textInput.getText().toString(), useGoogle.isChecked());
break;

case Contact:
Expand Down Expand Up @@ -221,20 +230,32 @@ private void loadInstalledAppsAsync(){
systemAppVisible.setEnabled(false);
recentlyAppVisible.setEnabled(false);
useContacts.setEnabled(false);
useCache.setEnabled(false);
});

if (cache == null) cache = new Cache(this);

ArrayList<ItemInList> loaded = new ArrayList<>(cache.db.inListDao().getAll());
if (loaded.size() == 0)
ArrayList<ItemInList> loaded;

if (useCache.isChecked()){
loaded = new ArrayList<>(cache.db.inListDao().getAll());
if (loaded.size() == 0)
{
Log.i("loadInstalledAppsAsync", "Load cache is 0 positions, full info loading...");
loaded = Utils.getInstalledApps(this, true);
if (useContacts.isChecked())
loaded.addAll(Utils.getContacts(this));
cache.saveToCacheFull(loaded);
}
}
else
{
Log.i("loadInstalledAppsAsync", "Load cache is 0 positions, full info loading...");
loaded = Utils.getInstalledApps(this, true);
loaded = Utils.getInstalledApps(this, systemAppVisible.isChecked());
if (useContacts.isChecked())
loaded.addAll(Utils.getContacts(this));
cache.saveToCacheFull(loaded);
}


fastStartApps.load(this, sharedPreferences, loaded);

ArrayList<ItemInList> finalLoaded = loaded;
Expand All @@ -252,6 +273,7 @@ private void loadInstalledAppsAsync(){
systemAppVisible.setEnabled(true);
recentlyAppVisible.setEnabled(true);
useContacts.setEnabled(true);
useCache.setEnabled(true);
});
}

Expand Down Expand Up @@ -279,7 +301,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
onSwitchesChanged(true);
} else {
useContacts.setChecked(false);
Toast.makeText(this, "No read_contacts permissions", Toast.LENGTH_SHORT).show();
Toasty.error(this, "No read_contacts permissions", Toasty.LENGTH_SHORT).show();
}

requestPermissionMode = false;
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/ru/mark99/appsearcher/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.provider.ContactsContract;
import android.widget.Toast;

import androidx.appcompat.content.res.AppCompatResources;

Expand All @@ -29,6 +28,8 @@
import java.util.List;
import java.util.Objects;

import es.dmoral.toasty.Toasty;

class Utils {

@SuppressLint("Range")
Expand Down Expand Up @@ -163,7 +164,7 @@ public static void openApp(Context context, ItemInList item){
context.startActivity(intent);
}
else
Toast.makeText(context, item.name + " can't be open (no have launch intent)",
Toast.LENGTH_SHORT).show();
Toasty.error(context, item.name + " can't be open (no have launch intent)",
Toasty.LENGTH_SHORT).show();
}
}
12 changes: 11 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,18 @@
android:layout_height="match_parent"
android:gravity="center"
android:textSize="13sp"
android:layout_marginHorizontal="100dp"
android:layout_marginHorizontal="10dp"
android:text="@string/switch_load_contacts"/>

<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/main_use_cache"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="13sp"
android:layout_marginHorizontal="10dp"
android:text="@string/switch_use_cache"/>
</androidx.appcompat.widget.LinearLayoutCompat>

<androidx.appcompat.widget.LinearLayoutCompat
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-night/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
<string name="switch_use_google">Google</string>
<string name="switch_load_contacts">Contacts</string>
<string name="button_clear_cache">Reload cache</string>
<string name="switch_use_cache">Use cache</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
<string name="switch_use_google">Google</string>
<string name="switch_load_contacts">Contacts</string>
<string name="button_clear_cache">Reload cache</string>
<string name="switch_use_cache">Use cache</string>
</resources>

0 comments on commit 2a158f1

Please sign in to comment.