From 5fccd742b3e3a96124afc666383c95aac35468eb Mon Sep 17 00:00:00 2001 From: AsianPw Date: Tue, 1 Jan 2019 18:41:55 +0100 Subject: [PATCH] Cleanup Code --- app/build.gradle | 2 ++ .../epicture/ImgurApi/ImgurApi.java | 17 ++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f489169..1933741 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -74,6 +74,8 @@ dependencies { implementation 'com.google.android.exoplayer:exoplayer:2.9.3' + implementation 'net.gotev:uploadservice:3.4.2' + testImplementation 'junit:junit:4.12' implementation 'com.android.support:design:28.0.0' } diff --git a/app/src/main/java/brice_bastien/epicture/ImgurApi/ImgurApi.java b/app/src/main/java/brice_bastien/epicture/ImgurApi/ImgurApi.java index 5164cb6..1099dd6 100644 --- a/app/src/main/java/brice_bastien/epicture/ImgurApi/ImgurApi.java +++ b/app/src/main/java/brice_bastien/epicture/ImgurApi/ImgurApi.java @@ -15,6 +15,10 @@ import com.android.volley.toolbox.JsonObjectRequest; import com.android.volley.toolbox.Volley; +import net.gotev.uploadservice.MultipartUploadRequest; +import net.gotev.uploadservice.UploadNotificationConfig; +import net.gotev.uploadservice.UploadService; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -123,7 +127,7 @@ public void onResponse(NetworkResponse response) { request.addPart(new MultipartRequest.FormPart("comment", comment)); Log.i("post a comment", new String(request.getBody())); requestQueue.add(request); - }catch (Exception e) { + } catch (Exception e) { Log.w("post a comment:", "failed"); } } @@ -132,7 +136,7 @@ public void getComment(String id, CommentAdapter adapter) { SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); Boolean switchPref = sharedPrefs.getBoolean(SettingsActivity.KEY_PREF_COMMENTARY_NEW, false); - String url = host + "gallery/" + id + "/comments/" + (switchPref ? "new" : "best" ); + String url = host + "gallery/" + id + "/comments/" + (switchPref ? "new" : "best"); JsonObjectRequest request = new JsonRequest(Request.Method.GET, url, null, new ResponseCommentListener(adapter), new ErrorListener(adapter.statesRecyclerViewAdapter), clientId, token); requestQueue.add(request); @@ -201,7 +205,7 @@ public void getRecentImg(PostsFragment fragment, String section) { public void getUsrAvatar(ImageView img, String username) { String url = host + "account/" + username + "/avatar"; - JsonObjectRequest request = new JsonRequest(Request.Method.GET, url, null, new ResponseAvatarListener(context, img) , new ErrorListener(), clientId, token); + JsonObjectRequest request = new JsonRequest(Request.Method.GET, url, null, new ResponseAvatarListener(context, img), new ErrorListener(), clientId, token); requestQueue.add(request); } @@ -214,7 +218,7 @@ public void getUsrSetting(AccountSetting view) { } public void putUsrSetting(SettingItem settingItem) { - String url = host + "account/" + username +"/settings"; + String url = host + "account/" + username + "/settings"; HashMap headers = new HashMap<>(); headers.put("Authorization", "Bearer " + token); MultipartRequest request = new MultipartRequest(Request.Method.POST, url, headers, new Response.Listener() { @@ -231,13 +235,13 @@ public void onResponse(NetworkResponse response) { request.addPart(new MultipartRequest.FormPart("newsletter_subscribed", Boolean.toString(settingItem.isNewsletter()))); Log.i("saveSetting", new String(request.getBody())); requestQueue.add(request); - }catch (Exception e) { + } catch (Exception e) { Log.w("saveSetting:", e.toString()); } } public void editImage(boolean isAlbum, String id, String title, String description) { - String url = host + (isAlbum ? "album/" : "image/") + id; + String url = host + (isAlbum ? "album/" : "image/") + id; HashMap headers = new HashMap<>(); headers.put("Authorization", "Bearer " + token); @@ -284,7 +288,6 @@ public void onResponse(NetworkResponse response) { requestQueue.add(request); } catch (Exception e) { e.printStackTrace(); - Log.w("Upload", e.toString()); } }