Some fixes
This commit is contained in:
parent
f7d44cb547
commit
3634e5e232
|
@ -10,4 +10,5 @@
|
|||
<color name="negative_thumbs">#F44336</color>
|
||||
<color name="backgroundDark">#DD000000</color>
|
||||
<color name="red_1">#F44336</color>
|
||||
<color name="gray_light">#80808080</color>
|
||||
</resources>
|
|
@ -304,6 +304,12 @@
|
|||
<item>Moyenne</item>
|
||||
<item>Faible</item>
|
||||
</string-array>
|
||||
|
||||
<string name="unlimited">Illimité</string>
|
||||
<string name="mb">Mo</string>
|
||||
<string name="gb">Go</string>
|
||||
<string name="total_video_quota">Total du quota vidéo</string>
|
||||
<string name="daily_video_quota">Quota vidéo journalier</string>
|
||||
<string name="nsfw_title_warning">Contenu explicite ou sensible</string>
|
||||
<string name="nsfw_message_warning">Cette vidéo contient du contenu sensible. Êtes-vous sûr·e de vouloir la regarder ?</string>
|
||||
<string name="set_autoplay_next_video_settings">Lecture automatique</string>
|
||||
|
|
|
@ -9,4 +9,5 @@
|
|||
<color name="negative_thumbs">#F44336</color>
|
||||
<color name="backgroundDark">#DD000000</color>
|
||||
<color name="red_1">#F44336</color>
|
||||
<color name="gray_light">#80808080</color>
|
||||
</resources>
|
|
@ -160,6 +160,11 @@
|
|||
|
||||
<string name="action_mute">Mute</string>
|
||||
|
||||
<string name="unlimited">Unlimited</string>
|
||||
<string name="mb">MB</string>
|
||||
<string name="gb">GB</string>
|
||||
<string name="total_video_quota">Total video quota</string>
|
||||
<string name="daily_video_quota">Daily video quota</string>
|
||||
|
||||
<string name="nsfw_title_warning">Mature or explicit content</string>
|
||||
<string name="nsfw_message_warning">This video contains mature or explicit content. Are you sure you want to watch it?</string>
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<>();
|
||||
|
|
|
@ -70,6 +70,10 @@ public interface PeertubeService {
|
|||
@GET("config/about")
|
||||
Call<InstanceData.InstanceInfo> configAbout();
|
||||
|
||||
//Instance config
|
||||
@GET("config")
|
||||
Call<InstanceData.InstanceConfig> config();
|
||||
|
||||
@GET("{nodeInfoPath}")
|
||||
Call<WellKnownNodeinfo.NodeInfo> getNodeinfo(@Path(value = "nodeInfoPath", encoded = true) String nodeInfoPath);
|
||||
|
||||
|
@ -120,6 +124,9 @@ public interface PeertubeService {
|
|||
Call<UserMe> verifyCredentials(@Header("Authorization") String credentials);
|
||||
|
||||
|
||||
@GET("users/me/video-quota-used")
|
||||
Call<UserMe.VideoQuota> getVideoQuota(@Header("Authorization") String credentials);
|
||||
|
||||
@FormUrlEncoded
|
||||
@PUT("videos/{id}/watching")
|
||||
Call<String> addToHistory(
|
||||
|
|
|
@ -677,6 +677,47 @@ public class RetrofitPeertubeAPI {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Config of the instance
|
||||
*
|
||||
* @return InstanceConfig
|
||||
*/
|
||||
public InstanceData.InstanceConfig getConfigInstance() {
|
||||
|
||||
PeertubeService peertubeService = init();
|
||||
Call<InstanceData.InstanceConfig> config = peertubeService.config();
|
||||
try {
|
||||
Response<InstanceData.InstanceConfig> 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<UserMe.VideoQuota> videoQuotaCall = peertubeService.getVideoQuota(getToken());
|
||||
try {
|
||||
Response<UserMe.VideoQuota> 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.
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -66,9 +66,9 @@ public class UserMe {
|
|||
@SerializedName("videoLanguages")
|
||||
private List<String> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@android:id/background">
|
||||
<shape>
|
||||
<corners android:radius="8dp" />
|
||||
<solid android:color="@color/gray_light" />
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@android:id/progress"
|
||||
android:bottom="1dp"
|
||||
android:left="1dp"
|
||||
android:right="1dp"
|
||||
android:top="1dp">
|
||||
|
||||
<scale android:scaleWidth="100%">
|
||||
<shape>
|
||||
<corners android:radius="8dp" />
|
||||
<solid android:color="@color/colorAccent" />
|
||||
</shape>
|
||||
</scale>
|
||||
</item>
|
||||
</layer-list>
|
|
@ -26,7 +26,70 @@
|
|||
android:layout_marginTop="50dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:labelFor="@+id/total_quota"
|
||||
android:text="@string/total_video_quota" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/total_quota_value"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/total_quota"
|
||||
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
|
||||
android:layout_width="300dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="10dp"
|
||||
android:indeterminate="false"
|
||||
android:max="100"
|
||||
android:progressDrawable="@drawable/progress_bar" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:labelFor="@+id/daily_quota"
|
||||
android:text="@string/daily_video_quota" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/daily_quota_value"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/daily_quota"
|
||||
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
|
||||
android:layout_width="300dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="10dp"
|
||||
android:indeterminate="false"
|
||||
android:max="100"
|
||||
android:progressDrawable="@drawable/progress_bar" />
|
||||
|
||||
<Button
|
||||
android:layout_marginTop="20dp"
|
||||
android:id="@+id/set_upload_file"
|
||||
style="@style/Base.Widget.AppCompat.Button.Colored"
|
||||
android:layout_width="wrap_content"
|
||||
|
|
Loading…
Reference in New Issue