Skip to content

Commit

Permalink
add entry id debug options
Browse files Browse the repository at this point in the history
  • Loading branch information
TBog committed May 8, 2024
1 parent 8e5d9da commit 29fb2f7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
40 changes: 25 additions & 15 deletions app/src/main/java/rocks/tbog/tblauncher/entry/EntryItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.CallSuper;
import androidx.annotation.LayoutRes;
Expand All @@ -20,6 +21,7 @@
import rocks.tbog.tblauncher.result.ResultHelper;
import rocks.tbog.tblauncher.ui.LinearAdapter;
import rocks.tbog.tblauncher.ui.ListPopup;
import rocks.tbog.tblauncher.utils.ClipboardUtils;
import rocks.tbog.tblauncher.utils.DebugInfo;
import rocks.tbog.tblauncher.utils.FuzzyScore;
import rocks.tbog.tblauncher.utils.Utilities;
Expand Down Expand Up @@ -273,27 +275,31 @@ ListPopup inflatePopupMenu(@NonNull Context context, @NonNull LinearAdapter adap
}

if (DebugInfo.itemRelevance(context)) {
String debugTitle = context.getString(R.string.popup_title_debug);
int pos = -1;
// find title
for (int i = 0; i < adapter.getCount(); i += 1) {
if (debugTitle.equals(adapter.getItem(i).toString())) {
pos = i + 1;
break;
}
}
// if title not found, add title
if (pos == -1) {
adapter.add(new LinearAdapter.ItemTitle(debugTitle));
pos = adapter.getCount();
}
// add debug data after title
int pos = addDebugTitleOnce(context, adapter);
adapter.add(pos, new LinearAdapter.ItemString("Relevance: " + getRelevance()));
}

if (DebugInfo.itemShowId(context)) {
int pos = addDebugTitleOnce(context, adapter);
adapter.add(pos, new LinearAdapter.ItemString(id));
}

return menu;
}

int addDebugTitleOnce(@NonNull Context context, @NonNull LinearAdapter adapter) {
String debugTitle = context.getString(R.string.popup_title_debug);
// find title
for (int i = 0; i < adapter.getCount(); i += 1) {
if (debugTitle.equals(adapter.getItem(i).toString())) {
return i + 1;
}
}
// if title not found, add title
adapter.add(new LinearAdapter.ItemTitle(debugTitle));
return adapter.getCount();
}

/**
* How to display the popup menu
*
Expand Down Expand Up @@ -343,6 +349,10 @@ boolean popupMenuClickHandler(@NonNull View view, @NonNull LinearAdapter.MenuIte
} else if (R.string.menu_popup_quick_list_customize == stringId) {
TBApplication.behaviour(context).launchEditQuickListDialog(context);
return true;
} else if (id.equals(item.toString())) {
ClipboardUtils.setClipboard(context, id);
Toast.makeText(context, context.getString(R.string.copy_confirmation, id), Toast.LENGTH_SHORT).show();
return true;
}

// FullscreenActivity mainActivity = (FullscreenActivity) context;
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/rocks/tbog/tblauncher/utils/DebugInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ public static boolean itemIconInfo(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getBoolean("debug-item-icon-info", false);
}

public static boolean itemShowId(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getBoolean("debug-item-id", false);
}
}
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 @@ -216,6 +216,7 @@
<string name="debug_widget_info">Long press for extra widget info</string>
<string name="debug_item_relevance">Search relevance</string>
<string name="debug_item_icon_info">Icon info</string>
<string name="debug_item_id">Show item id</string>
<string name="shortcut_section">Shortcut</string>
<string name="shortcut_pin_auto_confirm">Auto-confirm shortcut</string>
<string name="shortcut_show_badge">Show app badge</string>
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,11 @@
android:key="debug-item-icon-info"
android:title="@string/debug_item_icon_info" />

<androidx.preference.SwitchPreference
android:defaultValue="false"
android:key="debug-item-id"
android:title="@string/debug_item_id" />

<androidx.preference.SwitchPreference
android:defaultValue="false"
android:key="debug-ksh-touch"
Expand Down

0 comments on commit 29fb2f7

Please sign in to comment.