Allow to change thumbnail for Playlists

This commit is contained in:
Thomas 2020-11-28 17:56:16 +01:00
parent 3a8c82ce63
commit 6ae42ffefe
6 changed files with 135 additions and 61 deletions

View File

@ -11,8 +11,8 @@ android {
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 30 targetSdkVersion 30
versionCode 28 versionCode 29
versionName "1.9.0-beta-1" versionName "1.9.0"
multiDexEnabled true multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }

View File

@ -2,11 +2,14 @@ Added:
- Allow to search channels - Allow to search channels
- Show storage quota - Show storage quota
- Warning on Playing NSFW videos - Warning on Playing NSFW videos
- Swipe to change timelines
Changed: Changed:
- Improve comment threads - Improve comment threads
- Comment composer in full-screen
- Swipe to change timeline - Swipe to change timeline
Fixed: Fixed:
- Status bar for fullscreen not removed - Status bar for fullscreen not removed
- Filter for subscriptions not working with remote accounts
- Some crashes - Some crashes

View File

@ -14,7 +14,12 @@ package app.fedilab.fedilabtube;
* You should have received a copy of the GNU General Public License along with TubeLab; if not, * You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import android.Manifest;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
@ -27,19 +32,19 @@ import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.Toast; import android.widget.Toast;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -54,11 +59,15 @@ import app.fedilab.fedilabtube.client.data.ChannelData;
import app.fedilab.fedilabtube.client.data.PlaylistData.Playlist; import app.fedilab.fedilabtube.client.data.PlaylistData.Playlist;
import app.fedilab.fedilabtube.client.entities.Item; import app.fedilab.fedilabtube.client.entities.Item;
import app.fedilab.fedilabtube.client.entities.PlaylistParams; import app.fedilab.fedilabtube.client.entities.PlaylistParams;
import app.fedilab.fedilabtube.databinding.ActivityAllPlaylistBinding;
import app.fedilab.fedilabtube.databinding.AddPlaylistBinding;
import app.fedilab.fedilabtube.drawer.PlaylistAdapter; import app.fedilab.fedilabtube.drawer.PlaylistAdapter;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.viewmodel.ChannelsVM; import app.fedilab.fedilabtube.viewmodel.ChannelsVM;
import app.fedilab.fedilabtube.viewmodel.PlaylistsVM; import app.fedilab.fedilabtube.viewmodel.PlaylistsVM;
import es.dmoral.toasty.Toasty; import es.dmoral.toasty.Toasty;
import static app.fedilab.fedilabtube.PeertubeUploadActivity.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE;
import static app.fedilab.fedilabtube.helper.Helper.peertubeInformation; import static app.fedilab.fedilabtube.helper.Helper.peertubeInformation;
@ -66,40 +75,37 @@ public class AllPlaylistsActivity extends AppCompatActivity implements PlaylistA
PlaylistAdapter playlistAdapter; PlaylistAdapter playlistAdapter;
private RelativeLayout mainLoader;
private RelativeLayout textviewNoAction;
private HashMap<Integer, String> privacyToSend; private HashMap<Integer, String> privacyToSend;
private Spinner set_upload_channel;
private Spinner set_upload_privacy;
private String idChannel; private String idChannel;
private List<Playlist> playlists; private List<Playlist> playlists;
private Playlist playlistToEdit; private Playlist playlistToEdit;
private List<ChannelData.Channel> myChannels; private List<ChannelData.Channel> myChannels;
private ChannelData.Channel selectedChannel; private ChannelData.Channel selectedChannel;
private static final int PICK_AVATAR = 467;
private AddPlaylistBinding bindingDialog;
private Uri inputData;
private ActivityAllPlaylistBinding binding;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_all_playlist); binding = ActivityAllPlaylistBinding.inflate(getLayoutInflater());
View viewRoot = binding.getRoot();
setContentView(viewRoot);
if (getSupportActionBar() != null) if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setTitle(R.string.playlists); setTitle(R.string.playlists);
textviewNoAction = findViewById(R.id.no_action); binding.loader.setVisibility(View.VISIBLE);
mainLoader = findViewById(R.id.loader); binding.loadingNextItems.setVisibility(View.GONE);
RelativeLayout nextElementLoader = findViewById(R.id.loading_next_items);
mainLoader.setVisibility(View.VISIBLE);
nextElementLoader.setVisibility(View.GONE);
idChannel = null; idChannel = null;
PlaylistsVM viewModel = new ViewModelProvider(AllPlaylistsActivity.this).get(PlaylistsVM.class); PlaylistsVM viewModel = new ViewModelProvider(AllPlaylistsActivity.this).get(PlaylistsVM.class);
viewModel.manage(PlaylistsVM.action.GET_PLAYLISTS, null, null).observe(AllPlaylistsActivity.this, apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_PLAYLISTS, apiResponse)); viewModel.manage(PlaylistsVM.action.GET_PLAYLISTS, null, null).observe(AllPlaylistsActivity.this, apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_PLAYLISTS, apiResponse));
FloatingActionButton add_new = findViewById(R.id.add_new);
LinkedHashMap<Integer, String> privaciesInit = new LinkedHashMap<>(peertubeInformation.getPrivacies()); LinkedHashMap<Integer, String> privaciesInit = new LinkedHashMap<>(peertubeInformation.getPrivacies());
if (privaciesInit.size() > 0) { if (privaciesInit.size() > 0) {
@ -110,13 +116,12 @@ public class AllPlaylistsActivity extends AppCompatActivity implements PlaylistA
playlists = new ArrayList<>(); playlists = new ArrayList<>();
RecyclerView lv_playlist = findViewById(R.id.lv_playlist);
playlistAdapter = new PlaylistAdapter(playlists, false); playlistAdapter = new PlaylistAdapter(playlists, false);
playlistAdapter.allPlaylistRemoved = this; playlistAdapter.allPlaylistRemoved = this;
lv_playlist.setAdapter(playlistAdapter); binding.lvPlaylist.setAdapter(playlistAdapter);
LinearLayoutManager mLayoutManager = new LinearLayoutManager(AllPlaylistsActivity.this); LinearLayoutManager mLayoutManager = new LinearLayoutManager(AllPlaylistsActivity.this);
lv_playlist.setLayoutManager(mLayoutManager); binding.lvPlaylist.setLayoutManager(mLayoutManager);
add_new.setOnClickListener(view -> manageAlert(null)); binding.addNew.setOnClickListener(view -> manageAlert(null));
} }
@Override @Override
@ -135,7 +140,7 @@ public class AllPlaylistsActivity extends AppCompatActivity implements PlaylistA
public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) { public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) {
mainLoader.setVisibility(View.GONE); binding.loader.setVisibility(View.GONE);
if (apiResponse.getError() != null) { if (apiResponse.getError() != null) {
Toasty.error(AllPlaylistsActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); Toasty.error(AllPlaylistsActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
return; return;
@ -144,9 +149,9 @@ public class AllPlaylistsActivity extends AppCompatActivity implements PlaylistA
if (apiResponse.getPlaylists() != null && apiResponse.getPlaylists().size() > 0) { if (apiResponse.getPlaylists() != null && apiResponse.getPlaylists().size() > 0) {
playlists.addAll(apiResponse.getPlaylists()); playlists.addAll(apiResponse.getPlaylists());
playlistAdapter.notifyDataSetChanged(); playlistAdapter.notifyDataSetChanged();
textviewNoAction.setVisibility(View.GONE); binding.noAction.setVisibility(View.GONE);
} else { } else {
textviewNoAction.setVisibility(View.VISIBLE); binding.noAction.setVisibility(View.VISIBLE);
} }
} }
} }
@ -155,37 +160,53 @@ public class AllPlaylistsActivity extends AppCompatActivity implements PlaylistA
playlistToEdit = playlistParam; playlistToEdit = playlistParam;
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(AllPlaylistsActivity.this); AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(AllPlaylistsActivity.this);
LayoutInflater inflater1 = getLayoutInflater(); bindingDialog = AddPlaylistBinding.inflate(LayoutInflater.from(AllPlaylistsActivity.this), null, false);
View dialogView = inflater1.inflate(R.layout.add_playlist, new LinearLayout(AllPlaylistsActivity.this), false); dialogBuilder.setView(bindingDialog.getRoot());
dialogBuilder.setView(dialogView);
EditText display_name = dialogView.findViewById(R.id.display_name); dialogBuilder.setView(bindingDialog.getRoot());
EditText description = dialogView.findViewById(R.id.description);
set_upload_channel = dialogView.findViewById(R.id.set_upload_channel);
set_upload_privacy = dialogView.findViewById(R.id.set_upload_privacy);
ChannelsVM viewModelC = new ViewModelProvider(AllPlaylistsActivity.this).get(ChannelsVM.class); ChannelsVM viewModelC = new ViewModelProvider(AllPlaylistsActivity.this).get(ChannelsVM.class);
viewModelC.get(RetrofitPeertubeAPI.DataType.MY_CHANNELS, null).observe(AllPlaylistsActivity.this, this::manageVIewChannels); viewModelC.get(RetrofitPeertubeAPI.DataType.MY_CHANNELS, null).observe(AllPlaylistsActivity.this, this::manageVIewChannels);
display_name.setFilters(new InputFilter[]{new InputFilter.LengthFilter(120)}); bindingDialog.displayName.setFilters(new InputFilter[]{new InputFilter.LengthFilter(120)});
description.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1000)}); bindingDialog.description.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1000)});
if (playlistToEdit != null) { if (playlistToEdit != null) {
display_name.setText(playlistToEdit.getDisplayName()); bindingDialog.displayName.setText(playlistToEdit.getDisplayName());
description.setText(playlistToEdit.getDescription()); bindingDialog.description.setText(playlistToEdit.getDescription());
} }
dialogBuilder.setPositiveButton(R.string.validate, null); dialogBuilder.setPositiveButton(R.string.validate, null);
dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss()); dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
AlertDialog alertDialog = dialogBuilder.create(); AlertDialog alertDialog = dialogBuilder.create();
bindingDialog.selectFile.setOnClickListener(v -> {
if (ContextCompat.checkSelfPermission(AllPlaylistsActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(AllPlaylistsActivity.this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
return;
}
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
String[] mimetypes = {"image/*"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
startActivityForResult(intent, PICK_AVATAR);
});
Helper.loadGiF(AllPlaylistsActivity.this, playlistParam.getThumbnailPath(), bindingDialog.profilePicture);
alertDialog.setOnShowListener(dialogInterface -> { alertDialog.setOnShowListener(dialogInterface -> {
Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE); Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
button.setOnClickListener(view -> { button.setOnClickListener(view -> {
if (display_name.getText() != null && display_name.getText().toString().trim().length() > 0) { if (bindingDialog.displayName.getText() != null && bindingDialog.displayName.getText().toString().trim().length() > 0) {
PlaylistParams playlistElement = new PlaylistParams(); PlaylistParams playlistElement = new PlaylistParams();
playlistElement.setDisplayName(display_name.getText().toString().trim()); playlistElement.setDisplayName(bindingDialog.displayName.getText().toString().trim());
if (description.getText() != null && description.getText().toString().trim().length() > 0) { if (bindingDialog.description.getText() != null && bindingDialog.description.getText().toString().trim().length() > 0) {
playlistElement.setDescription(description.getText().toString().trim()); playlistElement.setDescription(bindingDialog.description.getText().toString().trim());
} }
playlistElement.setVideoChannelId(idChannel); playlistElement.setVideoChannelId(idChannel);
String label; String label;
@ -203,11 +224,11 @@ public class AllPlaylistsActivity extends AppCompatActivity implements PlaylistA
new Thread(() -> { new Thread(() -> {
String playlistId; String playlistId;
if (playlistToEdit == null) { if (playlistToEdit == null) {
APIResponse apiResponse = new RetrofitPeertubeAPI(AllPlaylistsActivity.this).createOrUpdatePlaylist(PlaylistsVM.action.CREATE_PLAYLIST, null, playlistElement, null); APIResponse apiResponse = new RetrofitPeertubeAPI(AllPlaylistsActivity.this).createOrUpdatePlaylist(PlaylistsVM.action.CREATE_PLAYLIST, null, playlistElement, inputData);
playlistId = apiResponse.getActionReturn(); playlistId = apiResponse.getActionReturn();
} else { } else {
playlistId = playlistToEdit.getId(); playlistId = playlistToEdit.getId();
new RetrofitPeertubeAPI(AllPlaylistsActivity.this).createOrUpdatePlaylist(PlaylistsVM.action.UPDATE_PLAYLIST, playlistId, playlistElement, null); new RetrofitPeertubeAPI(AllPlaylistsActivity.this).createOrUpdatePlaylist(PlaylistsVM.action.UPDATE_PLAYLIST, playlistId, playlistElement, inputData);
} }
Handler mainHandler = new Handler(Looper.getMainLooper()); Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> { Runnable myRunnable = () -> {
@ -247,7 +268,7 @@ public class AllPlaylistsActivity extends AppCompatActivity implements PlaylistA
//Hide keyboard //Hide keyboard
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
assert imm != null; assert imm != null;
imm.hideSoftInputFromWindow(display_name.getWindowToken(), 0); imm.hideSoftInputFromWindow(bindingDialog.displayName.getWindowToken(), 0);
}); });
if (alertDialog.getWindow() != null) if (alertDialog.getWindow() != null)
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
@ -255,6 +276,24 @@ public class AllPlaylistsActivity extends AppCompatActivity implements PlaylistA
} }
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_AVATAR && resultCode == Activity.RESULT_OK) {
if (data == null || data.getData() == null) {
Toasty.error(AllPlaylistsActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show();
return;
}
inputData = data.getData();
Glide.with(AllPlaylistsActivity.this)
.load(inputData)
.thumbnail(0.1f)
.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(10)))
.into(bindingDialog.profilePicture);
}
}
public void manageVIewChannels(APIResponse apiResponse) { public void manageVIewChannels(APIResponse apiResponse) {
if (apiResponse.getError() != null || apiResponse.getChannels() == null || apiResponse.getChannels().size() == 0) { if (apiResponse.getError() != null || apiResponse.getChannels() == null || apiResponse.getChannels().size() == 0) {
if (apiResponse.getError() != null && apiResponse.getError().getError() != null) if (apiResponse.getError() != null && apiResponse.getError().getError() != null)
@ -280,7 +319,7 @@ public class AllPlaylistsActivity extends AppCompatActivity implements PlaylistA
ArrayAdapter<String> adapterChannel = new ArrayAdapter<>(AllPlaylistsActivity.this, ArrayAdapter<String> adapterChannel = new ArrayAdapter<>(AllPlaylistsActivity.this,
android.R.layout.simple_spinner_dropdown_item, channelName); android.R.layout.simple_spinner_dropdown_item, channelName);
set_upload_channel.setAdapter(adapterChannel); bindingDialog.setUploadChannel.setAdapter(adapterChannel);
LinkedHashMap<String, String> translations = null; LinkedHashMap<String, String> translations = null;
@ -308,19 +347,19 @@ public class AllPlaylistsActivity extends AppCompatActivity implements PlaylistA
ArrayAdapter<String> adapterPrivacies = new ArrayAdapter<>(AllPlaylistsActivity.this, ArrayAdapter<String> adapterPrivacies = new ArrayAdapter<>(AllPlaylistsActivity.this,
android.R.layout.simple_spinner_dropdown_item, privaciesA); android.R.layout.simple_spinner_dropdown_item, privaciesA);
set_upload_privacy.setAdapter(adapterPrivacies); bindingDialog.setUploadPrivacy.setAdapter(adapterPrivacies);
if (playlistToEdit != null) { if (playlistToEdit != null) {
Item privacy = playlistToEdit.getPrivacy(); Item privacy = playlistToEdit.getPrivacy();
if (privacy.getId() > 0) { if (privacy.getId() > 0) {
set_upload_privacy.setSelection(privacy.getId() - 1); bindingDialog.setUploadPrivacy.setSelection(privacy.getId() - 1);
} }
} else { } else {
set_upload_privacy.setSelection(2); bindingDialog.setUploadPrivacy.setSelection(2);
} }
//Manage privacies //Manage privacies
set_upload_privacy.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { bindingDialog.setUploadPrivacy.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
LinkedHashMap<Integer, String> privaciesCheck = new LinkedHashMap<>(peertubeInformation.getPrivacies()); LinkedHashMap<Integer, String> privaciesCheck = new LinkedHashMap<>(peertubeInformation.getPrivacies());
@ -348,12 +387,12 @@ public class AllPlaylistsActivity extends AppCompatActivity implements PlaylistA
Item privacy = playlistToEdit.getPrivacy(); Item privacy = playlistToEdit.getPrivacy();
if (privacy.getId() > 0) { if (privacy.getId() > 0) {
set_upload_privacy.setSelection(privacy.getId() - 1); bindingDialog.setUploadPrivacy.setSelection(privacy.getId() - 1);
} }
} }
//Manage languages //Manage languages
set_upload_channel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { bindingDialog.setUploadChannel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
idChannel = channelId[position]; idChannel = channelId[position];
@ -378,12 +417,12 @@ public class AllPlaylistsActivity extends AppCompatActivity implements PlaylistA
} }
k++; k++;
} }
set_upload_channel.setSelection(position); bindingDialog.setUploadChannel.setSelection(position);
} }
} }
@Override @Override
public void onAllPlaylistRemoved() { public void onAllPlaylistRemoved() {
textviewNoAction.setVisibility(View.VISIBLE); binding.noAction.setVisibility(View.VISIBLE);
} }
} }

View File

@ -398,7 +398,6 @@ public class MainActivity extends AppCompatActivity {
}).start(); }).start();
} }
@Override @Override
public boolean onCreateOptionsMenu(@NotNull Menu menu) { public boolean onCreateOptionsMenu(@NotNull Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu); getMenuInflater().inflate(R.menu.main_menu, menu);

View File

@ -31,7 +31,6 @@ import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
@ -1446,21 +1445,31 @@ public class RetrofitPeertubeAPI {
* @param playlistParams PlaylistParams * @param playlistParams PlaylistParams
* @return APIResponse * @return APIResponse
*/ */
public APIResponse createOrUpdatePlaylist(PlaylistsVM.action apiAction, String playlistId, PlaylistParams playlistParams, File thumbnail) { public APIResponse createOrUpdatePlaylist(PlaylistsVM.action apiAction, String playlistId, PlaylistParams playlistParams, Uri thumbnail) {
PeertubeService peertubeService = init(); PeertubeService peertubeService = init();
APIResponse apiResponse = new APIResponse(); APIResponse apiResponse = new APIResponse();
MultipartBody.Part body = null; MultipartBody.Part body = null;
MultipartBody.Part bodyThumbnail = null;
if (thumbnail != null) { if (thumbnail != null) {
RequestBody requestFile = RequestBody.create(thumbnail, MediaType.parse("multipart/form-data")); DocumentFile documentFile = DocumentFile.fromSingleUri(_context, thumbnail);
body = MultipartBody.Part.createFormData("image", thumbnail.getName(), requestFile); String avatarfileName = null;
if (documentFile != null) {
avatarfileName = documentFile.getName();
}
try {
bodyThumbnail = createFile("thumbnailfile", thumbnail, avatarfileName);
} catch (IOException e) {
e.printStackTrace();
}
} }
try { try {
RequestBody displayName = RequestBody.create(playlistParams.getDisplayName(), MediaType.parse("text/plain")); RequestBody displayName = RequestBody.create(playlistParams.getDisplayName(), MediaType.parse("text/plain"));
RequestBody description = RequestBody.create(playlistParams.getDescription(), MediaType.parse("text/plain")); RequestBody description = RequestBody.create(playlistParams.getDescription(), MediaType.parse("text/plain"));
RequestBody channelId = RequestBody.create(playlistParams.getVideoChannelId(), MediaType.parse("text/plain")); RequestBody channelId = RequestBody.create(playlistParams.getVideoChannelId(), MediaType.parse("text/plain"));
if (apiAction == PlaylistsVM.action.CREATE_PLAYLIST) { if (apiAction == PlaylistsVM.action.CREATE_PLAYLIST) {
Call<VideoPlaylistData.VideoPlaylistCreation> stringCall = peertubeService.addPlaylist(getToken(), displayName, description, playlistParams.getPrivacy(), channelId, body); Call<VideoPlaylistData.VideoPlaylistCreation> stringCall = peertubeService.addPlaylist(getToken(), displayName, description, playlistParams.getPrivacy(), channelId, bodyThumbnail);
Response<VideoPlaylistData.VideoPlaylistCreation> response = stringCall.execute(); Response<VideoPlaylistData.VideoPlaylistCreation> response = stringCall.execute();
if (response.isSuccessful() && response.body() != null) { if (response.isSuccessful() && response.body() != null) {
apiResponse.setActionReturn(response.body().getVideoPlaylist().getId()); apiResponse.setActionReturn(response.body().getVideoPlaylist().getId());
@ -1469,7 +1478,7 @@ public class RetrofitPeertubeAPI {
} }
} else if (apiAction == PlaylistsVM.action.UPDATE_PLAYLIST) { } else if (apiAction == PlaylistsVM.action.UPDATE_PLAYLIST) {
Call<String> stringCall = peertubeService.updatePlaylist(getToken(), playlistId, displayName, description, playlistParams.getPrivacy(), channelId, body); Call<String> stringCall = peertubeService.updatePlaylist(getToken(), playlistId, displayName, description, playlistParams.getPrivacy(), channelId, bodyThumbnail);
Response<String> response = stringCall.execute(); Response<String> response = stringCall.execute();
if (response.isSuccessful()) { if (response.isSuccessful()) {
apiResponse.setActionReturn(response.body()); apiResponse.setActionReturn(response.body());

View File

@ -20,6 +20,30 @@
android:orientation="vertical" android:orientation="vertical"
android:padding="15dp"> android:padding="15dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/profile_picture"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginStart="20dp"
android:contentDescription="@string/profile_picture" />
<Button
android:id="@+id/select_file"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="10dp"
android:singleLine="true"
android:text="@string/change_profile_picture"
android:textColor="?attr/colorAccent" />
</LinearLayout>
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"