2013-04-20 23:58:59 +02:00
|
|
|
/*
|
|
|
|
This file is part of Subsonic.
|
|
|
|
|
|
|
|
Subsonic is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Subsonic is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
Copyright 2009 (C) Sindre Mehus
|
|
|
|
*/
|
|
|
|
|
2015-07-26 18:15:07 +02:00
|
|
|
package org.moire.ultrasonic.activity;
|
2013-04-20 23:58:59 +02:00
|
|
|
|
|
|
|
import android.content.Intent;
|
2013-04-27 11:52:25 +02:00
|
|
|
import android.os.AsyncTask;
|
2013-04-20 23:58:59 +02:00
|
|
|
import android.os.Bundle;
|
2020-09-30 14:47:59 +02:00
|
|
|
import timber.log.Timber;
|
2013-04-20 23:58:59 +02:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.ListView;
|
2013-04-27 11:52:25 +02:00
|
|
|
|
2020-09-21 12:17:55 +02:00
|
|
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
|
|
|
|
2015-07-26 18:15:07 +02:00
|
|
|
import org.moire.ultrasonic.R;
|
|
|
|
import org.moire.ultrasonic.domain.Genre;
|
|
|
|
import org.moire.ultrasonic.service.MusicService;
|
|
|
|
import org.moire.ultrasonic.service.MusicServiceFactory;
|
|
|
|
import org.moire.ultrasonic.util.BackgroundTask;
|
|
|
|
import org.moire.ultrasonic.util.Constants;
|
|
|
|
import org.moire.ultrasonic.util.TabActivityBackgroundTask;
|
|
|
|
import org.moire.ultrasonic.util.Util;
|
|
|
|
import org.moire.ultrasonic.view.GenreAdapter;
|
2013-04-20 23:58:59 +02:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2013-12-04 07:36:02 +01:00
|
|
|
public class SelectGenreActivity extends SubsonicTabActivity implements AdapterView.OnItemClickListener
|
|
|
|
{
|
2020-09-21 12:17:55 +02:00
|
|
|
private SwipeRefreshLayout refreshGenreListView;
|
2013-04-27 11:52:25 +02:00
|
|
|
private ListView genreListView;
|
2013-12-04 07:36:02 +01:00
|
|
|
private View emptyView;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the activity is first created.
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState)
|
|
|
|
{
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.select_genre);
|
|
|
|
|
2020-09-21 12:17:55 +02:00
|
|
|
refreshGenreListView = findViewById(R.id.select_genre_refresh);
|
|
|
|
genreListView = findViewById(R.id.select_genre_list);
|
2013-12-04 07:36:02 +01:00
|
|
|
|
2020-09-21 12:17:55 +02:00
|
|
|
refreshGenreListView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener()
|
2013-12-04 07:36:02 +01:00
|
|
|
{
|
|
|
|
@Override
|
2020-09-21 12:17:55 +02:00
|
|
|
public void onRefresh()
|
2013-12-04 07:36:02 +01:00
|
|
|
{
|
|
|
|
new GetDataTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
genreListView.setOnItemClickListener(this);
|
|
|
|
|
|
|
|
emptyView = findViewById(R.id.select_genre_empty);
|
|
|
|
|
|
|
|
registerForContextMenu(genreListView);
|
|
|
|
|
|
|
|
View browseMenuItem = findViewById(R.id.menu_browse);
|
|
|
|
menuDrawer.setActiveView(browseMenuItem);
|
|
|
|
|
|
|
|
setActionBarSubtitle(R.string.main_genres_title);
|
|
|
|
|
|
|
|
load();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu)
|
|
|
|
{
|
|
|
|
super.onCreateOptionsMenu(menu);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void refresh()
|
|
|
|
{
|
|
|
|
finish();
|
|
|
|
Intent intent = getIntent();
|
|
|
|
intent.putExtra(Constants.INTENT_EXTRA_NAME_REFRESH, true);
|
2013-12-31 06:06:30 +01:00
|
|
|
startActivityForResultWithoutTransition(this, intent);
|
2013-12-04 07:36:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
BackgroundTask<List<Genre>> task = new TabActivityBackgroundTask<List<Genre>>(this, true)
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
protected List<Genre> doInBackground() throws Throwable
|
|
|
|
{
|
2020-09-24 15:16:59 +02:00
|
|
|
boolean refresh = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_REFRESH, false);
|
2013-12-04 07:36:02 +01:00
|
|
|
MusicService musicService = MusicServiceFactory.getMusicService(SelectGenreActivity.this);
|
|
|
|
|
|
|
|
List<Genre> genres = new ArrayList<Genre>();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2020-09-24 15:16:59 +02:00
|
|
|
genres = musicService.getGenres(refresh, SelectGenreActivity.this, this);
|
2013-12-04 07:36:02 +01:00
|
|
|
}
|
|
|
|
catch (Exception x)
|
|
|
|
{
|
2020-09-30 14:47:59 +02:00
|
|
|
Timber.e(x, "Failed to load genres");
|
2013-12-04 07:36:02 +01:00
|
|
|
}
|
|
|
|
|
2013-04-20 23:58:59 +02:00
|
|
|
return genres;
|
2013-12-04 07:36:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void done(List<Genre> result)
|
|
|
|
{
|
|
|
|
emptyView.setVisibility(result == null || result.isEmpty() ? View.VISIBLE : View.GONE);
|
|
|
|
|
|
|
|
if (result != null)
|
|
|
|
{
|
|
|
|
genreListView.setAdapter(new GenreAdapter(SelectGenreActivity.this, result));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
task.execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
|
|
|
|
{
|
|
|
|
Genre genre = (Genre) parent.getItemAtPosition(position);
|
|
|
|
|
|
|
|
if (genre != null)
|
|
|
|
{
|
|
|
|
Intent intent = new Intent(this, SelectAlbumActivity.class);
|
|
|
|
intent.putExtra(Constants.INTENT_EXTRA_NAME_GENRE_NAME, genre.getName());
|
|
|
|
intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, Util.getMaxSongs(this));
|
|
|
|
intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0);
|
2013-12-31 06:06:30 +01:00
|
|
|
startActivityForResultWithoutTransition(this, intent);
|
2013-12-04 07:36:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item)
|
|
|
|
{
|
|
|
|
switch (item.getItemId())
|
|
|
|
{
|
2013-04-24 18:31:42 +02:00
|
|
|
case android.R.id.home:
|
|
|
|
menuDrawer.toggleMenu();
|
2013-12-04 07:36:02 +01:00
|
|
|
return true;
|
|
|
|
case R.id.main_shuffle:
|
|
|
|
Intent intent = new Intent(this, DownloadActivity.class);
|
|
|
|
intent.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, true);
|
2013-12-31 06:06:30 +01:00
|
|
|
startActivityForResultWithoutTransition(this, intent);
|
2013-12-04 07:36:02 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private class GetDataTask extends AsyncTask<Void, Void, String[]>
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(String[] result)
|
|
|
|
{
|
|
|
|
super.onPostExecute(result);
|
|
|
|
}
|
2013-04-27 11:52:25 +02:00
|
|
|
|
|
|
|
@Override
|
2013-12-04 07:36:02 +01:00
|
|
|
protected String[] doInBackground(Void... params)
|
|
|
|
{
|
2013-04-27 11:52:25 +02:00
|
|
|
refresh();
|
|
|
|
return null;
|
|
|
|
}
|
2013-12-04 07:36:02 +01:00
|
|
|
}
|
2020-09-21 12:17:55 +02:00
|
|
|
}
|