Skip to content

Commit

Permalink
refactor: Handle menu clicks programmatically in MainActivity.onOptio…
Browse files Browse the repository at this point in the history
…nsItemSelected
  • Loading branch information
ghusta committed Dec 21, 2024
1 parent 6bec4a7 commit 8f1d527
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
47 changes: 47 additions & 0 deletions app/src/main/java/fr/husta/android/dockersearch/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.husta.android.dockersearch;

import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.app.SearchManager;
import android.content.ActivityNotFoundException;
Expand Down Expand Up @@ -29,6 +30,7 @@
import java.util.ArrayList;
import java.util.Objects;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
Expand Down Expand Up @@ -257,6 +259,51 @@ public boolean onCreateOptionsMenu(Menu menu)
return true;
}

@SuppressLint("NonConstantResourceId")
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item)
{
return switch (item.getItemId())
{
case R.id.menu_clear_search_history ->
{
clickClearSearchHistory(item);
yield true;
}
case R.id.menu_choose_theme ->
{
clickChooseTheme(item);
yield true;
}
case R.id.menu_submit_issue ->
{
clickSubmitIssue(item);
yield true;
}
case R.id.menu_contribute ->
{
clickContribute(item);
yield true;
}
case R.id.menu_check_latest_release ->
{
clickCheckLatestRelease(item);
yield true;
}
case R.id.menu_note_app ->
{
clickNoteApp(item);
yield true;
}
case R.id.menu_about ->
{
clickAbout(item);
yield true;
}
default -> super.onOptionsItemSelected(item);
};
}

@Override
public boolean onQueryTextSubmit(String query)
{
Expand Down
7 changes: 0 additions & 7 deletions app/src/main/res/menu/options_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,33 @@
<item
android:id="@+id/menu_clear_search_history"
android:icon="@android:drawable/ic_menu_delete"
android:onClick="clickClearSearchHistory"
android:title="@string/clear_search_history" />

<item
android:id="@+id/menu_choose_theme"
android:onClick="clickChooseTheme"
android:title="@string/choose_theme" />

<item
android:id="@+id/menu_submit_issue"
android:icon="@android:drawable/ic_menu_send"
android:onClick="clickSubmitIssue"
android:title="@string/action_report_issue"
app:showAsAction="never" />

<item
android:id="@+id/menu_contribute"
android:icon="@android:drawable/ic_menu_edit"
android:onClick="clickContribute"
android:title="@string/action_contribute"
app:showAsAction="never" />

<item
android:id="@+id/menu_check_latest_release"
android:onClick="clickCheckLatestRelease"
android:title="@string/action_check_latest_release"
app:showAsAction="never" />

<item
android:id="@+id/menu_note_app"
android:enabled="false"
android:icon="@android:drawable/star_big_on"
android:onClick="clickNoteApp"
android:title="@string/action_rate_app"
android:visible="false"
app:showAsAction="never" />
Expand All @@ -53,7 +47,6 @@
android:id="@+id/menu_about"
android:enabled="true"
android:icon="@android:drawable/ic_menu_info_details"
android:onClick="clickAbout"
android:title="@string/about"
app:showAsAction="never" />

Expand Down

0 comments on commit 8f1d527

Please sign in to comment.