mirror of
https://github.com/imcarlost/Android-Itunes-API.git
synced 2026-04-09 18:38:29 -04:00
+ Open artist URL with the listview onClick
This commit is contained in:
@@ -7,12 +7,12 @@
|
|||||||
<application
|
<application
|
||||||
android:name=".AndroidItunesAPI"
|
android:name=".AndroidItunesAPI"
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
|
android:fullBackupContent="@xml/backup_rules"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme.BrandedLaunch"
|
android:theme="@style/AppTheme.BrandedLaunch">
|
||||||
android:fullBackupContent="@xml/backup_rules">
|
|
||||||
<activity android:name=".activities.ArtistListActivity">
|
<activity android:name=".activities.ArtistListActivity">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.hakodev.androiditunesapi.activities;
|
package com.hakodev.androiditunesapi.activities;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.constraint.ConstraintLayout;
|
import android.support.constraint.ConstraintLayout;
|
||||||
@@ -25,6 +27,7 @@ import com.hakodev.androiditunesapi.util.Utils;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
@@ -44,6 +47,7 @@ public class ArtistListActivity extends AppCompatActivity {
|
|||||||
private OkHttpClient networkClient;
|
private OkHttpClient networkClient;
|
||||||
private ArtistsListAdapter artistsListAdapter;
|
private ArtistsListAdapter artistsListAdapter;
|
||||||
private ArrayList<String> artistsList = new ArrayList<>();
|
private ArrayList<String> artistsList = new ArrayList<>();
|
||||||
|
private List<Result> artists;
|
||||||
|
|
||||||
private ConstraintLayout lytBase;
|
private ConstraintLayout lytBase;
|
||||||
private ListView listArtists;
|
private ListView listArtists;
|
||||||
@@ -96,7 +100,7 @@ public class ArtistListActivity extends AppCompatActivity {
|
|||||||
new TimerTask() {
|
new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (txt.toString().length() > 3){
|
if (txt.toString().length() > 3) {
|
||||||
requestArtist(txt.toString());
|
requestArtist(txt.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -109,6 +113,9 @@ public class ArtistListActivity extends AppCompatActivity {
|
|||||||
networkClient = AndroidItunesAPI.getInstance().getNetworkClient();
|
networkClient = AndroidItunesAPI.getInstance().getNetworkClient();
|
||||||
artistsListAdapter = new ArtistsListAdapter(this, artistsList);
|
artistsListAdapter = new ArtistsListAdapter(this, artistsList);
|
||||||
listArtists.setAdapter(artistsListAdapter);
|
listArtists.setAdapter(artistsListAdapter);
|
||||||
|
listArtists.setOnItemClickListener((parent, view, position, id) -> {
|
||||||
|
openWebLink(artists.get(position).getArtistLinkUrl());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void askForPermissions() {
|
private void askForPermissions() {
|
||||||
@@ -151,8 +158,14 @@ public class ArtistListActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<String> parseArtistsResponse(String body) {
|
private ArrayList<String> parseArtistsResponse(String body) {
|
||||||
ItunesResponse itunesResponse = new Gson().fromJson(body, ItunesResponse.class);
|
ItunesResponse itunesResponse = new ItunesResponse();
|
||||||
|
try {
|
||||||
|
itunesResponse = new Gson().fromJson(body, ItunesResponse.class);
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
Log.d(TAG, "The Json was malformed, the request has been ignored");
|
||||||
|
}
|
||||||
ArrayList<String> artistsNames = new ArrayList<>();
|
ArrayList<String> artistsNames = new ArrayList<>();
|
||||||
|
artists = itunesResponse.getResults();
|
||||||
for (Result artist : itunesResponse.getResults()) {
|
for (Result artist : itunesResponse.getResults()) {
|
||||||
artistsNames.add(artist.getArtistName());
|
artistsNames.add(artist.getArtistName());
|
||||||
}
|
}
|
||||||
@@ -164,4 +177,10 @@ public class ArtistListActivity extends AppCompatActivity {
|
|||||||
artistsList.addAll(artists);
|
artistsList.addAll(artists);
|
||||||
runOnUiThread(() -> artistsListAdapter.notifyDataSetChanged());
|
runOnUiThread(() -> artistsListAdapter.notifyDataSetChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void openWebLink(String url) {
|
||||||
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
|
intent.setData(Uri.parse(url));
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
android:id="@+id/lytBase"
|
android:id="@+id/lytBase"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context="com.hakodev.androiditunesapi.activities.ArtistListActivity"
|
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
android:focusableInTouchMode="true">
|
android:focusableInTouchMode="true"
|
||||||
|
tools:context="com.hakodev.androiditunesapi.activities.ArtistListActivity">
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/txtArtistSearch"
|
android:id="@+id/txtArtistSearch"
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<full-backup-content>
|
<full-backup-content>
|
||||||
<include domain="sharedpref" path="."/>
|
<include
|
||||||
|
domain="sharedpref"
|
||||||
|
path="." />
|
||||||
</full-backup-content>
|
</full-backup-content>
|
||||||
Reference in New Issue
Block a user