From 3634e5e23288c303ab75abc42ccd5b709e48d019 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 24 Nov 2020 17:32:18 +0100 Subject: [PATCH] Some fixes --- app/src/acad/res/values/colors.xml | 1 + app/src/acad/res/values/strings.xml | 6 ++ app/src/full/res/values/colors.xml | 1 + app/src/full/res/values/strings.xml | 5 ++ .../app/fedilab/fedilabtube/MainActivity.java | 2 + .../fedilabtube/PeertubeUploadActivity.java | 55 ++++++++++++++++ .../fedilabtube/client/PeertubeService.java | 7 +++ .../client/RetrofitPeertubeAPI.java | 41 ++++++++++++ .../fedilabtube/client/data/InstanceData.java | 37 +++++++++++ .../fedilabtube/client/entities/UserMe.java | 35 +++++++++-- .../fedilab/fedilabtube/helper/Helper.java | 16 ++++- app/src/main/res/drawable/progress_bar.xml | 24 +++++++ .../res/layout/activity_peertube_upload.xml | 63 +++++++++++++++++++ 13 files changed, 286 insertions(+), 7 deletions(-) create mode 100644 app/src/main/res/drawable/progress_bar.xml diff --git a/app/src/acad/res/values/colors.xml b/app/src/acad/res/values/colors.xml index 0db596c..41d179b 100644 --- a/app/src/acad/res/values/colors.xml +++ b/app/src/acad/res/values/colors.xml @@ -10,4 +10,5 @@ #F44336 #DD000000 #F44336 + #80808080 \ No newline at end of file diff --git a/app/src/acad/res/values/strings.xml b/app/src/acad/res/values/strings.xml index 897dc22..f8578df 100644 --- a/app/src/acad/res/values/strings.xml +++ b/app/src/acad/res/values/strings.xml @@ -304,6 +304,12 @@ Moyenne Faible + + Illimité + Mo + Go + Total du quota vidéo + Quota vidéo journalier Contenu explicite ou sensible Cette vidéo contient du contenu sensible. Êtes-vous sûr·e de vouloir la regarder ? Lecture automatique diff --git a/app/src/full/res/values/colors.xml b/app/src/full/res/values/colors.xml index 0cf97a5..8d944f0 100644 --- a/app/src/full/res/values/colors.xml +++ b/app/src/full/res/values/colors.xml @@ -9,4 +9,5 @@ #F44336 #DD000000 #F44336 + #80808080 \ No newline at end of file diff --git a/app/src/full/res/values/strings.xml b/app/src/full/res/values/strings.xml index 1fa8b3d..b190628 100644 --- a/app/src/full/res/values/strings.xml +++ b/app/src/full/res/values/strings.xml @@ -160,6 +160,11 @@ Mute + Unlimited + MB + GB + Total video quota + Daily video quota Mature or explicit content This video contains mature or explicit content. Are you sure you want to watch it? diff --git a/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java b/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java index 32e11fd..8c477ac 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java @@ -85,6 +85,7 @@ public class MainActivity extends AppCompatActivity { public static int PICK_INSTANCE = 5641; public static int PICK_INSTANCE_SURF = 5642; public static UserMe userMe; + public static InstanceData.InstanceConfig instanceConfig; public static TypeOfConnection typeOfConnection; final FragmentManager fm = getSupportFragmentManager(); Fragment active; @@ -337,6 +338,7 @@ public class MainActivity extends AppCompatActivity { editor.apply(); } } + instanceConfig = new RetrofitPeertubeAPI(MainActivity.this).getConfigInstance(); } catch (Error error) { runOnUiThread(() -> Helper.logoutCurrentUser(MainActivity.this, finalAccount)); error.printStackTrace(); diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeUploadActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeUploadActivity.java index 9b6c3dd..1af05cd 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeUploadActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeUploadActivity.java @@ -23,6 +23,7 @@ import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.graphics.Color; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.view.MenuItem; import android.view.View; @@ -49,15 +50,19 @@ import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import app.fedilab.fedilabtube.client.APIResponse; +import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI; import app.fedilab.fedilabtube.client.data.ChannelData; +import app.fedilab.fedilabtube.client.entities.UserMe; import app.fedilab.fedilabtube.databinding.ActivityPeertubeUploadBinding; import app.fedilab.fedilabtube.helper.Helper; import app.fedilab.fedilabtube.viewmodel.ChannelsVM; import es.dmoral.toasty.Toasty; +import static app.fedilab.fedilabtube.MainActivity.userMe; import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.DataType.MY_CHANNELS; import static app.fedilab.fedilabtube.helper.Helper.peertubeInformation; @@ -86,6 +91,56 @@ public class PeertubeUploadActivity extends AppCompatActivity { setContentView(view); + new Thread(() -> { + UserMe.VideoQuota videoQuotaReply = new RetrofitPeertubeAPI(PeertubeUploadActivity.this).getVideoQuota(); + runOnUiThread(() -> { + if (videoQuotaReply != null) { + long videoQuota = videoQuotaReply.getVideoQuotaUsed(); + long dailyQuota = videoQuotaReply.getVideoQuotaUsedDaily(); + long instanceVideoQuota = userMe.getVideoQuota(); + long instanceDailyQuota = userMe.getVideoQuotaDaily(); + + if (instanceVideoQuota != -1) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + binding.totalQuota.setProgress((int) (videoQuota * 100 / instanceVideoQuota), true); + } else { + binding.totalQuota.setProgress((int) (videoQuota * 100 / instanceVideoQuota)); + } + } else { + int progress = videoQuota > 0 ? 30 : 0; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + binding.totalQuota.setProgress(progress, true); + } else { + binding.totalQuota.setProgress(progress); + } + } + if (instanceDailyQuota != -1) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + binding.dailyQuota.setProgress((int) (dailyQuota * 100 / instanceDailyQuota), true); + } else { + binding.dailyQuota.setProgress((int) (dailyQuota * 100 / instanceDailyQuota)); + } + } else { + int progress = dailyQuota > 0 ? 30 : 0; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + binding.dailyQuota.setProgress(progress, true); + } else { + binding.dailyQuota.setProgress(progress); + } + } + binding.totalQuotaValue.setText( + String.format(Locale.getDefault(), "%s/%s", + Helper.returnRoundedSize(PeertubeUploadActivity.this, videoQuota), + Helper.returnRoundedSize(PeertubeUploadActivity.this, instanceVideoQuota))); + binding.dailyQuotaValue.setText( + String.format(Locale.getDefault(), "%s/%s", + Helper.returnRoundedSize(PeertubeUploadActivity.this, dailyQuota), + Helper.returnRoundedSize(PeertubeUploadActivity.this, instanceDailyQuota))); + } + }); + }).start(); + + ChannelsVM viewModelC = new ViewModelProvider(PeertubeUploadActivity.this).get(ChannelsVM.class); viewModelC.get(MY_CHANNELS, null).observe(PeertubeUploadActivity.this, this::manageVIewChannels); channels = new HashMap<>(); diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeService.java b/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeService.java index e2a3221..b240da3 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeService.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeService.java @@ -70,6 +70,10 @@ public interface PeertubeService { @GET("config/about") Call configAbout(); + //Instance config + @GET("config") + Call config(); + @GET("{nodeInfoPath}") Call getNodeinfo(@Path(value = "nodeInfoPath", encoded = true) String nodeInfoPath); @@ -120,6 +124,9 @@ public interface PeertubeService { Call verifyCredentials(@Header("Authorization") String credentials); + @GET("users/me/video-quota-used") + Call getVideoQuota(@Header("Authorization") String credentials); + @FormUrlEncoded @PUT("videos/{id}/watching") Call addToHistory( diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java b/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java index 2aaca53..ee4ecbb 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java @@ -677,6 +677,47 @@ public class RetrofitPeertubeAPI { return null; } + /** + * Config of the instance + * + * @return InstanceConfig + */ + public InstanceData.InstanceConfig getConfigInstance() { + + PeertubeService peertubeService = init(); + Call config = peertubeService.config(); + try { + Response response = config.execute(); + if (response.isSuccessful() && response.body() != null) { + return response.body(); + } + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + + /** + * Get video quota + * + * @return UserMe.VideoQuota + */ + public UserMe.VideoQuota getVideoQuota() { + + PeertubeService peertubeService = init(); + Call videoQuotaCall = peertubeService.getVideoQuota(getToken()); + try { + Response response = videoQuotaCall.execute(); + if (response.isSuccessful() && response.body() != null) { + return response.body(); + } + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + /** * Returns informations about Peertube such privacies, licenses, etc. * diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/data/InstanceData.java b/app/src/main/java/app/fedilab/fedilabtube/client/data/InstanceData.java index 59eff4c..e864958 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/data/InstanceData.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/data/InstanceData.java @@ -343,5 +343,42 @@ public class InstanceData { parcel.writeString(host); } } + + + public static class InstanceConfig { + @SerializedName("user") + private User user; + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + } + + public static class User { + @SerializedName("videoQuota") + private long videoQuota; + @SerializedName("videoQuotaDaily") + private long videoQuotaDaily; + + public long getVideoQuota() { + return videoQuota; + } + + public void setVideoQuota(long videoQuota) { + this.videoQuota = videoQuota; + } + + public long getVideoQuotaDaily() { + return videoQuotaDaily; + } + + public void setVideoQuotaDaily(long videoQuotaDaily) { + this.videoQuotaDaily = videoQuotaDaily; + } + } } diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/entities/UserMe.java b/app/src/main/java/app/fedilab/fedilabtube/client/entities/UserMe.java index 7e2656d..5d0d034 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/entities/UserMe.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/entities/UserMe.java @@ -66,9 +66,9 @@ public class UserMe { @SerializedName("videoLanguages") private List videoLanguages; @SerializedName("videoQuota") - private String videoQuota; + private long videoQuota; @SerializedName("videoQuotaDaily") - private String videoQuotaDaily; + private long videoQuotaDaily; @SerializedName("videosHistoryEnabled") private boolean videosHistoryEnabled; @SerializedName("webTorrentEnabled") @@ -226,19 +226,19 @@ public class UserMe { this.videoLanguages = videoLanguages; } - public String getVideoQuota() { + public long getVideoQuota() { return videoQuota; } - public void setVideoQuota(String videoQuota) { + public void setVideoQuota(long videoQuota) { this.videoQuota = videoQuota; } - public String getVideoQuotaDaily() { + public long getVideoQuotaDaily() { return videoQuotaDaily; } - public void setVideoQuotaDaily(String videoQuotaDaily) { + public void setVideoQuotaDaily(long videoQuotaDaily) { this.videoQuotaDaily = videoQuotaDaily; } @@ -279,4 +279,27 @@ public class UserMe { this.avatar = avatar; } } + + public static class VideoQuota { + @SerializedName("videoQuotaUsed") + private long videoQuotaUsed; + @SerializedName("videoQuotaUsedDaily") + private long videoQuotaUsedDaily; + + public long getVideoQuotaUsed() { + return videoQuotaUsed; + } + + public void setVideoQuotaUsed(long videoQuotaUsed) { + this.videoQuotaUsed = videoQuotaUsed; + } + + public long getVideoQuotaUsedDaily() { + return videoQuotaUsedDaily; + } + + public void setVideoQuotaUsedDaily(long videoQuotaUsedDaily) { + this.videoQuotaUsedDaily = videoQuotaUsedDaily; + } + } } diff --git a/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java b/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java index da057bb..01e0b03 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java +++ b/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java @@ -53,6 +53,7 @@ import com.bumptech.glide.request.RequestOptions; import java.net.InetAddress; import java.text.DateFormat; +import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; @@ -123,7 +124,6 @@ public class Helper { public static final String PREF_KEY_ID = "userID"; public static final String PREF_KEY_NAME = "my_user_name"; public static final String PREF_INSTANCE = "instance"; - public static final String PREF_INSTANCE_SURF = "instance_surf"; public static final int EXTERNAL_STORAGE_REQUEST_CODE = 84; public static final String SET_VIDEOS_PER_PAGE = "set_videos_per_page"; public static final String VIDEO_ID = "video_id_update"; @@ -794,4 +794,18 @@ public class Helper { return false; } } + + public static String returnRoundedSize(Context context, long size) { + if (size == -1) { + return context.getString(R.string.unlimited); + } else if (size > 1000000000) { + float rounded = (float) size / 1000000000; + DecimalFormat df = new DecimalFormat("#.#"); + return String.format(Locale.getDefault(), "%s%s", df.format(rounded), context.getString(R.string.gb)); + } else { + float rounded = (float) size / 1000000; + DecimalFormat df = new DecimalFormat("#.#"); + return String.format(Locale.getDefault(), "%s%s", df.format(rounded), context.getString(R.string.mb)); + } + } } diff --git a/app/src/main/res/drawable/progress_bar.xml b/app/src/main/res/drawable/progress_bar.xml new file mode 100644 index 0000000..0449550 --- /dev/null +++ b/app/src/main/res/drawable/progress_bar.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_peertube_upload.xml b/app/src/main/res/layout/activity_peertube_upload.xml index 29d023e..d7f1269 100644 --- a/app/src/main/res/layout/activity_peertube_upload.xml +++ b/app/src/main/res/layout/activity_peertube_upload.xml @@ -26,7 +26,70 @@ android:layout_marginTop="50dp" android:orientation="vertical"> + + + + + + + + + + + + + + + + + + +