-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'system_prod' of https://github.com/dat911zz/CringeMPOne …
…into android_PhamLeXuanPhong � Conflicts: � app/src/main/AndroidManifest.xml � app/src/main/java/com/ltdd/cringempone/MainActivity.java
- Loading branch information
Showing
7 changed files
with
170 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
app/src/main/java/com/ltdd/cringempone/api/BaseAPIService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.ltdd.cringempone.api; | ||
|
||
import android.util.Log; | ||
|
||
public class BaseAPIService { | ||
private String hostAPI = "https://zingmp3api-dvn.onrender.com/"; | ||
private String LOG_TAG = "Base API Service"; | ||
public static BaseAPIService getInstance(){ | ||
return new BaseAPIService(); | ||
} | ||
public BaseAPIService() { | ||
} | ||
public String getRequest(String path){ | ||
HttpGetRequest httpGetRequest = new HttpGetRequest(); | ||
httpGetRequest.execute(hostAPI + path); | ||
try { | ||
Log.i("BaseAPI", httpGetRequest.get()); | ||
return httpGetRequest.get(); | ||
} catch (Exception e) { | ||
Log.e(LOG_TAG, "getRequest: " + e.getMessage()); | ||
return String.format("{\"err\":\"{0}\",\"mess:\":\"{1}\"}","404",e.getMessage()); | ||
} | ||
} | ||
public String getTop100(){ | ||
return getRequest("top100"); | ||
} | ||
public String getHome(){ | ||
return getRequest("Home"); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
app/src/main/java/com/ltdd/cringempone/api/HttpGetRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.ltdd.cringempone.api; | ||
|
||
import android.os.AsyncTask; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
|
||
public class HttpGetRequest extends AsyncTask<String, Void, String> { | ||
public static final String REQUEST_METHOD = "GET"; | ||
public static final int READ_TIMEOUT = 15000; | ||
public static final int CONNECTION_TIMEOUT = 15000; | ||
@Override | ||
protected String doInBackground(String... params){ | ||
String stringUrl = params[0]; | ||
String result; | ||
String inputLine; | ||
try { | ||
//Create a URL object holding our url | ||
URL myUrl = new URL(stringUrl); | ||
//Create a connection | ||
HttpURLConnection connection =(HttpURLConnection) | ||
myUrl.openConnection(); | ||
//Set methods and timeouts | ||
connection.setRequestMethod(REQUEST_METHOD); | ||
connection.setReadTimeout(READ_TIMEOUT); | ||
connection.setConnectTimeout(CONNECTION_TIMEOUT); | ||
|
||
//Connect to our url | ||
connection.connect(); | ||
//Create a new InputStreamReader | ||
InputStreamReader streamReader = new | ||
InputStreamReader(connection.getInputStream()); | ||
//Create a new buffered reader and String Builder | ||
BufferedReader reader = new BufferedReader(streamReader); | ||
StringBuilder stringBuilder = new StringBuilder(); | ||
//Check if the line we are reading is not null | ||
while((inputLine = reader.readLine()) != null){ | ||
stringBuilder.append(inputLine); | ||
} | ||
//Close our InputStream and Buffered reader | ||
reader.close(); | ||
streamReader.close(); | ||
//Set our result equal to our stringBuilder | ||
result = stringBuilder.toString(); | ||
} | ||
catch(IOException e){ | ||
e.printStackTrace(); | ||
result = null; | ||
} | ||
return result; | ||
} | ||
protected void onPostExecute(String result){ | ||
super.onPostExecute(result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.ltdd.cringempone.api; | ||
|
||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
|
||
import com.android.volley.Request; | ||
import com.android.volley.RequestQueue; | ||
import com.android.volley.Response; | ||
import com.android.volley.VolleyError; | ||
import com.android.volley.toolbox.StringRequest; | ||
import com.android.volley.toolbox.Volley; | ||
public class Zmp3API { | ||
static String URL_API = "https://zingmp3api-dvn.onrender.com/top100"; | ||
Context context; | ||
RequestQueue requestQueue; | ||
public Zmp3API(Context context) { | ||
this.context = context; | ||
requestQueue = Volley.newRequestQueue(context); | ||
} | ||
public void makeAPICall(){ | ||
String MyPREFERENCES = "MyPrefs"; | ||
SharedPreferences.Editor editor = context.getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE).edit(); | ||
|
||
Request request = new StringRequest(Request.Method.GET, URL_API, new Response.Listener<String>(){ | ||
@Override | ||
public void onResponse(String response) { | ||
editor.putString("returnResponse", response); | ||
editor.apply(); | ||
} | ||
}, new Response.ErrorListener() { | ||
@Override | ||
public void onErrorResponse(VolleyError error) { | ||
editor.putString("returnResponse", error.getMessage()); | ||
editor.apply(); | ||
} | ||
}); | ||
requestQueue.add(request); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../com/ltdd/cringempone/ui/MusicPlayer.java → .../cringempone/ui/activity/MusicPlayer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters