Skip to content

Commit

Permalink
Add proper search and open menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaned1as committed May 5, 2020
1 parent ce43e56 commit 542f05f
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.SearchView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewSwitcher;
Expand Down Expand Up @@ -115,8 +116,6 @@ public class CoverShowActivity extends DialogActivity {
private ViewSwitcher mSwitcher;
private Button mOkButton, mWriteButton;
private ProgressBar mProgressBar;
private EditText mCustomSearch;
private Button mCustomMedia;

private SafPermissionHandler mSafHandler;
private CoverEngine mEngine = new CoverArchiveEngine();
Expand All @@ -142,8 +141,6 @@ protected void onCreate(Bundle savedInstanceState) {
mWriteButton = findViewById(R.id.write_button);
mOkButton = findViewById(R.id.ok_button);
mProgressBar = findViewById(R.id.progress_bar);
mCustomSearch = findViewById(R.id.search_custom);
mCustomMedia = findViewById(R.id.from_custom_media);

setupUI();
}
Expand Down Expand Up @@ -194,11 +191,39 @@ public boolean onCreateOptionsMenu(Menu menu) {

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
// setup search
MenuItem customSearch = menu.findItem(R.id.custom_search_option);
SearchView searchView = (SearchView) customSearch.getActionView();

int searchImgId = getResources().getIdentifier("android:id/search_button", null, null);
ImageView v = searchView.findViewById(searchImgId);
v.setImageResource(R.drawable.search);

searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
new ArtworkFetcher().execute(query, null, null, null);
return true;
}

@Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
searchView.setOnCloseListener(() -> {
// other items can come out of overflow menu now
invalidateOptionsMenu();
return false;
});

// setup simple options
for (int i = 0; i < menu.size(); i++) {
MenuItem item = menu.getItem(i);
switch (item.getItemId()) {
case R.id.reload_option:
case R.id.custom_option:
case R.id.open_local_option:
case R.id.custom_search_option:
// show only when loading is complete
item.setVisible(mSwitcher != null && mSwitcher.getDisplayedChild() == 1);
continue;
Expand All @@ -212,9 +237,13 @@ public boolean onPrepareOptionsMenu(Menu menu) {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.custom_option:
mCustomSearch.setVisibility(mCustomSearch.getVisibility() == VISIBLE ? GONE : VISIBLE);
mCustomMedia.setVisibility(mCustomMedia.getVisibility() == VISIBLE ? GONE : VISIBLE);
case R.id.custom_search_option:
// search view handles these
return true;
case R.id.open_local_option:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, getString(R.string.pick_custom_media)), PICK_IMAGE_REQUEST);
return true;
case R.id.reload_option:
mSwitcher.setDisplayedChild(0);
Expand Down Expand Up @@ -341,12 +370,6 @@ private void setCoverImage(Bitmap raw) {
private void setupUI() {
mOkButton.setOnClickListener(v -> finish());
mWriteButton.setOnClickListener(new SelectWriteAction());
mCustomSearch.setOnEditorActionListener(new CustomSearchQueryListener());
mCustomMedia.setOnClickListener(v -> {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, getString(R.string.pick_custom_media)), PICK_IMAGE_REQUEST);
});
}

/**
Expand Down Expand Up @@ -664,16 +687,4 @@ private void handleCustomFilename() {
.setPositiveButton(android.R.string.ok, (_d, which) -> persistAsSeparateFile(editor.getText().toString()))
.show();
}

/**
* Listener which submits query to the artwork execution engine
*/
private class CustomSearchQueryListener implements TextView.OnEditorActionListener {

@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
new ArtworkFetcher().execute(v.getText().toString());
return true;
}
}
}
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/open_local.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#ffffffff"
android:pathData="M19,20H4C2.89,20 2,19.1 2,18V6C2,4.89 2.89,4 4,4H10L12,6H19A2,2 0 0,1 21,
8H21L4,8V18L6.14,10H23.21L20.93,18.5C20.7,19.37 19.92,20 19,20Z" />
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/search.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z"/>
</vector>
20 changes: 0 additions & 20 deletions app/src/main/res/layout/activity_cover_show.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,6 @@
android:paddingRight="16dp"
tools:context=".CoverShowActivity">

<EditText
android:id="@+id/search_custom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:hint="@string/custom_album"
android:imeOptions="actionSearch"
android:inputType="textCapWords"
android:visibility="gone" />

<Button
android:id="@+id/from_custom_media"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:hint="@string/from_custom_media"
android:visibility="gone" />

<ViewSwitcher
android:id="@+id/loading_switcher"
android:layout_width="match_parent"
Expand Down
13 changes: 10 additions & 3 deletions app/src/main/res/menu/cover_options.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/custom_option"
android:icon="@drawable/edit"
android:id="@+id/custom_search_option"
android:icon="@drawable/search"
android:actionViewClass="android.widget.SearchView"
android:showAsAction="always"
android:title="@string/custom" />

<item
android:id="@+id/open_local_option"
android:icon="@drawable/open_local"
android:showAsAction="ifRoom"
android:title="@string/open_local" />

<item
android:id="@+id/reload_option"
android:icon="@drawable/refresh"
android:showAsAction="always"
android:showAsAction="ifRoom"
android:title="@string/reload" />

</menu>
2 changes: 1 addition & 1 deletion app/src/main/res/values-hu/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources>
<string name="app_name">Vanilla borítóletöltő</string>
<string name="app_name">Borítóletöltő</string>
<string name="cover_fetch">Borítóletöltő</string>
<string name="plugin_desc">A segítségével letöltheti az albumborítót a kért számhoz</string>
<string name="cover_not_found">Nem található borító.</string>
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<resources>
<string name="app_name">Vanilla Cover Fetch</string>
<string name="cover_fetch">Cover fetch</string>
<string name="app_name">Cover Fetcher</string>
<string name="plugin_desc">曲のアルバムのカバーをダウンロードすることができます</string>
<string name="cover_not_found">カバーが見つかりません!</string>
<string name="invalid_cover_image_format">カバー画像の形式が正しくありません!</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Vanilla Artwork Ophalen</string>
<string name="app_name">Artwork Ophalen</string>
<string name="cover_fetch">Artwork ophalen</string>
<string name="plugin_desc">Download artwork van een album voor bepaalde nummers</string>
<string name="cover_not_found">Artwork niet gevonden!</string>
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Vanilla Cover Fetch</string>
<string name="cover_fetch">Cover fetch</string>
<string name="app_name">Cover Fetcher</string>
<string name="cover_fetch">Cover fetcher plugin</string>
<string name="plugin_desc">Allows you to download album covers for requested songs</string>
<string name="cover_not_found">Cover not found!</string>
<string name="invalid_cover_image_format">Invalid cover image format!</string>
Expand All @@ -18,4 +18,5 @@
<string name="reload">Reload</string>
<string name="write_to_custom_file">Write to custom file</string>
<string name="enter_filename">Enter filename</string>
<string name="open_local">Open local</string>
</resources>

0 comments on commit 542f05f

Please sign in to comment.