Skip to content

Commit

Permalink
Fixed local fragment search
Browse files Browse the repository at this point in the history
  • Loading branch information
harjot-oberai committed Dec 27, 2016
1 parent 8c6abd3 commit c19a150
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
Expand Down Expand Up @@ -60,6 +61,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

((HomeActivity) getActivity()).onQueryTextChange("");
isSearchboxVisible = false;

backBtn = (ImageView) view.findViewById(R.id.local_fragment_back_btn);
backBtn.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down Expand Up @@ -97,9 +101,16 @@ public void onClick(View v) {
if (isSearchboxVisible) {
searchBox.setText("");
searchBox.setVisibility(View.INVISIBLE);
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(getActivity().INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
searchIcon.setImageResource(R.drawable.ic_search);
fragTitle.setVisibility(View.VISIBLE);
} else {
searchBox.setVisibility(View.VISIBLE);
searchBox.requestFocus();
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(getActivity().INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
searchIcon.setImageResource(R.drawable.ic_cross_white);
fragTitle.setVisibility(View.INVISIBLE);
}
isSearchboxVisible = !isSearchboxVisible;
Expand Down
157 changes: 81 additions & 76 deletions app/src/main/java/com/sdsmdg/harjot/MusicDNA/HomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,22 @@ public void onBackPressed() {
plFrag.toggleContainer.setVisibility(View.VISIBLE);
plFrag.spToolbar.setVisibility(View.VISIBLE);
onFullScreen();
} else if (isEqualizerVisible) {
showPlayer2();
} else if (isQueueVisible) {
showPlayer3();
} else if (isPlayerVisible && !isPlayerTransitioning) {
hidePlayer();
showTabs();
isPlayerVisible = false;
} else if (isLocalVisible && flmFrag != null && flmFrag.searchBox != null && flmFrag.isSearchboxVisible) {
flmFrag.searchBox.setText("");
flmFrag.searchBox.setVisibility(View.INVISIBLE);
flmFrag.isSearchboxVisible = false;
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
flmFrag.searchIcon.setImageResource(R.drawable.ic_search);
flmFrag.fragTitle.setVisibility(View.VISIBLE);
} else if (!searchView.isIconified()) {
searchView.setQuery("", true);
searchView.setIconified(true);
Expand All @@ -1428,15 +1444,7 @@ public void onBackPressed() {
localRecyclerContainer.setVisibility(GONE);
streamRecyclerContainer.setVisibility(GONE);
} else {
if (isEqualizerVisible) {
showPlayer2();
} else if (isQueueVisible) {
showPlayer3();
} else if (isPlayerVisible && !isPlayerTransitioning) {
hidePlayer();
showTabs();
isPlayerVisible = false;
} else if (isEditVisible) {
if (isEditVisible) {
hideFragment("Edit");
} else if (isAlbumVisible) {
hideFragment("viewAlbum");
Expand Down Expand Up @@ -1602,9 +1610,6 @@ public boolean onQueryTextChange(String newText) {
}

private void updateLocalList(String query) {
if (isPlayerVisible) {
hidePlayer();
}

FullLocalMusicFragment flmFrag = (FullLocalMusicFragment) fragMan.findFragmentByTag("local");
LocalMusicFragment lFrag = null;
Expand All @@ -1616,7 +1621,9 @@ private void updateLocalList(String query) {

/*Update the Local List*/

localRecyclerContainer.setVisibility(View.VISIBLE);
if (!isLocalVisible)
localRecyclerContainer.setVisibility(View.VISIBLE);

finalLocalSearchResultList.clear();
for (int i = 0; i < localTrackList.size(); i++) {
LocalTrack lt = localTrackList.get(i);
Expand All @@ -1627,17 +1634,20 @@ private void updateLocalList(String query) {
}
}

if (finalLocalSearchResultList.size() == 0) {
localsongsRecyclerView.setVisibility(GONE);
localNothingText.setVisibility(View.VISIBLE);
} else {
localsongsRecyclerView.setVisibility(View.VISIBLE);
localNothingText.setVisibility(View.INVISIBLE);
if (!isLocalVisible) {
if (finalLocalSearchResultList.size() == 0) {
localsongsRecyclerView.setVisibility(GONE);
localNothingText.setVisibility(View.VISIBLE);
} else {
localsongsRecyclerView.setVisibility(View.VISIBLE);
localNothingText.setVisibility(View.INVISIBLE);
}
(localsongsRecyclerView.getAdapter()).notifyDataSetChanged();
}

(localsongsRecyclerView.getAdapter()).notifyDataSetChanged();
if (lFrag != null)
lFrag.updateAdapter();

if (query.equals("")) {
localRecyclerContainer.setVisibility(GONE);
}
Expand Down Expand Up @@ -1689,74 +1699,71 @@ private void updateArtistList(String query) {

private void updateStreamingList(String query) {

mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if ((settings.isStreamOnlyOnWifiEnabled() && mWifi.isConnected()) || (!settings.isStreamOnlyOnWifiEnabled())) {
new Thread(new CancelCall()).start();
if (!isLocalVisible) {

if (isPlayerVisible) {
hidePlayer();
}
mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if ((settings.isStreamOnlyOnWifiEnabled() && mWifi.isConnected()) || (!settings.isStreamOnlyOnWifiEnabled())) {
new Thread(new CancelCall()).start();

/*Update the Streaming List*/

if (!query.equals("")) {
/*streamingTrackList.clear();
if(sAdapter!=null){
soundcloudRecyclerView.getAdapter().notifyDataSetChanged();
}*/
streamRecyclerContainer.setVisibility(View.VISIBLE);
startLoadingIndicator();
Retrofit client = new Retrofit.Builder()
.baseUrl(Config.API_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
StreamService ss = client.create(StreamService.class);
call = ss.getTracks(query, 75);
call.enqueue(new Callback<List<Track>>() {
/*Update the Streaming List*/

@Override
public void onResponse(Response<List<Track>> response) {

if (response.isSuccess()) {
streamingTrackList = response.body();
sAdapter = new StreamTracksHorizontalAdapter(streamingTrackList, ctx);
LinearLayoutManager mLayoutManager = new LinearLayoutManager(ctx, LinearLayoutManager.HORIZONTAL, false);
soundcloudRecyclerView.setLayoutManager(mLayoutManager);
soundcloudRecyclerView.setItemAnimator(new DefaultItemAnimator());
soundcloudRecyclerView.setAdapter(sAdapter);

if (streamingTrackList.size() == 0) {
streamRecyclerContainer.setVisibility(GONE);
} else {
streamRecyclerContainer.setVisibility(View.VISIBLE);
}
if (!query.equals("")) {
streamRecyclerContainer.setVisibility(View.VISIBLE);

stopLoadingIndicator();
(soundcloudRecyclerView.getAdapter()).notifyDataSetChanged();
startLoadingIndicator();
Retrofit client = new Retrofit.Builder()
.baseUrl(Config.API_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
StreamService ss = client.create(StreamService.class);
call = ss.getTracks(query, 75);
call.enqueue(new Callback<List<Track>>() {

StreamMusicFragment sFrag = (StreamMusicFragment) fragMan.findFragmentByTag("stream");
if (sFrag != null) {
sFrag.dataChanged();
@Override
public void onResponse(Response<List<Track>> response) {

if (response.isSuccess()) {
streamingTrackList = response.body();
sAdapter = new StreamTracksHorizontalAdapter(streamingTrackList, ctx);
LinearLayoutManager mLayoutManager = new LinearLayoutManager(ctx, LinearLayoutManager.HORIZONTAL, false);
soundcloudRecyclerView.setLayoutManager(mLayoutManager);
soundcloudRecyclerView.setItemAnimator(new DefaultItemAnimator());
soundcloudRecyclerView.setAdapter(sAdapter);

if (streamingTrackList.size() == 0) {
streamRecyclerContainer.setVisibility(GONE);
} else {
streamRecyclerContainer.setVisibility(View.VISIBLE);
}

stopLoadingIndicator();
(soundcloudRecyclerView.getAdapter()).notifyDataSetChanged();

StreamMusicFragment sFrag = (StreamMusicFragment) fragMan.findFragmentByTag("stream");
if (sFrag != null) {
sFrag.dataChanged();
}
} else {
stopLoadingIndicator();
}
} else {
stopLoadingIndicator();
Log.d("RETRO", response.body() + "");
}
Log.d("RETRO", response.body() + "");
}

@Override
public void onFailure(Throwable t) {
Log.d("RETRO1", t.getMessage());
}
});
@Override
public void onFailure(Throwable t) {
Log.d("RETRO1", t.getMessage());
}
});

} else {
stopLoadingIndicator();
streamRecyclerContainer.setVisibility(GONE);
}
} else {
stopLoadingIndicator();
streamRecyclerContainer.setVisibility(GONE);
}
} else {
stopLoadingIndicator();
streamRecyclerContainer.setVisibility(GONE);
}
}

Expand Down Expand Up @@ -1882,7 +1889,6 @@ public void hidePlayer3() {
if (playerFragment.mVisualizerView != null)
playerFragment.mVisualizerView.setVisibility(View.INVISIBLE);

// setUpFragmentToolbar(Color.BLACK, "Queue");
switchToolbar(toolbar, queueToolbar, "left");

final Handler handler2 = new Handler();
Expand Down Expand Up @@ -2951,7 +2957,6 @@ public void getNewBitmap() {
@Override
public void deleteMediaStoreCache() {
File dir = new File(Environment.getExternalStorageDirectory() + "/Android/data/com.android.providers.media/albumthumbs");
// Toast.makeText(this, Environment.getExternalStorageDirectory() + "/Android/data/com.android.providers.media/albumthumbs/", Toast.LENGTH_SHORT).show();
if (dir.isDirectory()) {
Toast.makeText(this, "Clearing cache", Toast.LENGTH_SHORT).show();
String[] children = dir.list();
Expand Down
Binary file added app/src/main/res/drawable/ic_cross_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions app/src/main/res/layout/fragment_full_local_music.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,23 @@
android:id="@+id/local_fragment_search_box"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="10dp"
android:layout_toLeftOf="@+id/local_fragment_search_icon"
android:layout_toRightOf="@+id/local_fragment_back_btn"
android:hint="Search"
android:paddingLeft="5dp"
android:visibility="invisible" />

<TextView
android:id="@+id/local_fragment_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@+id/local_fragment_back_btn"
android:text="LOCAL"
android:textColor="#FFFFFF"
android:textSize="25sp" />
android:textSize="23sp" />

<ImageView
android:id="@+id/local_fragment_search_icon"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<!--<color name="colorAccent">#FF4081</color>-->
<color name="colorPrimary">#000000</color>
<color name="colorPrimaryDark">#000000</color>
<color name="colorAccent">#555555</color>
<color name="colorAccent">#FFFFFF</color>
<color name="colorDark">#111111</color>
<color name="colorListItem">#111111</color>
</resources>

0 comments on commit c19a150

Please sign in to comment.