Skip to content

Commit

Permalink
feat: show loading indicator for apps #116
Browse files Browse the repository at this point in the history
  • Loading branch information
Xtr126 committed Nov 30, 2024
1 parent d9b311b commit 6c52443
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 8 deletions.
13 changes: 8 additions & 5 deletions app/src/main/java/xtr/keymapper/profiles/ProfileSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,15 @@ public static void createNewProfileForApp(@UiContext Context context, String pac
}

public static void showAppSelectionDialog(Context context, OnAppSelectedListener listener) {
ProfilesApps appsView = new ProfilesApps(context).asyncLoadApps((p, adapter) ->
p.binding.appsGrid.setAdapter(adapter)
);

ProfilesApps appsView = new ProfilesApps(context);
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(context);
builder.setView(appsView.view);
builder.setView(R.layout.loading);

appsView.asyncLoadApps((p, adapter) -> {
p.binding.appsGrid.setAdapter(adapter);
builder.setView(p.view);
});

AlertDialog dialog = showDialog(builder);

appsView.setListener(packageName -> {
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/xtr/keymapper/profiles/ProfilesApps.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;

import xtr.keymapper.databinding.AppViewBinding;
import xtr.keymapper.databinding.FragmentProfilesAppsBinding;
Expand All @@ -38,7 +37,7 @@ public ProfilesApps(Context context){
}

@UiThread
ProfilesApps asyncLoadApps(OnAppsLoadedListener l) {
void asyncLoadApps(OnAppsLoadedListener l) {
Context context = view.getContext();

new Thread(() -> {
Expand All @@ -47,7 +46,6 @@ ProfilesApps asyncLoadApps(OnAppsLoadedListener l) {
mHandler.post(() -> l.onAppsLoaded(ProfilesApps.this, adapter));
}).start();

return this;
}

public void setListener(ProfileSelector.OnAppSelectedListener mListener) {
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/res/layout/loading.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:gravity="center"
android:orientation="vertical">
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" />

<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/loading"/>
</LinearLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,5 @@
<string name="use_shizuku_for_activation">Use Shizuku for activation?</string>
<string name="add_games">Add Games</string>
<string name="macro">Macro</string>
<string name="loading">Loading…</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-pa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,5 @@
<string name="use_shizuku_for_activation">Use Shizuku for activation?</string>
<string name="add_games">Add Games</string>
<string name="macro">Macro</string>
<string name="loading">Loading…</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,5 @@
<string name="use_shizuku_for_activation">Use Shizuku for activation?</string>
<string name="add_games">Add Games</string>
<string name="macro">Macro</string>
<string name="loading">Loading…</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 @@ -107,4 +107,5 @@
<string name="use_shizuku_for_activation">Use Shizuku for activation?</string>
<string name="add_games">Add Games</string>
<string name="macro">Macro</string>
<string name="loading">Loading…</string>
</resources>

0 comments on commit 6c52443

Please sign in to comment.