upload+actions with retrofit
This commit is contained in:
parent
f21732f753
commit
70903578d1
|
@ -47,6 +47,7 @@ import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
|||
import app.fedilab.fedilabtube.client.data.AccountData.Account;
|
||||
import app.fedilab.fedilabtube.drawer.OwnAccountsAdapter;
|
||||
import app.fedilab.fedilabtube.fragment.DisplayAccountsFragment;
|
||||
import app.fedilab.fedilabtube.fragment.DisplayChannelsFragment;
|
||||
import app.fedilab.fedilabtube.fragment.DisplayNotificationsFragment;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.sqlite.AccountDAO;
|
||||
|
@ -178,12 +179,17 @@ public class AccountActivity extends AppCompatActivity {
|
|||
}
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
if (fragment != null) {
|
||||
DisplayAccountsFragment displayAccountsFragment = ((DisplayAccountsFragment) fragment);
|
||||
displayAccountsFragment.scrollToTop();
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (fragment != null) {
|
||||
DisplayChannelsFragment displayChannelsFragment = ((DisplayChannelsFragment) fragment);
|
||||
displayChannelsFragment.scrollToTop();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -267,27 +273,17 @@ public class AccountActivity extends AppCompatActivity {
|
|||
Bundle bundle = new Bundle();
|
||||
switch (position) {
|
||||
case 1:
|
||||
case 2:
|
||||
DisplayAccountsFragment displayAccountsFragment = new DisplayAccountsFragment();
|
||||
if (position == 1) {
|
||||
bundle.putSerializable("accountFetch", RetrofitPeertubeAPI.DataType.MUTED);
|
||||
} else {
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = Helper.getLiveInstance(AccountActivity.this);
|
||||
Account account = new AccountDAO(AccountActivity.this, db).getUniqAccount(userId, instance);
|
||||
bundle.putString("name", account.getUsername() + "@" + account.getHost());
|
||||
bundle.putSerializable("accountFetch", RetrofitPeertubeAPI.DataType.CHANNEL);
|
||||
}
|
||||
bundle.putSerializable("accountFetch", RetrofitPeertubeAPI.DataType.MUTED);
|
||||
displayAccountsFragment.setArguments(bundle);
|
||||
return displayAccountsFragment;
|
||||
case 2:
|
||||
return new DisplayChannelsFragment();
|
||||
default:
|
||||
return new DisplayNotificationsFragment();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 3;
|
||||
|
|
|
@ -15,7 +15,6 @@ package app.fedilab.fedilabtube;
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
@ -50,12 +49,11 @@ import java.util.Map;
|
|||
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.data.AccountData.Account;
|
||||
import app.fedilab.fedilabtube.client.data.ChannelData;
|
||||
import app.fedilab.fedilabtube.client.data.PlaylistData.Playlist;
|
||||
import app.fedilab.fedilabtube.client.entities.Item;
|
||||
import app.fedilab.fedilabtube.client.entities.PlaylistParams;
|
||||
import app.fedilab.fedilabtube.drawer.PlaylistAdapter;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.viewmodel.ChannelsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.PlaylistsVM;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
@ -75,6 +73,8 @@ public class AllPlaylistsActivity extends AppCompatActivity {
|
|||
private String idChannel;
|
||||
private List<Playlist> playlists;
|
||||
private Playlist playlistToEdit;
|
||||
private List<ChannelData.Channel> myChannels;
|
||||
private ChannelData.Channel selectedChannel;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -160,10 +160,8 @@ public class AllPlaylistsActivity extends AppCompatActivity {
|
|||
set_upload_channel = dialogView.findViewById(R.id.set_upload_channel);
|
||||
set_upload_privacy = dialogView.findViewById(R.id.set_upload_privacy);
|
||||
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
ChannelsVM viewModelC = new ViewModelProvider(AllPlaylistsActivity.this).get(ChannelsVM.class);
|
||||
viewModelC.get(RetrofitPeertubeAPI.DataType.CHANNELS_FOR_ACCOUNT, userId).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)});
|
||||
description.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1000)});
|
||||
|
@ -217,8 +215,10 @@ public class AllPlaylistsActivity extends AppCompatActivity {
|
|||
playlist = playlistToEdit;
|
||||
}
|
||||
playlist.setId(playlistId);
|
||||
playlist.setUuid(playlistId);
|
||||
playlist.setDescription(playlistElement.getDescription());
|
||||
playlist.setDisplayName(playlistElement.getDisplayName());
|
||||
playlist.setVideoChannel(selectedChannel);
|
||||
playlist.setPrivacy(privacyItem);
|
||||
if (playlistToEdit == null) {
|
||||
playlists.add(playlist);
|
||||
|
@ -253,7 +253,7 @@ public class AllPlaylistsActivity extends AppCompatActivity {
|
|||
|
||||
|
||||
public void manageVIewChannels(APIResponse apiResponse) {
|
||||
if (apiResponse.getError() != null || apiResponse.getAccounts() == null || apiResponse.getAccounts().size() == 0) {
|
||||
if (apiResponse.getError() != null || apiResponse.getChannels() == null || apiResponse.getChannels().size() == 0) {
|
||||
if (apiResponse.getError() != null && apiResponse.getError().getError() != null)
|
||||
Toasty.error(AllPlaylistsActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
else
|
||||
|
@ -262,16 +262,16 @@ public class AllPlaylistsActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
//Populate channels
|
||||
List<Account> channels = apiResponse.getAccounts();
|
||||
String[] channelName = new String[channels.size() + 1];
|
||||
String[] channelId = new String[channels.size() + 1];
|
||||
myChannels = apiResponse.getChannels();
|
||||
String[] channelName = new String[myChannels.size() + 1];
|
||||
String[] channelId = new String[myChannels.size() + 1];
|
||||
int i = 1;
|
||||
channelName[0] = "";
|
||||
channelId[0] = "null";
|
||||
|
||||
for (Account account : channels) {
|
||||
channelName[i] = account.getUsername();
|
||||
channelId[i] = account.getId();
|
||||
for (ChannelData.Channel channel : myChannels) {
|
||||
channelName[i] = channel.getName();
|
||||
channelId[i] = channel.getId();
|
||||
i++;
|
||||
}
|
||||
|
||||
|
@ -354,6 +354,7 @@ public class AllPlaylistsActivity extends AppCompatActivity {
|
|||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
idChannel = channelId[position];
|
||||
selectedChannel = myChannels.get(position - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -365,8 +366,8 @@ public class AllPlaylistsActivity extends AppCompatActivity {
|
|||
if (playlistToEdit != null) {
|
||||
int position = 0;
|
||||
int k = 1;
|
||||
for (Account ac : channels) {
|
||||
if (playlistToEdit.getId() != null && ac.getId().compareTo(playlistToEdit.getId()) == 0) {
|
||||
for (ChannelData.Channel ac : myChannels) {
|
||||
if (playlistToEdit.getVideoChannel() != null && playlistToEdit.getVideoChannel().getId() != null && ac.getId().compareTo(playlistToEdit.getVideoChannel().getId()) == 0) {
|
||||
position = k;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -263,10 +263,8 @@ public class InstancePickerActivity extends AppCompatActivity {
|
|||
|
||||
public void manageVIewInstance(APIResponse apiResponse) {
|
||||
mainLoader.setVisibility(View.GONE);
|
||||
//Discards 404 - error which can often happen due to toots which have been deleted
|
||||
if (apiResponse.getError() != null) {
|
||||
if (!apiResponse.getError().getError().startsWith("404 -") && !apiResponse.getError().getError().startsWith("501 -"))
|
||||
Toasty.error(InstancePickerActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
Toasty.error(InstancePickerActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
List<InstanceData.Instance> instances = apiResponse.getInstances();
|
||||
|
|
|
@ -14,6 +14,7 @@ package app.fedilab.fedilabtube;
|
|||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
|
@ -35,8 +36,6 @@ import androidx.core.content.ContextCompat;
|
|||
import com.google.android.material.textfield.TextInputEditText;
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Arrays;
|
||||
|
||||
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
||||
|
@ -153,12 +152,10 @@ public class LoginActivity extends AppCompatActivity {
|
|||
}
|
||||
instance = host = login_instance.getText().toString().trim().toLowerCase();
|
||||
}
|
||||
|
||||
|
||||
if (Arrays.asList(Helper.openid).contains(host) && !BuildConfig.full_instances) {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Oauth oauth = new RetrofitPeertubeAPI(LoginActivity.this, instance, null).oauthClient(Helper.CLIENT_NAME_VALUE, Helper.WEBSITE_VALUE, Helper.OAUTH_SCOPES_PEERTUBE, Helper.WEBSITE_VALUE);
|
||||
Oauth oauth = new RetrofitPeertubeAPI(LoginActivity.this, instance, null).oauthClient(null, null, null, null);
|
||||
if (oauth == null) {
|
||||
runOnUiThread(() -> {
|
||||
connectionButton.setEnabled(true);
|
||||
|
@ -190,93 +187,42 @@ public class LoginActivity extends AppCompatActivity {
|
|||
}).start();
|
||||
} else {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Oauth oauth = new RetrofitPeertubeAPI(LoginActivity.this, instance, null).oauthClient(Helper.CLIENT_NAME_VALUE, Helper.WEBSITE_VALUE, Helper.OAUTH_SCOPES_PEERTUBE, Helper.WEBSITE_VALUE);
|
||||
if (oauth == null) {
|
||||
runOnUiThread(() -> {
|
||||
connectionButton.setEnabled(true);
|
||||
Toasty.error(LoginActivity.this, getString(R.string.client_error), Toast.LENGTH_LONG).show();
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
client_id = oauth.getClient_id();
|
||||
client_secret = oauth.getClient_secret();
|
||||
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.CLIENT_ID, client_id);
|
||||
editor.putString(Helper.CLIENT_SECRET, client_secret);
|
||||
editor.apply();
|
||||
OauthParams oauthParams = new OauthParams();
|
||||
oauthParams.setClient_id(client_id);
|
||||
oauthParams.setClient_secret(client_secret);
|
||||
oauthParams.setGrant_type("password");
|
||||
oauthParams.setScope("user");
|
||||
try {
|
||||
oauthParams.setUsername(URLEncoder.encode(login_uid.getText().toString().trim(), "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
oauthParams.setUsername(login_uid.getText().toString().trim());
|
||||
}
|
||||
try {
|
||||
oauthParams.setPassword(URLEncoder.encode(login_passwd.getText().toString(), "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
oauthParams.setPassword(login_passwd.getText().toString());
|
||||
}
|
||||
|
||||
try {
|
||||
Token token = null;
|
||||
try {
|
||||
token = new RetrofitPeertubeAPI(LoginActivity.this, instance, null).manageToken(oauthParams);
|
||||
} catch (Error error) {
|
||||
Error.displayError(LoginActivity.this, error);
|
||||
error.printStackTrace();
|
||||
}
|
||||
proceedLogin(token, host);
|
||||
} catch (final Exception e) {
|
||||
|
||||
try {
|
||||
oauthParams.setUsername(URLEncoder.encode(login_uid.getText().toString().toLowerCase().trim(), "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e2) {
|
||||
oauthParams.setUsername(login_uid.getText().toString().toLowerCase().trim());
|
||||
}
|
||||
try {
|
||||
Token token = null;
|
||||
try {
|
||||
token = new RetrofitPeertubeAPI(LoginActivity.this, instance, null).manageToken(oauthParams);
|
||||
} catch (Error error) {
|
||||
Error.displayError(LoginActivity.this, error);
|
||||
error.printStackTrace();
|
||||
}
|
||||
proceedLogin(token, host);
|
||||
} catch (final Exception e2) {
|
||||
e2.printStackTrace();
|
||||
runOnUiThread(() -> {
|
||||
connectionButton.setEnabled(true);
|
||||
String message;
|
||||
if (e2.getLocalizedMessage() != null && e2.getLocalizedMessage().trim().length() > 0)
|
||||
message = e2.getLocalizedMessage();
|
||||
else if (e2.getMessage() != null && e2.getMessage().trim().length() > 0)
|
||||
message = e2.getMessage();
|
||||
else
|
||||
message = getString(R.string.toast_error);
|
||||
Toasty.error(LoginActivity.this, message, Toast.LENGTH_LONG).show();
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
Oauth oauth = new RetrofitPeertubeAPI(LoginActivity.this, instance, null).oauthClient(Helper.CLIENT_NAME_VALUE, Helper.WEBSITE_VALUE, Helper.OAUTH_SCOPES_PEERTUBE, Helper.WEBSITE_VALUE);
|
||||
if (oauth == null) {
|
||||
runOnUiThread(() -> {
|
||||
connectionButton.setEnabled(true);
|
||||
String message = null;
|
||||
if (e.getLocalizedMessage() != null) {
|
||||
message = e.getMessage();
|
||||
}
|
||||
if (message == null) {
|
||||
message = getString(R.string.toast_error);
|
||||
}
|
||||
Toasty.error(LoginActivity.this, message, Toast.LENGTH_LONG).show();
|
||||
Toasty.error(LoginActivity.this, getString(R.string.client_error), Toast.LENGTH_LONG).show();
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
client_id = oauth.getClient_id();
|
||||
client_secret = oauth.getClient_secret();
|
||||
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.CLIENT_ID, client_id);
|
||||
editor.putString(Helper.CLIENT_SECRET, client_secret);
|
||||
editor.apply();
|
||||
OauthParams oauthParams = new OauthParams();
|
||||
oauthParams.setClient_id(client_id);
|
||||
oauthParams.setClient_secret(client_secret);
|
||||
oauthParams.setGrant_type("password");
|
||||
oauthParams.setScope("user");
|
||||
oauthParams.setUsername(login_uid.getText().toString().trim());
|
||||
oauthParams.setPassword(login_passwd.getText().toString());
|
||||
try {
|
||||
Token token = new RetrofitPeertubeAPI(LoginActivity.this, instance, null).manageToken(oauthParams);
|
||||
proceedLogin(token, host);
|
||||
} catch (final Exception | Error e) {
|
||||
oauthParams.setUsername(login_uid.getText().toString().toLowerCase().trim());
|
||||
try {
|
||||
Token token = new RetrofitPeertubeAPI(LoginActivity.this, instance, null).manageToken(oauthParams);
|
||||
proceedLogin(token, host);
|
||||
} catch (Error error) {
|
||||
Error.displayError(LoginActivity.this, error);
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
@ -284,6 +230,7 @@ public class LoginActivity extends AppCompatActivity {
|
|||
});
|
||||
}
|
||||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
private void proceedLogin(Token token, String host) {
|
||||
runOnUiThread(() -> {
|
||||
if (token != null) {
|
||||
|
@ -291,8 +238,7 @@ public class LoginActivity extends AppCompatActivity {
|
|||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token.getAccess_token());
|
||||
editor.putString(Helper.PREF_INSTANCE, host);
|
||||
|
||||
editor.apply();
|
||||
editor.commit();
|
||||
//Update the account with the token;
|
||||
updateCredential(LoginActivity.this, token.getAccess_token(), client_id, client_secret, token.getRefresh_token(), host);
|
||||
} else {
|
||||
|
|
|
@ -74,6 +74,27 @@ public class MainActivity extends AppCompatActivity {
|
|||
|
||||
if (Helper.isLoggedIn(MainActivity.this)) {
|
||||
navView.inflateMenu(R.menu.bottom_nav_menu_connected);
|
||||
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = Helper.getLiveInstance(MainActivity.this);
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(MainActivity.this, db).getUniqAccount(userId, instance);
|
||||
if (account != null) {
|
||||
OauthParams oauthParams = new OauthParams();
|
||||
oauthParams.setGrant_type("refresh_token");
|
||||
oauthParams.setClient_id(account.getClient_id());
|
||||
oauthParams.setClient_secret(account.getClient_secret());
|
||||
oauthParams.setRefresh_token(account.getRefresh_token());
|
||||
oauthParams.setAccess_token(account.getToken());
|
||||
new Thread(() -> {
|
||||
try {
|
||||
new RetrofitPeertubeAPI(MainActivity.this).manageToken(oauthParams);
|
||||
} catch (Error error) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
} else {
|
||||
navView.inflateMenu(R.menu.bottom_nav_menu);
|
||||
}
|
||||
|
@ -93,6 +114,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
.build();
|
||||
}
|
||||
|
||||
|
||||
startInForeground();
|
||||
NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
|
||||
if (navHostFragment != null) {
|
||||
|
@ -161,27 +183,6 @@ public class MainActivity extends AppCompatActivity {
|
|||
playslistItem.setVisible(true);
|
||||
historyItem.setVisible(true);
|
||||
settingsItem.setVisible(false);
|
||||
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = Helper.getLiveInstance(MainActivity.this);
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(MainActivity.this, db).getUniqAccount(userId, instance);
|
||||
if (account != null) {
|
||||
OauthParams oauthParams = new OauthParams();
|
||||
oauthParams.setGrant_type("refresh_token");
|
||||
oauthParams.setClient_id(account.getClient_id());
|
||||
oauthParams.setClient_secret(account.getClient_secret());
|
||||
oauthParams.setRefresh_token(account.getRefresh_token());
|
||||
oauthParams.setAccess_token(account.getToken());
|
||||
new Thread(() -> {
|
||||
try {
|
||||
new RetrofitPeertubeAPI(MainActivity.this).manageToken(oauthParams);
|
||||
} catch (Error error) {
|
||||
|
||||
error.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
} else {
|
||||
instanceItem.setVisible(true);
|
||||
uploadItem.setVisible(false);
|
||||
|
@ -302,7 +303,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
(dialog, which) -> new Thread(() -> {
|
||||
try {
|
||||
String newInstance = input.getText().toString().trim();
|
||||
WellKnownNodeinfo.NodeInfo instanceNodeInfo = new RetrofitPeertubeAPI(MainActivity.this).getNodeInfo(newInstance);
|
||||
WellKnownNodeinfo.NodeInfo instanceNodeInfo = new RetrofitPeertubeAPI(MainActivity.this, newInstance, null).getNodeInfo();
|
||||
if (instanceNodeInfo.getSoftware() != null && instanceNodeInfo.getSoftware().getName().trim().toLowerCase().compareTo("peertube") == 0) {
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.PREF_INSTANCE, newInstance);
|
||||
|
|
|
@ -789,7 +789,7 @@ public class PeertubeActivity extends AppCompatActivity {
|
|||
|
||||
|
||||
public void manageVIewComment(APIResponse apiResponse) {
|
||||
if (apiResponse == null || (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404 && apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 501)) {
|
||||
if (apiResponse == null || (apiResponse.getError() != null)) {
|
||||
if (apiResponse == null)
|
||||
Toasty.error(PeertubeActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
||||
else
|
||||
|
|
|
@ -57,7 +57,6 @@ import java.util.UUID;
|
|||
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.data.AccountData.Account;
|
||||
import app.fedilab.fedilabtube.client.data.ChannelData.Channel;
|
||||
import app.fedilab.fedilabtube.client.data.VideoData.Video;
|
||||
import app.fedilab.fedilabtube.client.entities.Item;
|
||||
|
@ -224,12 +223,22 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
|
|||
|
||||
|
||||
TimelineVM feedsViewModel = new ViewModelProvider(PeertubeEditUploadActivity.this).get(TimelineVM.class);
|
||||
feedsViewModel.getVideo(videoId).observe(PeertubeEditUploadActivity.this, this::manageVIewVideo);
|
||||
feedsViewModel.getMyVideo(videoId).observe(PeertubeEditUploadActivity.this, this::manageVIewVideo);
|
||||
channels = new LinkedHashMap<>();
|
||||
|
||||
setTitle(R.string.edit_video);
|
||||
}
|
||||
|
||||
public void manageUpdate(APIResponse apiResponse) {
|
||||
set_upload_submit.setEnabled(true);
|
||||
if (apiResponse.getError() != null) {
|
||||
if (apiResponse.getError() != null && apiResponse.getError().getError() != null)
|
||||
Toasty.error(PeertubeEditUploadActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
else
|
||||
Toasty.error(PeertubeEditUploadActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
Toasty.info(PeertubeEditUploadActivity.this, getString(R.string.toast_peertube_video_updated), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
public void manageVIewVideo(APIResponse apiResponse) {
|
||||
if (apiResponse.getError() != null || apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0) {
|
||||
|
@ -252,7 +261,9 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
|
|||
privacyToSend = video.getPrivacy();
|
||||
categoryToSend = video.getCategory();
|
||||
|
||||
Helper.loadGiF(PeertubeEditUploadActivity.this, video.getThumbnailPath(), p_video_preview);
|
||||
if (video.getThumbnailPath() != null) {
|
||||
Helper.loadGiF(PeertubeEditUploadActivity.this, video.getThumbnailPath(), p_video_preview);
|
||||
}
|
||||
|
||||
|
||||
set_preview.setOnClickListener(v -> {
|
||||
|
@ -271,7 +282,6 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
|
|||
startActivityForResult(intent, PICK_IMAGE);
|
||||
|
||||
});
|
||||
|
||||
if (languageToSend == null) {
|
||||
languageToSend = new ItemStr();
|
||||
LinkedHashMap<String, String> languages = new LinkedHashMap<>(peertubeInformation.getLanguages());
|
||||
|
@ -284,7 +294,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
|
|||
licenseToSend = new Item();
|
||||
LinkedHashMap<Integer, String> licences = new LinkedHashMap<>(peertubeInformation.getLicences());
|
||||
Map.Entry<Integer, String> entryInt = licences.entrySet().iterator().next();
|
||||
licenseToSend.setId(Long.parseLong(String.valueOf(entryInt.getKey())));
|
||||
licenseToSend.setId(entryInt.getKey());
|
||||
licenseToSend.setLabel(entryInt.getValue());
|
||||
}
|
||||
|
||||
|
@ -292,21 +302,21 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
|
|||
categoryToSend = new Item();
|
||||
LinkedHashMap<Integer, String> categories = new LinkedHashMap<>(peertubeInformation.getCategories());
|
||||
Map.Entry<Integer, String> entryInt = categories.entrySet().iterator().next();
|
||||
categoryToSend.setId(Long.parseLong(String.valueOf(entryInt.getKey())));
|
||||
categoryToSend.setId(entryInt.getKey());
|
||||
categoryToSend.setLabel(entryInt.getValue());
|
||||
}
|
||||
if (privacyToSend == null) {
|
||||
privacyToSend = new Item();
|
||||
LinkedHashMap<Integer, String> privacies = new LinkedHashMap<>(peertubeInformation.getPrivacies());
|
||||
Map.Entry<Integer, String> entryInt = privacies.entrySet().iterator().next();
|
||||
privacyToSend.setId(Long.parseLong(String.valueOf(entryInt.getKey())));
|
||||
privacyToSend.setId(entryInt.getKey());
|
||||
privacyToSend.setLabel(entryInt.getValue());
|
||||
}
|
||||
|
||||
String language = languageToSend.getLabel();
|
||||
String license = licenseToSend.getLabel();
|
||||
String privacy = privacyToSend.getLabel();
|
||||
String category = categoryToSend.getLabel();
|
||||
String language = languageToSend.getId();
|
||||
int license = licenseToSend.getId();
|
||||
int privacy = privacyToSend.getId();
|
||||
int category = categoryToSend.getId();
|
||||
|
||||
channel = video.getChannel();
|
||||
String title = video.getName();
|
||||
|
@ -326,44 +336,45 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
|
|||
|
||||
|
||||
int languagePosition = 0;
|
||||
if (languages.containsValue(language)) {
|
||||
Iterator<Map.Entry<String, String>> it = languages.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<String, String> pair = it.next();
|
||||
if (pair.getValue().equals(language))
|
||||
|
||||
if (languages.containsKey(language)) {
|
||||
Iterator<Map.Entry<String, String>> itstr = languages.entrySet().iterator();
|
||||
while (itstr.hasNext()) {
|
||||
Map.Entry<String, String> pair = itstr.next();
|
||||
if (pair.getKey().compareTo(language) == 0)
|
||||
break;
|
||||
it.remove();
|
||||
itstr.remove();
|
||||
languagePosition++;
|
||||
}
|
||||
}
|
||||
int privacyPosition = 0;
|
||||
if (privacy != null && privacies.containsValue(privacy)) {
|
||||
if (privacies.containsKey(privacy)) {
|
||||
Iterator<Map.Entry<Integer, String>> it = privacies.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<Integer, String> pair = it.next();
|
||||
if (pair.getValue().compareTo(privacy) == 0)
|
||||
if (pair.getKey() == privacy)
|
||||
break;
|
||||
it.remove();
|
||||
privacyPosition++;
|
||||
}
|
||||
}
|
||||
int licensePosition = 0;
|
||||
if (license != null && licences.containsValue(license)) {
|
||||
if (licences.containsKey(license)) {
|
||||
Iterator<Map.Entry<Integer, String>> it = licences.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<Integer, String> pair = it.next();
|
||||
if (pair.getValue().compareTo(license) == 0)
|
||||
if (pair.getKey() == license)
|
||||
break;
|
||||
it.remove();
|
||||
licensePosition++;
|
||||
}
|
||||
}
|
||||
int categoryPosition = 0;
|
||||
if (category != null && categories.containsValue(category)) {
|
||||
if (categories.containsKey(category)) {
|
||||
Iterator<Map.Entry<Integer, String>> it = categories.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<Integer, String> pair = it.next();
|
||||
if (pair.getValue().compareTo(category) == 0)
|
||||
if (pair.getKey() == category)
|
||||
break;
|
||||
it.remove();
|
||||
categoryPosition++;
|
||||
|
@ -373,19 +384,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
|
|||
set_upload_privacy.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
LinkedHashMap<Integer, String> privaciesCheck = new LinkedHashMap<>(peertubeInformation.getPrivacies());
|
||||
Iterator<Map.Entry<Integer, String>> it = privaciesCheck.entrySet().iterator();
|
||||
int i = 0;
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<Integer, String> pair = it.next();
|
||||
if (i == position) {
|
||||
privacyToSend.setId(pair.getKey());
|
||||
privacyToSend.setLabel(pair.getValue());
|
||||
break;
|
||||
}
|
||||
it.remove();
|
||||
i++;
|
||||
}
|
||||
updatePrivacyPosition(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -396,19 +395,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
|
|||
set_upload_licenses.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
LinkedHashMap<Integer, String> licensesCheck = new LinkedHashMap<>(peertubeInformation.getLicences());
|
||||
Iterator<Map.Entry<Integer, String>> it = licensesCheck.entrySet().iterator();
|
||||
int i = 0;
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<Integer, String> pair = it.next();
|
||||
if (i == position) {
|
||||
licenseToSend.setId(pair.getKey());
|
||||
licenseToSend.setLabel(pair.getValue());
|
||||
break;
|
||||
}
|
||||
it.remove();
|
||||
i++;
|
||||
}
|
||||
updateLicensePosition(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -420,19 +407,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
|
|||
set_upload_categories.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
LinkedHashMap<Integer, String> categoriesCheck = new LinkedHashMap<>(peertubeInformation.getCategories());
|
||||
Iterator<Map.Entry<Integer, String>> it = categoriesCheck.entrySet().iterator();
|
||||
int i = 0;
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<Integer, String> pair = it.next();
|
||||
if (i == position) {
|
||||
categoryToSend.setId(pair.getKey());
|
||||
categoryToSend.setLabel(pair.getValue());
|
||||
break;
|
||||
}
|
||||
it.remove();
|
||||
i++;
|
||||
}
|
||||
updateCategoryPosition(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -445,19 +420,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
|
|||
set_upload_languages.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
LinkedHashMap<String, String> languagesCheck = new LinkedHashMap<>(peertubeInformation.getLanguages());
|
||||
Iterator<Map.Entry<String, String>> it = languagesCheck.entrySet().iterator();
|
||||
int i = 0;
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<String, String> pair = it.next();
|
||||
if (i == position) {
|
||||
languageToSend.setId(pair.getKey());
|
||||
languageToSend.setLabel(pair.getValue());
|
||||
break;
|
||||
}
|
||||
it.remove();
|
||||
i++;
|
||||
}
|
||||
updateLanguagesPosition(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -469,18 +432,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
|
|||
set_upload_channel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
LinkedHashMap<String, String> channelsCheck = new LinkedHashMap<>(channels);
|
||||
Iterator<Map.Entry<String, String>> it = channelsCheck.entrySet().iterator();
|
||||
int i = 0;
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<String, String> pair = it.next();
|
||||
if (i == position) {
|
||||
channelToSendId = pair.getKey();
|
||||
break;
|
||||
}
|
||||
it.remove();
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -507,27 +459,109 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
|
|||
videoParams.setCategory((int) finalCategoryToSend.getId());
|
||||
videoParams.setLicence(String.valueOf(finalLicenseToSend.getId()));
|
||||
videoParams.setLanguage(finalLanguageToSend.getId());
|
||||
|
||||
videoParams.setChannelId(channelToSendId);
|
||||
videoParams.setPrivacy((int) finalPrivacyToSend.getId());
|
||||
List<String> tags = p_video_tags.getTags();
|
||||
videoParams.setTags(tags);
|
||||
set_upload_submit.setEnabled(false);
|
||||
MyVideoVM myVideoVM = new ViewModelProvider(PeertubeEditUploadActivity.this).get(MyVideoVM.class);
|
||||
myVideoVM.updateVideo(videoId, videoParams, null, null).observe(PeertubeEditUploadActivity.this, this::manageVIewVideo);
|
||||
myVideoVM.updateVideo(videoId, videoParams, null, null).observe(PeertubeEditUploadActivity.this, this::manageUpdate);
|
||||
});
|
||||
|
||||
set_upload_privacy.setSelection(privacyPosition);
|
||||
set_upload_languages.setSelection(languagePosition);
|
||||
set_upload_licenses.setSelection(licensePosition);
|
||||
set_upload_categories.setSelection(categoryPosition);
|
||||
set_upload_privacy.setSelection(privacyPosition, false);
|
||||
updatePrivacyPosition(privacyPosition);
|
||||
set_upload_languages.setSelection(languagePosition, false);
|
||||
updateLanguagesPosition(languagePosition);
|
||||
set_upload_licenses.setSelection(licensePosition, false);
|
||||
updateLicensePosition(licensePosition);
|
||||
set_upload_categories.setSelection(categoryPosition, false);
|
||||
updateCategoryPosition(categoryPosition);
|
||||
|
||||
List<String> tags = video.getTags();
|
||||
if (tags != null && tags.size() > 0) {
|
||||
p_video_tags.setTags(tags.toArray(new String[0]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void updateUploadChannel(int position) {
|
||||
LinkedHashMap<String, String> channelsCheck = new LinkedHashMap<>(channels);
|
||||
Iterator<Map.Entry<String, String>> it = channelsCheck.entrySet().iterator();
|
||||
int i = 0;
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<String, String> pair = it.next();
|
||||
if (i == position) {
|
||||
channelToSendId = pair.getValue();
|
||||
break;
|
||||
}
|
||||
it.remove();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateLanguagesPosition(int position) {
|
||||
LinkedHashMap<String, String> languagesCheck = new LinkedHashMap<>(peertubeInformation.getLanguages());
|
||||
Iterator<Map.Entry<String, String>> it = languagesCheck.entrySet().iterator();
|
||||
int i = 0;
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<String, String> pair = it.next();
|
||||
if (i == position) {
|
||||
languageToSend.setId(pair.getKey());
|
||||
languageToSend.setLabel(pair.getValue());
|
||||
break;
|
||||
}
|
||||
it.remove();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCategoryPosition(int position) {
|
||||
LinkedHashMap<Integer, String> categoriesCheck = new LinkedHashMap<>(peertubeInformation.getCategories());
|
||||
Iterator<Map.Entry<Integer, String>> it = categoriesCheck.entrySet().iterator();
|
||||
int i = 0;
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<Integer, String> pair = it.next();
|
||||
if (i == position) {
|
||||
categoryToSend.setId(pair.getKey());
|
||||
categoryToSend.setLabel(pair.getValue());
|
||||
break;
|
||||
}
|
||||
it.remove();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateLicensePosition(int position) {
|
||||
LinkedHashMap<Integer, String> licensesCheck = new LinkedHashMap<>(peertubeInformation.getLicences());
|
||||
Iterator<Map.Entry<Integer, String>> it = licensesCheck.entrySet().iterator();
|
||||
int i = 0;
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<Integer, String> pair = it.next();
|
||||
if (i == position) {
|
||||
licenseToSend.setId(pair.getKey());
|
||||
licenseToSend.setLabel(pair.getValue());
|
||||
break;
|
||||
}
|
||||
it.remove();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePrivacyPosition(int position) {
|
||||
LinkedHashMap<Integer, String> privaciesCheck = new LinkedHashMap<>(peertubeInformation.getPrivacies());
|
||||
Iterator<Map.Entry<Integer, String>> it = privaciesCheck.entrySet().iterator();
|
||||
int i = 0;
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<Integer, String> pair = it.next();
|
||||
if (i == position) {
|
||||
privacyToSend.setId(pair.getKey());
|
||||
privacyToSend.setLabel(pair.getValue());
|
||||
break;
|
||||
}
|
||||
it.remove();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
|
@ -546,7 +580,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
|
|||
try {
|
||||
String uploadId = UUID.randomUUID().toString();
|
||||
new MultipartUploadRequest(PeertubeEditUploadActivity.this, uploadId, "https://" + Helper.getLiveInstance(PeertubeEditUploadActivity.this) + "/api/v1/" + String.format("/videos/%s", video.getId()))
|
||||
.addFileToUpload(uri.toString().replace("file://", ""), "previewfile")
|
||||
.addFileToUpload(uri.toString().replace("file://", ""), "thumbnailfile")
|
||||
.setMethod("PUT")
|
||||
.addHeader("Authorization", "Bearer " + token)
|
||||
.setNotificationConfig(uploadConfig)
|
||||
|
@ -598,20 +632,20 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
|
|||
|
||||
|
||||
public void manageVIewChannels(APIResponse apiResponse) {
|
||||
if (apiResponse.getError() != null || apiResponse.getAccounts() == null || apiResponse.getAccounts().size() == 0) {
|
||||
if (apiResponse.getError().getError() != null)
|
||||
if (apiResponse.getError() != null || apiResponse.getChannels() == null || apiResponse.getChannels().size() == 0) {
|
||||
if (apiResponse.getError() != null && apiResponse.getError().getError() != null)
|
||||
Toasty.error(PeertubeEditUploadActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
else
|
||||
Toasty.error(PeertubeEditUploadActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
//Populate channels
|
||||
List<Account> accounts = apiResponse.getAccounts();
|
||||
String[] channelName = new String[accounts.size()];
|
||||
List<Channel> channelsReply = apiResponse.getChannels();
|
||||
String[] channelName = new String[channelsReply.size()];
|
||||
int i = 0;
|
||||
for (Account account : accounts) {
|
||||
channels.put(account.getUsername(), account.getId());
|
||||
channelName[i] = account.getUsername();
|
||||
for (Channel channel : channelsReply) {
|
||||
channels.put(channel.getName(), channel.getId());
|
||||
channelName[i] = channel.getName();
|
||||
i++;
|
||||
}
|
||||
ArrayAdapter<String> adapterChannel = new ArrayAdapter<>(PeertubeEditUploadActivity.this,
|
||||
|
@ -631,7 +665,8 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
|
|||
channelPosition++;
|
||||
}
|
||||
}
|
||||
set_upload_channel.setSelection(channelPosition);
|
||||
set_upload_channel.setSelection(channelPosition, false);
|
||||
updateUploadChannel(channelPosition);
|
||||
set_upload_submit.setEnabled(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ import java.util.List;
|
|||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.data.PlaylistData.Playlist;
|
||||
import app.fedilab.fedilabtube.client.data.VideoData.Video;
|
||||
import app.fedilab.fedilabtube.client.data.VideoPlaylistData;
|
||||
import app.fedilab.fedilabtube.drawer.PeertubeAdapter;
|
||||
import app.fedilab.fedilabtube.viewmodel.PlaylistsVM;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
@ -93,7 +94,7 @@ public class PlaylistsActivity extends AppCompatActivity {
|
|||
if (b != null) {
|
||||
playlist = b.getParcelable("playlist");
|
||||
} else {
|
||||
Toasty.error(PlaylistsActivity.this, getString(R.string.toast_error_search), Toast.LENGTH_LONG).show();
|
||||
Toasty.error(PlaylistsActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
if (getSupportActionBar() != null)
|
||||
|
@ -129,7 +130,6 @@ public class PlaylistsActivity extends AppCompatActivity {
|
|||
swiped = true;
|
||||
viewModel.manage(GET_LIST_VIDEOS, playlist, null).observe(PlaylistsActivity.this, apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_LIST_VIDEOS, apiResponse));
|
||||
});
|
||||
|
||||
viewModel.manage(GET_LIST_VIDEOS, playlist, null).observe(PlaylistsActivity.this, apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_LIST_VIDEOS, apiResponse));
|
||||
}
|
||||
|
||||
|
@ -147,10 +147,8 @@ public class PlaylistsActivity extends AppCompatActivity {
|
|||
public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) {
|
||||
mainLoader.setVisibility(View.GONE);
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
//Discards 404 - error which can often happen due to toots which have been deleted
|
||||
if (apiResponse.getError() != null) {
|
||||
if (!apiResponse.getError().getError().startsWith("404 -") && !apiResponse.getError().getError().startsWith("501 -"))
|
||||
Toasty.error(PlaylistsActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
Toasty.error(PlaylistsActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
swiped = false;
|
||||
flag_loading = false;
|
||||
|
@ -159,10 +157,14 @@ public class PlaylistsActivity extends AppCompatActivity {
|
|||
if (actionType == GET_LIST_VIDEOS) {
|
||||
|
||||
int previousPosition = this.peertubes.size();
|
||||
List<Video> videos = apiResponse.getPeertubes();
|
||||
List<VideoPlaylistData.VideoPlaylist> videoPlaylists = apiResponse.getVideoPlaylist();
|
||||
List<Video> videos = new ArrayList<>();
|
||||
for (VideoPlaylistData.VideoPlaylist v : videoPlaylists) {
|
||||
videos.add(v.getVideo());
|
||||
}
|
||||
max_id = apiResponse.getMax_id();
|
||||
flag_loading = (max_id == null);
|
||||
if (!swiped && firstLoad && (videos == null || videos.size() == 0))
|
||||
if (!swiped && firstLoad && videos.size() == 0)
|
||||
textviewNoAction.setVisibility(View.VISIBLE);
|
||||
else
|
||||
textviewNoAction.setVisibility(View.GONE);
|
||||
|
@ -174,7 +176,7 @@ public class PlaylistsActivity extends AppCompatActivity {
|
|||
}
|
||||
swiped = false;
|
||||
}
|
||||
if (videos != null && videos.size() > 0) {
|
||||
if (videos.size() > 0) {
|
||||
this.peertubes.addAll(videos);
|
||||
peertubeAdapter.notifyItemRangeInserted(previousPosition, videos.size());
|
||||
}
|
||||
|
|
|
@ -136,7 +136,7 @@ public class ShowChannelActivity extends AppCompatActivity {
|
|||
return true;
|
||||
} else if (item.getItemId() == R.id.action_mute) {
|
||||
PostActionsVM viewModel = new ViewModelProvider(ShowChannelActivity.this).get(PostActionsVM.class);
|
||||
viewModel.post(MUTE, channel.getOwnerAccount() != null ? channel.getOwnerAccount().getAcct() : channel.getAcct(), null).observe(ShowChannelActivity.this, apiResponse -> manageVIewPostActions(MUTE, apiResponse));
|
||||
viewModel.post(MUTE, channel.getOwnerAccount().getAcct(), null).observe(ShowChannelActivity.this, apiResponse -> manageVIewPostActions(MUTE, apiResponse));
|
||||
} else if (item.getItemId() == R.id.action_report) {
|
||||
androidx.appcompat.app.AlertDialog.Builder dialogBuilder = new androidx.appcompat.app.AlertDialog.Builder(ShowChannelActivity.this);
|
||||
LayoutInflater inflater1 = getLayoutInflater();
|
||||
|
@ -369,9 +369,9 @@ public class ShowChannelActivity extends AppCompatActivity {
|
|||
this.channel = channel;
|
||||
manageChannel();
|
||||
}
|
||||
/*if (channel.getOwnerAccount() != null) {
|
||||
if (channel.getOwnerAccount() != null) {
|
||||
this.channel.setOwnerAccount(channel.getOwnerAccount());
|
||||
}*/
|
||||
}
|
||||
subscriber_count.setText(getString(R.string.followers_count, Helper.withSuffix(channel.getFollowersCount())));
|
||||
subscriber_count.setVisibility(View.VISIBLE);
|
||||
manageNotes(channel);
|
||||
|
|
|
@ -18,6 +18,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import app.fedilab.fedilabtube.client.data.AccountData;
|
||||
import app.fedilab.fedilabtube.client.data.BlockData.Block;
|
||||
import app.fedilab.fedilabtube.client.data.CaptionData;
|
||||
import app.fedilab.fedilabtube.client.data.ChannelData;
|
||||
import app.fedilab.fedilabtube.client.data.CommentData;
|
||||
|
@ -25,6 +26,7 @@ import app.fedilab.fedilabtube.client.data.InstanceData;
|
|||
import app.fedilab.fedilabtube.client.data.NotificationData;
|
||||
import app.fedilab.fedilabtube.client.data.PlaylistData;
|
||||
import app.fedilab.fedilabtube.client.data.VideoData;
|
||||
import app.fedilab.fedilabtube.client.data.VideoPlaylistData.VideoPlaylist;
|
||||
import app.fedilab.fedilabtube.client.entities.Error;
|
||||
import app.fedilab.fedilabtube.client.entities.OverviewVideo;
|
||||
import app.fedilab.fedilabtube.client.entities.Rating;
|
||||
|
@ -40,6 +42,8 @@ public class APIResponse {
|
|||
private OverviewVideo overviewVideo = null;
|
||||
private List<VideoData.Video> peertubes = null;
|
||||
private List<CommentData.Comment> comments = null;
|
||||
private List<Block> muted;
|
||||
private List<VideoPlaylist> videoPlaylist;
|
||||
private List<NotificationData.Notification> peertubeNotifications = null;
|
||||
private List<PlaylistData.Playlist> playlists = null;
|
||||
private List<String> domains = null;
|
||||
|
@ -217,4 +221,20 @@ public class APIResponse {
|
|||
public void setActionReturn(String actionReturn) {
|
||||
this.actionReturn = actionReturn;
|
||||
}
|
||||
|
||||
public List<Block> getMuted() {
|
||||
return muted;
|
||||
}
|
||||
|
||||
public void setMuted(List<Block> muted) {
|
||||
this.muted = muted;
|
||||
}
|
||||
|
||||
public List<VideoPlaylist> getVideoPlaylist() {
|
||||
return videoPlaylist;
|
||||
}
|
||||
|
||||
public void setVideoPlaylist(List<VideoPlaylist> videoPlaylist) {
|
||||
this.videoPlaylist = videoPlaylist;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import app.fedilab.fedilabtube.client.data.AccountData;
|
||||
import app.fedilab.fedilabtube.client.data.BlockData;
|
||||
import app.fedilab.fedilabtube.client.data.CaptionData;
|
||||
import app.fedilab.fedilabtube.client.data.ChannelData;
|
||||
import app.fedilab.fedilabtube.client.data.CommentData;
|
||||
|
@ -25,18 +26,18 @@ import app.fedilab.fedilabtube.client.data.InstanceData;
|
|||
import app.fedilab.fedilabtube.client.data.NotificationData;
|
||||
import app.fedilab.fedilabtube.client.data.PlaylistData;
|
||||
import app.fedilab.fedilabtube.client.data.VideoData;
|
||||
import app.fedilab.fedilabtube.client.data.VideoPlaylistData;
|
||||
import app.fedilab.fedilabtube.client.entities.CaptionsParams;
|
||||
import app.fedilab.fedilabtube.client.entities.ChannelParams;
|
||||
import app.fedilab.fedilabtube.client.entities.Oauth;
|
||||
import app.fedilab.fedilabtube.client.entities.OverviewVideo;
|
||||
import app.fedilab.fedilabtube.client.entities.PlaylistExist;
|
||||
import app.fedilab.fedilabtube.client.entities.PlaylistParams;
|
||||
import app.fedilab.fedilabtube.client.entities.Rating;
|
||||
import app.fedilab.fedilabtube.client.entities.Report;
|
||||
import app.fedilab.fedilabtube.client.entities.Token;
|
||||
import app.fedilab.fedilabtube.client.entities.VideoParams;
|
||||
import app.fedilab.fedilabtube.client.entities.WellKnownNodeinfo;
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.RequestBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.DELETE;
|
||||
|
@ -44,6 +45,7 @@ import retrofit2.http.Field;
|
|||
import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Header;
|
||||
import retrofit2.http.Multipart;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.PUT;
|
||||
import retrofit2.http.Part;
|
||||
|
@ -112,7 +114,7 @@ public interface PeertubeService {
|
|||
//Timelines Authenticated
|
||||
//Subscriber timeline
|
||||
@GET("users/me/subscriptions/videos?sort=-publishedAt")
|
||||
Call<VideoData> getSubscriptionVideos(@Query("start") String maxId, @Query("languageOneOf") List<String> languageOneOf);
|
||||
Call<VideoData> getSubscriptionVideos(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("languageOneOf") List<String> languageOneOf);
|
||||
|
||||
//Overview videos
|
||||
@GET("overviews/videos")
|
||||
|
@ -144,29 +146,52 @@ public interface PeertubeService {
|
|||
|
||||
//Get notifications
|
||||
@GET("users/me/notifications")
|
||||
Call<List<NotificationData.Notification>> getNotifications(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("since_id") String sinceId);
|
||||
Call<NotificationData> getNotifications(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("since_id") String sinceId);
|
||||
|
||||
//Get/Post/Update/Delete video
|
||||
//Get a video
|
||||
@GET("videos/{id}")
|
||||
Call<VideoData.Video> getVideo(@Path("id") String id);
|
||||
|
||||
@GET("videos/{id}")
|
||||
Call<VideoData.Video> getMyVideo(@Header("Authorization") String credentials, @Path("id") String id);
|
||||
|
||||
//Get my video
|
||||
@GET("users/me/videos?sort=-publishedAt")
|
||||
Call<VideoData> getMyVideo(@Header("Authorization") String credentials, @Query("start") String maxId);
|
||||
Call<VideoData> getMyVideos(@Header("Authorization") String credentials, @Query("start") String maxId);
|
||||
|
||||
//Get my video
|
||||
@GET("accounts/{name}/videos?sort=-publishedAt")
|
||||
Call<VideoData.Video> getVideosForAccount(@Query("start") String maxId);
|
||||
|
||||
|
||||
@Multipart
|
||||
@PUT("videos/{id}")
|
||||
Call<String> updateVideo(@Header("Authorization") String credentials, @Path("id") String videoId, @Body VideoParams videoParams, @Part MultipartBody.Part thumbnailfile, @Part MultipartBody.Part previewfile);
|
||||
Call<String> updateVideo(
|
||||
@Header("Authorization") String credentials,
|
||||
@Path("id") String videoId,
|
||||
@Part("channelId") RequestBody channelId,
|
||||
@Part("name") RequestBody name,
|
||||
@Part("category") int category,
|
||||
@Part("commentsEnabled") boolean commentsEnabled,
|
||||
@Part("description") RequestBody description,
|
||||
@Part("downloadEnabled") boolean downloadEnabled,
|
||||
@Part("language") RequestBody language,
|
||||
@Part("licence") RequestBody licence,
|
||||
@Part("nsfw") boolean nsfw,
|
||||
@Part("privacy") int privacy,
|
||||
@Part("support") RequestBody support,
|
||||
@Part("tags[]") List<RequestBody> tags,
|
||||
@Part("waitTranscoding") boolean waitTranscoding,
|
||||
@Part MultipartBody.Part thumbnailfile,
|
||||
@Part MultipartBody.Part previewfile);
|
||||
|
||||
@DELETE("videos/{id}")
|
||||
Call<String> deleteVideo(@Header("Authorization") String credentials, @Path("id") String videoId);
|
||||
|
||||
|
||||
@GET("oauth-clients/local")
|
||||
Call<Oauth> getOauthAcad();
|
||||
|
||||
@GET("oauth-clients/local")
|
||||
Call<Oauth> getOauth(@Query("client_name") String client_name, @Query("redirect_uris") String redirect_uris, @Query("scopes") String scopes, @Query("website") String website);
|
||||
|
||||
|
@ -174,20 +199,20 @@ public interface PeertubeService {
|
|||
//Post/Update/Delete channel
|
||||
//Channels for account
|
||||
@GET("accounts/{accountId}/video-channels")
|
||||
Call<List<ChannelData.Channel>> getChannelsForAccount(@Path("accountId") String accountId);
|
||||
Call<ChannelData> getChannelsForAccount(@Path("accountId") String accountId);
|
||||
|
||||
//Get a channel
|
||||
@GET("video-channels/{name}")
|
||||
Call<ChannelData.Channel> getChannel(@Path("name") String name);
|
||||
|
||||
@GET("video-channels")
|
||||
Call<List<ChannelData.Channel>> getMyChannels(@Header("Authorization") String credentials);
|
||||
Call<ChannelData> getAllChannels();
|
||||
|
||||
@GET("video-channels/{channelHandle}/videos")
|
||||
Call<VideoData> getChannelVideos(@Path("channelHandle") String channelHandle, @Query("start") String maxId);
|
||||
|
||||
@POST("video-channels")
|
||||
Call<String> addChannel(@Header("Authorization") String credentials, @Body ChannelParams channelParams);
|
||||
Call<ChannelData.ChannelCreation> addChannel(@Header("Authorization") String credentials, @Body ChannelParams channelParams);
|
||||
|
||||
@PUT("video-channels/{channelHandle}")
|
||||
Call<String> updateChannel(@Header("Authorization") String credentials, @Path("channelHandle") String channelHandle, @Body ChannelParams channelParams);
|
||||
|
@ -208,19 +233,36 @@ public interface PeertubeService {
|
|||
Call<PlaylistData.Playlist> getPlaylist(@Path("id") String id);
|
||||
|
||||
@GET("video-playlists/{id}/videos")
|
||||
Call<List<VideoData.Video>> getVideosPlayList(@Path("id") String id);
|
||||
Call<VideoPlaylistData> getVideosPlayList(@Header("Authorization") String credentials, @Path("id") String id);
|
||||
|
||||
@GET("users/me/video-playlists/videos-exist")
|
||||
Call<List<PlaylistExist>> getVideoExistsInPlaylist(@Query("videoIds") List<String> videoIds);
|
||||
|
||||
@Multipart
|
||||
@POST("video-playlists")
|
||||
Call<String> addPlaylist(@Header("Authorization") String credentials, @Body PlaylistParams playlistParams, @Part MultipartBody.Part thumbnailfile);
|
||||
Call<VideoPlaylistData.VideoPlaylistCreation> addPlaylist(
|
||||
@Header("Authorization") String credentials,
|
||||
@Part("displayName") RequestBody displayName,
|
||||
@Part("description") RequestBody description,
|
||||
@Part("privacy") int privacy,
|
||||
@Part("videoChannelId") RequestBody videoChannelId,
|
||||
@Part MultipartBody.Part thumbnailfile);
|
||||
|
||||
@Multipart
|
||||
@PUT("video-playlists/{id}")
|
||||
Call<String> updatePlaylist(
|
||||
@Header("Authorization") String credentials,
|
||||
@Path("id") String videoId,
|
||||
@Part("displayName") RequestBody displayName,
|
||||
@Part("description") RequestBody description,
|
||||
@Part("privacy") int privacy,
|
||||
@Part("videoChannelId") RequestBody videoChannelId,
|
||||
@Part MultipartBody.Part thumbnailfil);
|
||||
|
||||
|
||||
@POST("video-playlists/{id}/videos")
|
||||
Call<String> addVideoInPlaylist(@Header("Authorization") String credentials, @Path("id") String id, @Query("videoId") String videoId);
|
||||
|
||||
@PUT("video-playlists/{id}")
|
||||
Call<String> updatePlaylist(@Header("Authorization") String credentials, @Path("id") String videoId, @Body PlaylistParams playlistParams, @Part MultipartBody.Part thumbnailfil);
|
||||
|
||||
@DELETE("video-playlists/{id}")
|
||||
Call<String> deletePlaylist(@Header("Authorization") String credentials, @Path("id") String playlistId);
|
||||
|
@ -247,8 +289,12 @@ public interface PeertubeService {
|
|||
@GET("users/me/subscriptions/exist")
|
||||
Call<List<Map<String, Boolean>>> getSubscriptionsExist(@Header("Authorization") String credentials, @Query("uris") List<String> uris);
|
||||
|
||||
@GET("users/me/subscriptions/exist")
|
||||
Call<Map<String, Boolean>> getSubscriptionExists(@Header("Authorization") String credentials, @Query("uris") String uris);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("users/me/subscriptions")
|
||||
Call<String> follow(@Header("Authorization") String credentials, @Query("uri") String uri);
|
||||
Call<String> follow(@Header("Authorization") String credentials, @Field("uri") String uri);
|
||||
|
||||
@DELETE("users/me/subscriptions/{subscriptionHandle}")
|
||||
Call<String> unfollow(@Header("Authorization") String credentials, @Path("subscriptionHandle") String subscriptionHandle);
|
||||
|
@ -256,10 +302,11 @@ public interface PeertubeService {
|
|||
//Mute/Unmute
|
||||
//Muted accounts
|
||||
@GET("users/me/blocklist/accounts")
|
||||
Call<AccountData> getMuted(@Header("Authorization") String credentials, @Query("start") String maxId);
|
||||
Call<BlockData> getMuted(@Header("Authorization") String credentials, @Query("start") String maxId);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("users/me/blocklist/accounts")
|
||||
Call<String> mute(@Header("Authorization") String credentials, @Query("accountName") String accountName);
|
||||
Call<String> mute(@Header("Authorization") String credentials, @Field("accountName") String accountName);
|
||||
|
||||
@DELETE("users/me/blocklist/accounts/{accountName}")
|
||||
Call<String> unmute(@Header("Authorization") String credentials, @Path("accountName") String accountName);
|
||||
|
@ -270,8 +317,9 @@ public interface PeertubeService {
|
|||
Call<Rating> getRating(@Header("Authorization") String credentials, @Path("id") String id);
|
||||
|
||||
//Like/unlike
|
||||
@FormUrlEncoded
|
||||
@PUT("videos/{id}/rate")
|
||||
Call<String> rate(@Header("Authorization") String credentials, @Path("id") String id, @Query("rating") String rating);
|
||||
Call<String> rate(@Header("Authorization") String credentials, @Path("id") String id, @Field("rating") String rating);
|
||||
|
||||
|
||||
//Comment
|
||||
|
@ -281,11 +329,13 @@ public interface PeertubeService {
|
|||
@GET("videos/{id}/comment-threads/{threadId}")
|
||||
Call<CommentData> getReplies(@Path("id") String id, @Path("threadId") String threadId);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("videos/{id}/comment-threads")
|
||||
Call<String> postComment(@Header("Authorization") String credentials, @Path("id") String id, @Query("text") String text);
|
||||
Call<String> postComment(@Header("Authorization") String credentials, @Path("id") String id, @Field("text") String text);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("videos/{id}/comments/{commentId}")
|
||||
Call<String> postReply(@Header("Authorization") String credentials, @Path("id") String id, @Path("commentId") String commentId, @Query("text") String text);
|
||||
Call<String> postReply(@Header("Authorization") String credentials, @Path("id") String id, @Path("commentId") String commentId, @Field("text") String text);
|
||||
|
||||
@DELETE("videos/{id}/comments/{commentId}")
|
||||
Call<String> deleteComment(@Header("Authorization") String credentials, @Path("id") String id, @Path("commentId") String commentId);
|
||||
|
|
|
@ -37,6 +37,7 @@ import app.fedilab.fedilabtube.BuildConfig;
|
|||
import app.fedilab.fedilabtube.MainActivity;
|
||||
import app.fedilab.fedilabtube.R;
|
||||
import app.fedilab.fedilabtube.client.data.AccountData;
|
||||
import app.fedilab.fedilabtube.client.data.BlockData;
|
||||
import app.fedilab.fedilabtube.client.data.CaptionData;
|
||||
import app.fedilab.fedilabtube.client.data.ChannelData;
|
||||
import app.fedilab.fedilabtube.client.data.CommentData;
|
||||
|
@ -44,6 +45,7 @@ import app.fedilab.fedilabtube.client.data.InstanceData;
|
|||
import app.fedilab.fedilabtube.client.data.NotificationData;
|
||||
import app.fedilab.fedilabtube.client.data.PlaylistData;
|
||||
import app.fedilab.fedilabtube.client.data.VideoData;
|
||||
import app.fedilab.fedilabtube.client.data.VideoPlaylistData;
|
||||
import app.fedilab.fedilabtube.client.entities.AccountCreation;
|
||||
import app.fedilab.fedilabtube.client.entities.ChannelParams;
|
||||
import app.fedilab.fedilabtube.client.entities.Error;
|
||||
|
@ -68,6 +70,7 @@ import app.fedilab.fedilabtube.viewmodel.TimelineVM;
|
|||
import okhttp3.MediaType;
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
|
@ -96,7 +99,7 @@ public class RetrofitPeertubeAPI {
|
|||
|
||||
public static void updateCredential(Activity activity, String token, String client_id, String client_secret, String refresh_token, String host) {
|
||||
new Thread(() -> {
|
||||
AccountData.Account account = null;
|
||||
AccountData.Account account;
|
||||
String instance;
|
||||
if (host.startsWith("tube") || BuildConfig.full_instances) {
|
||||
instance = host;
|
||||
|
@ -146,6 +149,10 @@ public class RetrofitPeertubeAPI {
|
|||
}).start();
|
||||
}
|
||||
|
||||
private String getToken() {
|
||||
return "Bearer " + token;
|
||||
}
|
||||
|
||||
private PeertubeService init() {
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.baseUrl(finalUrl)
|
||||
|
@ -176,7 +183,7 @@ public class RetrofitPeertubeAPI {
|
|||
Call<Token> refreshTokenCall = null;
|
||||
if (oauthParams.getGrant_type().compareTo("password") == 0) {
|
||||
refreshTokenCall = peertubeService.createToken(oauthParams.getClient_id(), oauthParams.getClient_secret(), oauthParams.getGrant_type(), oauthParams.getUsername(), oauthParams.getPassword());
|
||||
}else if (oauthParams.getGrant_type().compareTo("refresh_token") == 0) {
|
||||
} else if (oauthParams.getGrant_type().compareTo("refresh_token") == 0) {
|
||||
refreshTokenCall = peertubeService.refreshToken(oauthParams.getClient_id(), oauthParams.getClient_secret(), oauthParams.getRefresh_token(), oauthParams.getGrant_type());
|
||||
}
|
||||
if (refreshTokenCall != null) {
|
||||
|
@ -190,7 +197,7 @@ public class RetrofitPeertubeAPI {
|
|||
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, tokenReply.getAccess_token());
|
||||
editor.apply();
|
||||
SQLiteDatabase db = Sqlite.getInstance(_context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
new AccountDAO(_context, db).updateAccountToken(oauthParams.getExternalAuthToken(), tokenReply);
|
||||
new AccountDAO(_context, db).updateAccountToken(tokenReply);
|
||||
}
|
||||
return tokenReply;
|
||||
} else {
|
||||
|
@ -220,20 +227,13 @@ public class RetrofitPeertubeAPI {
|
|||
public APIResponse getNotifications(String max_id, String since_id) {
|
||||
APIResponse apiResponse = new APIResponse();
|
||||
PeertubeService peertubeService = init();
|
||||
Call<List<NotificationData.Notification>> notificationsCall = peertubeService.getNotifications(token, max_id, since_id);
|
||||
Call<NotificationData> notificationsCall = peertubeService.getNotifications("Bearer " + token, max_id, since_id);
|
||||
try {
|
||||
Response<List<NotificationData.Notification>> response = notificationsCall.execute();
|
||||
if (response.isSuccessful()) {
|
||||
apiResponse.setPeertubeNotifications(response.body());
|
||||
Response<NotificationData> response = notificationsCall.execute();
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
apiResponse.setPeertubeNotifications(response.body().data);
|
||||
} else {
|
||||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
if (response.errorBody() != null) {
|
||||
error.setError(response.message());
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
apiResponse.setError(error);
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Error error = new Error();
|
||||
|
@ -259,14 +259,7 @@ public class RetrofitPeertubeAPI {
|
|||
if (response.isSuccessful()) {
|
||||
apiResponse.setCaptionText(response.body());
|
||||
} else {
|
||||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
if (response.errorBody() != null) {
|
||||
error.setError(response.message());
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
apiResponse.setError(error);
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Error error = new Error();
|
||||
|
@ -294,14 +287,7 @@ public class RetrofitPeertubeAPI {
|
|||
if (response.isSuccessful() && response.body() != null) {
|
||||
apiResponse.setPeertubes(response.body().data);
|
||||
} else {
|
||||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
if (response.errorBody() != null) {
|
||||
error.setError(response.message());
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
apiResponse.setError(error);
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Error error = new Error();
|
||||
|
@ -320,10 +306,10 @@ public class RetrofitPeertubeAPI {
|
|||
ArrayList<String> filter = selection != null ? new ArrayList<>(selection) : null;
|
||||
switch (timelineType) {
|
||||
case MY_VIDEOS:
|
||||
videoCall = peertubeService.getMyVideo(token, max_id);
|
||||
videoCall = peertubeService.getMyVideos(getToken(), max_id);
|
||||
break;
|
||||
case SUBSCRIBTIONS:
|
||||
videoCall = peertubeService.getSubscriptionVideos(max_id, filter);
|
||||
videoCall = peertubeService.getSubscriptionVideos(getToken(), max_id, filter);
|
||||
break;
|
||||
case MOST_LIKED:
|
||||
videoCall = peertubeService.getMostLikedVideos(max_id, filter);
|
||||
|
@ -347,14 +333,7 @@ public class RetrofitPeertubeAPI {
|
|||
if (response.isSuccessful() && response.body() != null) {
|
||||
apiResponse.setPeertubes(response.body().data);
|
||||
} else {
|
||||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
if (response.errorBody() != null) {
|
||||
error.setError(response.message());
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
apiResponse.setError(error);
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Error error = new Error();
|
||||
|
@ -382,14 +361,7 @@ public class RetrofitPeertubeAPI {
|
|||
if (response.isSuccessful() && response.body() != null) {
|
||||
apiResponse.setOverviewVideo(response.body());
|
||||
} else {
|
||||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
if (response.errorBody() != null) {
|
||||
error.setError(response.message());
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
apiResponse.setError(error);
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Error error = new Error();
|
||||
|
@ -400,28 +372,48 @@ public class RetrofitPeertubeAPI {
|
|||
return apiResponse;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if users via their uris are following the authenticated user
|
||||
*
|
||||
* @param uris List<String>
|
||||
* @return APIResponse
|
||||
*/
|
||||
public APIResponse isFollowing(String uris) {
|
||||
APIResponse apiResponse = new APIResponse();
|
||||
PeertubeService peertubeService = init();
|
||||
Call<Map<String, Boolean>> followingCall = peertubeService.getSubscriptionExists(getToken(), uris);
|
||||
try {
|
||||
Response<Map<String, Boolean>> response = followingCall.execute();
|
||||
if (response.isSuccessful()) {
|
||||
List<Map<String, Boolean>> relations = new ArrayList<>();
|
||||
relations.add(response.body());
|
||||
apiResponse.setRelationships(relations);
|
||||
} else {
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if users via their uris are following the authenticated user
|
||||
*
|
||||
* @param uris List<String>
|
||||
* @return APIResponse
|
||||
*/
|
||||
public APIResponse isFollowing(List<String> uris) {
|
||||
public APIResponse areFollowing(List<String> uris) {
|
||||
APIResponse apiResponse = new APIResponse();
|
||||
PeertubeService peertubeService = init();
|
||||
Call<List<Map<String, Boolean>>> followingCall = peertubeService.getSubscriptionsExist(token, uris);
|
||||
Call<List<Map<String, Boolean>>> followingCall = peertubeService.getSubscriptionsExist(getToken(), uris);
|
||||
try {
|
||||
Response<List<Map<String, Boolean>>> response = followingCall.execute();
|
||||
if (response.isSuccessful()) {
|
||||
apiResponse.setRelationships(response.body());
|
||||
} else {
|
||||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
if (response.errorBody() != null) {
|
||||
error.setError(response.message());
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -445,13 +437,7 @@ public class RetrofitPeertubeAPI {
|
|||
if (response.isSuccessful() && response.body() != null) {
|
||||
apiResponse.setCaptions(response.body().data);
|
||||
} else {
|
||||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
if (response.errorBody() != null) {
|
||||
error.setError(response.message());
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -476,7 +462,7 @@ public class RetrofitPeertubeAPI {
|
|||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
if (response.errorBody() != null) {
|
||||
error.setError(response.message());
|
||||
error.setError(response.errorBody().string());
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
|
@ -493,7 +479,7 @@ public class RetrofitPeertubeAPI {
|
|||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
if (response.errorBody() != null) {
|
||||
error.setError(response.message());
|
||||
error.setError(response.errorBody().string());
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
|
@ -510,7 +496,7 @@ public class RetrofitPeertubeAPI {
|
|||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
if (response.errorBody() != null) {
|
||||
error.setError(response.message());
|
||||
error.setError(response.errorBody().string());
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
|
@ -527,7 +513,7 @@ public class RetrofitPeertubeAPI {
|
|||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
if (response.errorBody() != null) {
|
||||
error.setError(response.message());
|
||||
error.setError(response.errorBody().string());
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
|
@ -544,7 +530,7 @@ public class RetrofitPeertubeAPI {
|
|||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
if (response.errorBody() != null) {
|
||||
error.setError(response.message());
|
||||
error.setError(response.errorBody().string());
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
|
@ -565,7 +551,7 @@ public class RetrofitPeertubeAPI {
|
|||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
if (response.errorBody() != null) {
|
||||
error.setError(response.message());
|
||||
error.setError(response.errorBody().string());
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
|
@ -595,14 +581,7 @@ public class RetrofitPeertubeAPI {
|
|||
try {
|
||||
Response<InstanceData> response = instancesCall.execute();
|
||||
if (!response.isSuccessful()) {
|
||||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
if (response.errorBody() != null) {
|
||||
error.setError(response.message());
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
apiResponse.setError(error);
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
} else {
|
||||
InstanceData instanceData = response.body();
|
||||
if (instanceData != null) {
|
||||
|
@ -633,14 +612,7 @@ public class RetrofitPeertubeAPI {
|
|||
if (response.isSuccessful() && response.body() != null) {
|
||||
apiResponse.setPeertubes(response.body().data);
|
||||
} else {
|
||||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
if (response.errorBody() != null) {
|
||||
error.setError(response.message());
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
apiResponse.setError(error);
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Error error = new Error();
|
||||
|
@ -667,7 +639,7 @@ public class RetrofitPeertubeAPI {
|
|||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
if (response.errorBody() != null) {
|
||||
error.setError(response.message());
|
||||
error.setError(response.errorBody().string());
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
|
@ -684,21 +656,14 @@ public class RetrofitPeertubeAPI {
|
|||
|
||||
public APIResponse report(Report report) {
|
||||
PeertubeService peertubeService = init();
|
||||
Call<String> report1 = peertubeService.report(token, report);
|
||||
Call<String> report1 = peertubeService.report(getToken(), report);
|
||||
APIResponse apiResponse = new APIResponse();
|
||||
try {
|
||||
Response<String> response = report1.execute();
|
||||
if (response.isSuccessful()) {
|
||||
apiResponse.setActionReturn(response.body());
|
||||
} else {
|
||||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
if (response.errorBody() != null) {
|
||||
error.setError(response.message());
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
apiResponse.setError(error);
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Error error = new Error();
|
||||
|
@ -729,21 +694,36 @@ public class RetrofitPeertubeAPI {
|
|||
RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), previewfile);
|
||||
bodyPreviewfile = MultipartBody.Part.createFormData("image", previewfile.getName(), requestFile);
|
||||
}
|
||||
Call<String> upload = peertubeService.updateVideo(token, videoId, videoParams, bodyThumbnail, bodyPreviewfile);
|
||||
RequestBody channelId = RequestBody.create(MediaType.parse("text/plain"), videoParams.getChannelId());
|
||||
RequestBody description = RequestBody.create(MediaType.parse("text/plain"), videoParams.getDescription());
|
||||
RequestBody language = RequestBody.create(MediaType.parse("text/plain"), videoParams.getLanguage());
|
||||
RequestBody license = RequestBody.create(MediaType.parse("text/plain"), videoParams.getLicence());
|
||||
RequestBody name = RequestBody.create(MediaType.parse("text/plain"), videoParams.getName());
|
||||
|
||||
List<RequestBody> tags = null;
|
||||
if( videoParams.getTags() != null && videoParams.getTags().size() >0 ) {
|
||||
tags = new ArrayList<>();
|
||||
for (String tag : videoParams.getTags()) {
|
||||
tags.add(RequestBody.create(MediaType.parse("text/plain"), tag));
|
||||
}
|
||||
}
|
||||
RequestBody support = null;
|
||||
if (videoParams.getSupport() != null) {
|
||||
support = RequestBody.create(MediaType.parse("text/plain"), videoParams.getSupport());
|
||||
}
|
||||
|
||||
|
||||
Call<String> upload = peertubeService.updateVideo(getToken(), videoId,
|
||||
channelId, name, videoParams.getCategory(), videoParams.isCommentsEnabled(), description, videoParams.isDownloadEnabled(), language, license, videoParams.isNsfw(),
|
||||
videoParams.getPrivacy(), support, tags, videoParams.isWaitTranscoding()
|
||||
, bodyThumbnail, bodyPreviewfile);
|
||||
APIResponse apiResponse = new APIResponse();
|
||||
try {
|
||||
Response<String> response = upload.execute();
|
||||
if (response.isSuccessful()) {
|
||||
apiResponse.setActionReturn(response.body());
|
||||
apiResponse.setActionReturn("ok");
|
||||
} else {
|
||||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
if (response.errorBody() != null) {
|
||||
error.setError(response.message());
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
apiResponse.setError(error);
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Error error = new Error();
|
||||
|
@ -763,14 +743,7 @@ public class RetrofitPeertubeAPI {
|
|||
if (response.isSuccessful()) {
|
||||
apiResponse.setActionReturn(accountCreation.getEmail());
|
||||
} else {
|
||||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
if (response.errorBody() != null) {
|
||||
error.setError(response.message());
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
apiResponse.setError(error);
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Error error = new Error();
|
||||
|
@ -787,25 +760,25 @@ public class RetrofitPeertubeAPI {
|
|||
APIResponse apiResponse = new APIResponse();
|
||||
switch (actionType) {
|
||||
case FOLLOW:
|
||||
postCall = peertubeService.follow(token, id);
|
||||
postCall = peertubeService.follow(getToken(), id);
|
||||
break;
|
||||
case UNFOLLOW:
|
||||
postCall = peertubeService.unfollow(token, id);
|
||||
postCall = peertubeService.unfollow(getToken(), id);
|
||||
break;
|
||||
case MUTE:
|
||||
postCall = peertubeService.mute(token, id);
|
||||
postCall = peertubeService.mute(getToken(), id);
|
||||
break;
|
||||
case UNMUTE:
|
||||
postCall = peertubeService.unmute(token, id);
|
||||
postCall = peertubeService.unmute(getToken(), id);
|
||||
break;
|
||||
case RATEVIDEO:
|
||||
postCall = peertubeService.rate(token, id, element);
|
||||
postCall = peertubeService.rate(getToken(), id, element);
|
||||
break;
|
||||
case PEERTUBEDELETEVIDEO:
|
||||
postCall = peertubeService.deleteVideo(token, id);
|
||||
postCall = peertubeService.deleteVideo(getToken(), id);
|
||||
break;
|
||||
case DELETE_CHANNEL:
|
||||
postCall = peertubeService.deleteChannel(token, id);
|
||||
postCall = peertubeService.deleteChannel(getToken(), id);
|
||||
break;
|
||||
}
|
||||
if (postCall != null) {
|
||||
|
@ -814,14 +787,7 @@ public class RetrofitPeertubeAPI {
|
|||
if (response.isSuccessful()) {
|
||||
apiResponse.setActionReturn(response.body());
|
||||
} else {
|
||||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
if (response.errorBody() != null) {
|
||||
error.setError(response.message());
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
apiResponse.setError(error);
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Error error = new Error();
|
||||
|
@ -834,41 +800,50 @@ public class RetrofitPeertubeAPI {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get accounts data
|
||||
* Get muted accounts
|
||||
*
|
||||
* @param accountDataType AccountDataType (type of requested data)
|
||||
* @param maxId String (pagination)
|
||||
* @param maxId String (pagination)
|
||||
* @return APIResponse
|
||||
*/
|
||||
public APIResponse getAccountData(DataType accountDataType, String maxId) {
|
||||
public APIResponse getMuted(String maxId) {
|
||||
PeertubeService peertubeService = init();
|
||||
Call<AccountData> accountDataCall = null;
|
||||
switch (accountDataType) {
|
||||
case SUBSCRIBER:
|
||||
accountDataCall = peertubeService.getSubscription("Bearer " + token, maxId);
|
||||
break;
|
||||
case MUTED:
|
||||
accountDataCall = peertubeService.getMuted("Bearer " + token, maxId);
|
||||
break;
|
||||
Call<BlockData> accountDataCall = peertubeService.getMuted("Bearer " + token, maxId);
|
||||
APIResponse apiResponse = new APIResponse();
|
||||
if (accountDataCall != null) {
|
||||
try {
|
||||
Response<BlockData> response = accountDataCall.execute();
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
apiResponse.setMuted(response.body().getData());
|
||||
} else {
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Error error = new Error();
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
apiResponse.setError(error);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get subscriptions data
|
||||
*
|
||||
* @param maxId String (pagination)
|
||||
* @return APIResponse
|
||||
*/
|
||||
public APIResponse getSubscribtions(String maxId) {
|
||||
PeertubeService peertubeService = init();
|
||||
Call<AccountData> accountDataCall = peertubeService.getSubscription("Bearer " + token, maxId);
|
||||
APIResponse apiResponse = new APIResponse();
|
||||
if (accountDataCall != null) {
|
||||
try {
|
||||
Response<AccountData> response = accountDataCall.execute();
|
||||
if (!response.isSuccessful()) {
|
||||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
if (response.errorBody() != null) {
|
||||
error.setError(response.message());
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
apiResponse.setError(error);
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
apiResponse.setAccounts(response.body().data);
|
||||
} else {
|
||||
AccountData accountData = response.body();
|
||||
if (accountData != null) {
|
||||
apiResponse.setAccounts(accountData.data);
|
||||
}
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Error error = new Error();
|
||||
|
@ -894,23 +869,21 @@ public class RetrofitPeertubeAPI {
|
|||
APIResponse apiResponse = new APIResponse();
|
||||
try {
|
||||
if (apiAction == ChannelsVM.action.CREATE_CHANNEL) {
|
||||
Call<String> stringCall = peertubeService.addChannel(token, channelParams);
|
||||
Response<String> response = stringCall.execute();
|
||||
if (response.isSuccessful()) {
|
||||
apiResponse.setActionReturn(response.body());
|
||||
Call<ChannelData.ChannelCreation> stringCall = peertubeService.addChannel(getToken(), channelParams);
|
||||
Response<ChannelData.ChannelCreation> response = stringCall.execute();
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
apiResponse.setActionReturn(response.body().getVideoChannel().getId());
|
||||
} else {
|
||||
Error error = generateError(response.code(), response.message());
|
||||
apiResponse.setError(error);
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
|
||||
} else if (apiAction == ChannelsVM.action.UPDATE_CHANNEL) {
|
||||
Call<String> stringCall = peertubeService.updateChannel(token, channelId, channelParams);
|
||||
Call<String> stringCall = peertubeService.updateChannel(getToken(), channelId, channelParams);
|
||||
Response<String> response = stringCall.execute();
|
||||
if (response.isSuccessful()) {
|
||||
apiResponse.setActionReturn(response.body());
|
||||
} else {
|
||||
Error error = generateError(response.code(), response.message());
|
||||
apiResponse.setError(error);
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
@ -930,7 +903,12 @@ public class RetrofitPeertubeAPI {
|
|||
public Oauth oauthClient(String client_name, String redirect_uris, String scopes, String website) {
|
||||
PeertubeService peertubeService = init();
|
||||
try {
|
||||
Call<Oauth> oauth = peertubeService.getOauth(client_name, redirect_uris, scopes, website);
|
||||
Call<Oauth> oauth;
|
||||
if (BuildConfig.full_instances) {
|
||||
oauth = peertubeService.getOauth(client_name, redirect_uris, scopes, website);
|
||||
} else {
|
||||
oauth = peertubeService.getOauthAcad();
|
||||
}
|
||||
Response<Oauth> response = oauth.execute();
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
return response.body();
|
||||
|
@ -944,10 +922,9 @@ public class RetrofitPeertubeAPI {
|
|||
/**
|
||||
* Get NodeInfo
|
||||
*
|
||||
* @param instance String
|
||||
* @return APIResponse
|
||||
*/
|
||||
public WellKnownNodeinfo.NodeInfo getNodeInfo(String instance) {
|
||||
public WellKnownNodeinfo.NodeInfo getNodeInfo() {
|
||||
PeertubeService peertubeService = init();
|
||||
try {
|
||||
Call<WellKnownNodeinfo> wellKnownNodeinfoCall = peertubeService.getWellKnownNodeinfo();
|
||||
|
@ -979,25 +956,14 @@ public class RetrofitPeertubeAPI {
|
|||
switch (accountDataType) {
|
||||
case MY_CHANNELS:
|
||||
case CHANNELS_FOR_ACCOUNT:
|
||||
Call<List<ChannelData.Channel>> channelDataCall;
|
||||
if (accountDataType == DataType.MY_CHANNELS) {
|
||||
channelDataCall = peertubeService.getMyChannels(token);
|
||||
} else {
|
||||
channelDataCall = peertubeService.getChannelsForAccount(element);
|
||||
}
|
||||
Call<ChannelData> channelDataCall = peertubeService.getChannelsForAccount(element);
|
||||
try {
|
||||
Response<List<ChannelData.Channel>> response = channelDataCall.execute();
|
||||
if (!response.isSuccessful()) {
|
||||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
if (response.errorBody() != null) {
|
||||
error.setError(response.message());
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
apiResponse.setError(error);
|
||||
Response<ChannelData> response = channelDataCall.execute();
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
|
||||
apiResponse.setChannels(response.body().data);
|
||||
} else {
|
||||
apiResponse.setChannels(response.body());
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Error error = new Error();
|
||||
|
@ -1011,14 +977,7 @@ public class RetrofitPeertubeAPI {
|
|||
try {
|
||||
Response<ChannelData.Channel> response = channelCall.execute();
|
||||
if (!response.isSuccessful()) {
|
||||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
if (response.errorBody() != null) {
|
||||
error.setError(response.message());
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
apiResponse.setError(error);
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
} else {
|
||||
ChannelData.Channel channelData = response.body();
|
||||
if (channelData != null) {
|
||||
|
@ -1056,24 +1015,25 @@ public class RetrofitPeertubeAPI {
|
|||
body = MultipartBody.Part.createFormData("image", thumbnail.getName(), requestFile);
|
||||
}
|
||||
try {
|
||||
RequestBody displayName = RequestBody.create(MediaType.parse("text/plain"), playlistParams.getDisplayName());
|
||||
RequestBody description = RequestBody.create(MediaType.parse("text/plain"), playlistParams.getDescription());
|
||||
RequestBody channelId = RequestBody.create(MediaType.parse("text/plain"), playlistParams.getVideoChannelId());
|
||||
if (apiAction == PlaylistsVM.action.CREATE_PLAYLIST) {
|
||||
Call<String> stringCall = peertubeService.addPlaylist(token, playlistParams, body);
|
||||
Response<String> response = stringCall.execute();
|
||||
if (response.isSuccessful()) {
|
||||
apiResponse.setActionReturn(response.body());
|
||||
Call<VideoPlaylistData.VideoPlaylistCreation> stringCall = peertubeService.addPlaylist(getToken(), displayName, description, playlistParams.getPrivacy(), channelId, body);
|
||||
Response<VideoPlaylistData.VideoPlaylistCreation> response = stringCall.execute();
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
apiResponse.setActionReturn(response.body().getVideoPlaylist().getId());
|
||||
} else {
|
||||
Error error = generateError(response.code(), response.message());
|
||||
apiResponse.setError(error);
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
|
||||
} else if (apiAction == PlaylistsVM.action.UPDATE_PLAYLIST) {
|
||||
Call<String> stringCall = peertubeService.updatePlaylist(token, playlistId, playlistParams, body);
|
||||
Call<String> stringCall = peertubeService.updatePlaylist(getToken(), playlistId, displayName, description, playlistParams.getPrivacy(), channelId, body);
|
||||
Response<String> response = stringCall.execute();
|
||||
if (response.isSuccessful()) {
|
||||
apiResponse.setActionReturn(response.body());
|
||||
} else {
|
||||
Error error = generateError(response.code(), response.message());
|
||||
apiResponse.setError(error);
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
@ -1107,55 +1067,48 @@ public class RetrofitPeertubeAPI {
|
|||
playlists.add(response.body());
|
||||
apiResponse.setPlaylists(playlists);
|
||||
} else {
|
||||
Error error = generateError(response.code(), response.message());
|
||||
apiResponse.setError(error);
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
|
||||
} else if (type == PlaylistsVM.action.GET_PLAYLISTS) {
|
||||
Call<PlaylistData> playlistsCall = peertubeService.getPlaylistsForAccount(token, acct);
|
||||
Call<PlaylistData> playlistsCall = peertubeService.getPlaylistsForAccount(getToken(), acct);
|
||||
Response<PlaylistData> response = playlistsCall.execute();
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
apiResponse.setPlaylists(response.body().data);
|
||||
} else {
|
||||
assert response.errorBody() != null;
|
||||
Error error = generateError(response.code(), response.errorBody().string());
|
||||
apiResponse.setError(error);
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
} else if (type == PlaylistsVM.action.GET_LIST_VIDEOS) {
|
||||
Call<List<VideoData.Video>> videosPlayList = peertubeService.getVideosPlayList(playlistId);
|
||||
Response<List<VideoData.Video>> response = videosPlayList.execute();
|
||||
if (response.isSuccessful()) {
|
||||
apiResponse.setPeertubes(response.body());
|
||||
Call<VideoPlaylistData> videosPlayList = peertubeService.getVideosPlayList(getToken(), playlistId);
|
||||
Response<VideoPlaylistData> response = videosPlayList.execute();
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
apiResponse.setVideoPlaylist(response.body().data);
|
||||
} else {
|
||||
Error error = generateError(response.code(), response.message());
|
||||
apiResponse.setError(error);
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
} else if (type == PlaylistsVM.action.DELETE_PLAYLIST) {
|
||||
Call<String> stringCall = peertubeService.deletePlaylist(token, playlistId);
|
||||
Call<String> stringCall = peertubeService.deletePlaylist(getToken(), playlistId);
|
||||
Response<String> response = stringCall.execute();
|
||||
if (response.isSuccessful()) {
|
||||
apiResponse.setActionReturn(response.body());
|
||||
} else {
|
||||
Error error = generateError(response.code(), response.message());
|
||||
apiResponse.setError(error);
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
} else if (type == PlaylistsVM.action.ADD_VIDEOS) {
|
||||
Call<String> stringCall = peertubeService.addVideoInPlaylist(token, playlistId, videoId);
|
||||
Call<String> stringCall = peertubeService.addVideoInPlaylist(getToken(), playlistId, videoId);
|
||||
Response<String> response = stringCall.execute();
|
||||
if (response.isSuccessful()) {
|
||||
apiResponse.setActionReturn(response.body());
|
||||
} else {
|
||||
Error error = generateError(response.code(), response.message());
|
||||
apiResponse.setError(error);
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
} else if (type == PlaylistsVM.action.DELETE_VIDEOS) {
|
||||
Call<String> stringCall = peertubeService.deleteVideoInPlaylist(token, playlistId, videoId);
|
||||
Call<String> stringCall = peertubeService.deleteVideoInPlaylist(getToken(), playlistId, videoId);
|
||||
Response<String> response = stringCall.execute();
|
||||
if (response.isSuccessful()) {
|
||||
apiResponse.setActionReturn(response.body());
|
||||
} else {
|
||||
Error error = generateError(response.code(), response.message());
|
||||
apiResponse.setError(error);
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1168,6 +1121,24 @@ public class RetrofitPeertubeAPI {
|
|||
return apiResponse;
|
||||
}
|
||||
|
||||
private void setError(APIResponse apiResponse, int responseCode, ResponseBody errorBody) {
|
||||
Error error;
|
||||
if (errorBody != null) {
|
||||
try {
|
||||
error = generateError(responseCode, errorBody.string());
|
||||
} catch (IOException e) {
|
||||
error = new Error();
|
||||
error.setStatusCode(responseCode);
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
} else {
|
||||
error = new Error();
|
||||
error.setStatusCode(responseCode);
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
apiResponse.setError(error);
|
||||
}
|
||||
|
||||
public APIResponse getComments(CommentVM.action type, String videoId, String forCommentId) {
|
||||
PeertubeService peertubeService = init();
|
||||
|
||||
|
@ -1179,8 +1150,7 @@ public class RetrofitPeertubeAPI {
|
|||
if (response.isSuccessful() && response.body() != null) {
|
||||
apiResponse.setComments(response.body().data);
|
||||
} else {
|
||||
Error error = generateError(response.code(), response.message());
|
||||
apiResponse.setError(error);
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
} else if (type == CommentVM.action.GET_REPLIES) {
|
||||
Call<CommentData> commentsCall = peertubeService.getReplies(videoId, forCommentId);
|
||||
|
@ -1188,8 +1158,7 @@ public class RetrofitPeertubeAPI {
|
|||
if (response.isSuccessful() && response.body() != null) {
|
||||
apiResponse.setComments(response.body().data);
|
||||
} else {
|
||||
Error error = generateError(response.code(), response.message());
|
||||
apiResponse.setError(error);
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
@ -1216,22 +1185,20 @@ public class RetrofitPeertubeAPI {
|
|||
APIResponse apiResponse = new APIResponse();
|
||||
try {
|
||||
if (type == ActionType.ADD_COMMENT) {
|
||||
Call<String> stringCall = peertubeService.postComment(token, videoId, text);
|
||||
Call<String> stringCall = peertubeService.postComment(getToken(), videoId, text);
|
||||
Response<String> response = stringCall.execute();
|
||||
if (response.isSuccessful()) {
|
||||
apiResponse.setActionReturn(response.body());
|
||||
} else {
|
||||
Error error = generateError(response.code(), response.message());
|
||||
apiResponse.setError(error);
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
} else if (type == ActionType.REPLY) {
|
||||
Call<String> stringCall = peertubeService.postReply(token, videoId, toCommentId, text);
|
||||
Call<String> stringCall = peertubeService.postReply(getToken(), videoId, toCommentId, text);
|
||||
Response<String> response = stringCall.execute();
|
||||
if (response.isSuccessful()) {
|
||||
apiResponse.setActionReturn(response.body());
|
||||
} else {
|
||||
Error error = generateError(response.code(), response.message());
|
||||
apiResponse.setError(error);
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
@ -1261,8 +1228,7 @@ public class RetrofitPeertubeAPI {
|
|||
playlists.add(response.body());
|
||||
apiResponse.setPlaylists(playlists);
|
||||
} else {
|
||||
Error error = generateError(response.code(), response.message());
|
||||
apiResponse.setError(error);
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Error error = new Error();
|
||||
|
@ -1292,7 +1258,7 @@ public class RetrofitPeertubeAPI {
|
|||
*/
|
||||
public APIResponse getRating(String id) {
|
||||
PeertubeService peertubeService = init();
|
||||
Call<Rating> rating = peertubeService.getRating(token, id);
|
||||
Call<Rating> rating = peertubeService.getRating(getToken(), id);
|
||||
APIResponse apiResponse = new APIResponse();
|
||||
try {
|
||||
Response<Rating> response = rating.execute();
|
||||
|
@ -1302,7 +1268,7 @@ public class RetrofitPeertubeAPI {
|
|||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
if (response.errorBody() != null) {
|
||||
error.setError(response.message());
|
||||
error.setError(response.errorBody().string());
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
|
@ -1322,9 +1288,14 @@ public class RetrofitPeertubeAPI {
|
|||
* @param id String id
|
||||
* @return APIResponse
|
||||
*/
|
||||
public APIResponse getVideos(String id) {
|
||||
public APIResponse getVideos(String id, boolean myVideo) {
|
||||
PeertubeService peertubeService = init();
|
||||
Call<VideoData.Video> video = peertubeService.getVideo(id);
|
||||
Call<VideoData.Video> video;
|
||||
if (myVideo) {
|
||||
video = peertubeService.getMyVideo(getToken(), id);
|
||||
} else {
|
||||
video = peertubeService.getVideo(id);
|
||||
}
|
||||
APIResponse apiResponse = new APIResponse();
|
||||
try {
|
||||
Response<VideoData.Video> response = video.execute();
|
||||
|
@ -1336,7 +1307,7 @@ public class RetrofitPeertubeAPI {
|
|||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
if (response.errorBody() != null) {
|
||||
error.setError(response.message());
|
||||
error.setError(response.errorBody().string());
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public class AccountData {
|
|||
public List<Account> data;
|
||||
|
||||
public static class Account implements Parcelable {
|
||||
public static final Parcelable.Creator<Account> CREATOR = new Parcelable.Creator<Account>() {
|
||||
public static final Creator<Account> CREATOR = new Creator<Account>() {
|
||||
@Override
|
||||
public Account createFromParcel(Parcel source) {
|
||||
return new Account(source);
|
||||
|
@ -63,12 +63,16 @@ public class AccountData {
|
|||
private boolean hostRedundancyAllowed;
|
||||
@SerializedName("id")
|
||||
private String id;
|
||||
@SerializedName("name")
|
||||
private String name;
|
||||
@SerializedName("username")
|
||||
private String username;
|
||||
@SerializedName("updatedAt")
|
||||
private Date updatedAt;
|
||||
@SerializedName("url")
|
||||
private String url;
|
||||
@SerializedName("userId")
|
||||
private String userId;
|
||||
private String token;
|
||||
private String client_id;
|
||||
private String client_secret;
|
||||
|
@ -89,10 +93,12 @@ public class AccountData {
|
|||
this.host = in.readString();
|
||||
this.hostRedundancyAllowed = in.readByte() != 0;
|
||||
this.id = in.readString();
|
||||
this.name = in.readString();
|
||||
this.username = in.readString();
|
||||
long tmpUpdatedAt = in.readLong();
|
||||
this.updatedAt = tmpUpdatedAt == -1 ? null : new Date(tmpUpdatedAt);
|
||||
this.url = in.readString();
|
||||
this.userId = in.readString();
|
||||
}
|
||||
|
||||
public Avatar getAvatar() {
|
||||
|
@ -168,11 +174,11 @@ public class AccountData {
|
|||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
return name != null ? name : username;
|
||||
}
|
||||
|
||||
public void setUsername(String name) {
|
||||
this.username = name;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Date getUpdatedAt() {
|
||||
|
@ -200,10 +206,9 @@ public class AccountData {
|
|||
}
|
||||
|
||||
public String getAcct() {
|
||||
return username + "@" + host;
|
||||
return name + "@" + host;
|
||||
}
|
||||
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
@ -236,6 +241,14 @@ public class AccountData {
|
|||
this.refresh_token = refresh_token;
|
||||
}
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
|
@ -252,9 +265,11 @@ public class AccountData {
|
|||
dest.writeString(this.host);
|
||||
dest.writeByte(this.hostRedundancyAllowed ? (byte) 1 : (byte) 0);
|
||||
dest.writeString(this.id);
|
||||
dest.writeString(this.name);
|
||||
dest.writeString(this.username);
|
||||
dest.writeLong(this.updatedAt != null ? this.updatedAt.getTime() : -1);
|
||||
dest.writeString(this.url);
|
||||
dest.writeString(this.userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
package app.fedilab.fedilabtube.client.data;
|
||||
/* Copyright 2020 Thomas Schneider
|
||||
*
|
||||
* This file is a part of TubeLab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class BlockData {
|
||||
|
||||
@SerializedName("total")
|
||||
public int total;
|
||||
@SerializedName("data")
|
||||
public List<Block> data;
|
||||
|
||||
public int getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(int total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public List<Block> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(List<Block> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static class Block {
|
||||
@SerializedName("blockedAccount")
|
||||
private AccountData.Account blockedAccount;
|
||||
@SerializedName("byAccount")
|
||||
private AccountData.Account byAccount;
|
||||
@SerializedName("createdAt")
|
||||
private Date createdAt;
|
||||
|
||||
public AccountData.Account getBlockedAccount() {
|
||||
return blockedAccount;
|
||||
}
|
||||
|
||||
public void setBlockedAccount(AccountData.Account blockedAccount) {
|
||||
this.blockedAccount = blockedAccount;
|
||||
}
|
||||
|
||||
public AccountData.Account getByAccount() {
|
||||
return byAccount;
|
||||
}
|
||||
|
||||
public void setByAccount(AccountData.Account byAccount) {
|
||||
this.byAccount = byAccount;
|
||||
}
|
||||
|
||||
public Date getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(Date createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -24,6 +24,7 @@ import java.util.Date;
|
|||
import java.util.List;
|
||||
|
||||
import app.fedilab.fedilabtube.client.entities.Avatar;
|
||||
import app.fedilab.fedilabtube.client.entities.ItemStr;
|
||||
import app.fedilab.fedilabtube.client.entities.ViewsPerDay;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
@ -268,4 +269,17 @@ public class ChannelData {
|
|||
dest.writeString(this.acct);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ChannelCreation {
|
||||
@SerializedName("videoChannel")
|
||||
private ItemStr videoChannel;
|
||||
|
||||
public ItemStr getVideoChannel() {
|
||||
return videoChannel;
|
||||
}
|
||||
|
||||
public void setVideoChannel(ItemStr videoChannel) {
|
||||
this.videoChannel = videoChannel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,145 @@
|
|||
package app.fedilab.fedilabtube.client.data;
|
||||
/* Copyright 2020 Thomas Schneider
|
||||
*
|
||||
* This file is a part of TubeLab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class VideoPlaylistData {
|
||||
|
||||
@SerializedName("total")
|
||||
public int total;
|
||||
@SerializedName("data")
|
||||
public List<VideoPlaylist> data;
|
||||
|
||||
public int getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(int total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public List<VideoPlaylist> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(List<VideoPlaylist> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public static class VideoPlaylist {
|
||||
@SerializedName("id")
|
||||
private String id;
|
||||
@SerializedName("position")
|
||||
private String position;
|
||||
@SerializedName("startTimestamp")
|
||||
private long startTimestamp;
|
||||
@SerializedName("stopTimestamp")
|
||||
private long stopTimestamp;
|
||||
@SerializedName("type")
|
||||
private int type;
|
||||
@SerializedName("video")
|
||||
private VideoData.Video video;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(String position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public long getStartTimestamp() {
|
||||
return startTimestamp;
|
||||
}
|
||||
|
||||
public void setStartTimestamp(long startTimestamp) {
|
||||
this.startTimestamp = startTimestamp;
|
||||
}
|
||||
|
||||
public long getStopTimestamp() {
|
||||
return stopTimestamp;
|
||||
}
|
||||
|
||||
public void setStopTimestamp(long stopTimestamp) {
|
||||
this.stopTimestamp = stopTimestamp;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public VideoData.Video getVideo() {
|
||||
return video;
|
||||
}
|
||||
|
||||
public void setVideo(VideoData.Video video) {
|
||||
this.video = video;
|
||||
}
|
||||
}
|
||||
|
||||
public static class VideoPlaylistCreation {
|
||||
@SerializedName("videoPlaylist")
|
||||
private VideoPlaylistCreationItem videoPlaylist;
|
||||
|
||||
public VideoPlaylistCreationItem getVideoPlaylist() {
|
||||
return videoPlaylist;
|
||||
}
|
||||
|
||||
public void setVideoPlaylist(VideoPlaylistCreationItem videoPlaylist) {
|
||||
this.videoPlaylist = videoPlaylist;
|
||||
}
|
||||
}
|
||||
|
||||
public static class VideoPlaylistCreationItem {
|
||||
@SerializedName("id")
|
||||
String id;
|
||||
@SerializedName("uuid")
|
||||
String uuid;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -33,7 +33,7 @@ public class Item implements Parcelable {
|
|||
}
|
||||
};
|
||||
@SerializedName("id")
|
||||
private long id;
|
||||
private int id;
|
||||
@SerializedName("label")
|
||||
private String label;
|
||||
|
||||
|
@ -41,15 +41,15 @@ public class Item implements Parcelable {
|
|||
}
|
||||
|
||||
protected Item(Parcel in) {
|
||||
this.id = in.readLong();
|
||||
this.id = in.readInt();
|
||||
this.label = in.readString();
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ public class Item implements Parcelable {
|
|||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeLong(this.id);
|
||||
dest.writeInt(this.id);
|
||||
dest.writeString(this.label);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ package app.fedilab.fedilabtube.client.entities;
|
|||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -51,6 +53,15 @@ public class VideoParams {
|
|||
@SerializedName("waitTranscoding")
|
||||
private boolean waitTranscoding;
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "channelId: " + channelId + "\nname: " + name + "\ncategory: " + category + "\ncommentsEnabled: " + commentsEnabled
|
||||
+ "\ndescription: " + description + "\ndownloadEnabled: " + downloadEnabled + "\nlanguage: " + language
|
||||
+ "\nlicence: " + licence + "\nnsfw: " + nsfw + "\noriginallyPublishedAt: " + originallyPublishedAt
|
||||
+ "\nprivacy: " + privacy + "\nsupport: " + support + "\ntags: " + tags + "\nwaitTranscoding: " + waitTranscoding;
|
||||
}
|
||||
|
||||
public String getChannelId() {
|
||||
return channelId;
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ public class AccountsHorizontalListAdapter extends RecyclerView.Adapter<Recycler
|
|||
holder.account_dn.setText(account.getUsername().replace("@", ""));
|
||||
|
||||
//Profile picture
|
||||
Helper.loadGiF(context, account.getAvatar().getPath(), holder.account_pp, 270);
|
||||
Helper.loadGiF(context, account.getAvatar() != null ? account.getAvatar().getPath() : null, holder.account_pp, 270);
|
||||
|
||||
if (account.isSelected()) {
|
||||
holder.main_container.setBackgroundColor(ColorUtils.setAlphaComponent(ContextCompat.getColor(context, Helper.getColorAccent()), 50));
|
||||
|
|
|
@ -16,14 +16,10 @@ package app.fedilab.fedilabtube.drawer;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
import android.text.util.Linkify;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
@ -40,7 +36,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
|||
import java.util.List;
|
||||
|
||||
import app.fedilab.fedilabtube.R;
|
||||
import app.fedilab.fedilabtube.ShowChannelActivity;
|
||||
import app.fedilab.fedilabtube.ShowAccountActivity;
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.data.AccountData.Account;
|
||||
|
@ -52,7 +48,6 @@ import es.dmoral.toasty.Toasty;
|
|||
public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
public AllAccountsRemoved allAccountsRemoved;
|
||||
public EditAlertDialog editAlertDialog;
|
||||
private List<Account> accounts;
|
||||
private Context context;
|
||||
private AccountsListAdapter accountsListAdapter;
|
||||
|
@ -79,26 +74,19 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
if (type == RetrofitPeertubeAPI.DataType.MUTED) {
|
||||
holder.account_action.setOnClickListener(v -> {
|
||||
PostActionsVM viewModel = new ViewModelProvider((ViewModelStoreOwner) context).get(PostActionsVM.class);
|
||||
viewModel.post(RetrofitPeertubeAPI.ActionType.UNMUTE, account.getId(), null).observe((LifecycleOwner) context, apiResponse -> manageVIewPostActions(RetrofitPeertubeAPI.ActionType.UNMUTE, apiResponse));
|
||||
viewModel.post(RetrofitPeertubeAPI.ActionType.UNMUTE, account.getAcct(), null).observe((LifecycleOwner) context, apiResponse -> manageVIewPostActions(RetrofitPeertubeAPI.ActionType.UNMUTE, apiResponse, account.getAcct()));
|
||||
});
|
||||
} else {
|
||||
holder.account_action.hide();
|
||||
}
|
||||
|
||||
holder.account_dn.setText(account.getDisplayName());
|
||||
holder.account_ac.setText(String.format("@%s", account.getUsername()));
|
||||
holder.account_ac.setText(String.format("@%s", account.getAcct()));
|
||||
if (account.getDescription() == null) {
|
||||
account.setDescription("");
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
holder.account_ds.setText(Html.fromHtml(account.getDescription(), Html.FROM_HTML_MODE_LEGACY));
|
||||
else
|
||||
holder.account_ds.setText(Html.fromHtml(account.getDescription()));
|
||||
holder.account_ds.setAutoLinkMask(Linkify.WEB_URLS);
|
||||
holder.account_fgc.setText(Helper.withSuffix(account.getFollowingCount()));
|
||||
holder.account_frc.setText(Helper.withSuffix(account.getFollowersCount()));
|
||||
//Profile picture
|
||||
Helper.loadGiF(context, account.getAvatar().getPath(), holder.account_pp);
|
||||
Helper.loadGiF(context, account.getAvatar() != null ? account.getAvatar().getPath() : null, holder.account_pp);
|
||||
//Follow button
|
||||
if (type == RetrofitPeertubeAPI.DataType.MUTED) {
|
||||
holder.account_action.show();
|
||||
|
@ -106,7 +94,7 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
}
|
||||
|
||||
holder.account_pp.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(context, ShowChannelActivity.class);
|
||||
Intent intent = new Intent(context, ShowAccountActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
b.putParcelable("channel", account);
|
||||
intent.putExtras(b);
|
||||
|
@ -126,25 +114,21 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
return accounts.size();
|
||||
}
|
||||
|
||||
public void manageVIewPostActions(RetrofitPeertubeAPI.ActionType statusAction, APIResponse apiResponse) {
|
||||
public void manageVIewPostActions(RetrofitPeertubeAPI.ActionType statusAction, APIResponse apiResponse, String elementTargeted) {
|
||||
if (apiResponse.getError() != null) {
|
||||
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
if (statusAction == RetrofitPeertubeAPI.ActionType.UNMUTE) {
|
||||
Account tmpAccount = null;
|
||||
int position = 0;
|
||||
for (Account account : accounts) {
|
||||
if (account.getId().equals(apiResponse.getTargetedId())) {
|
||||
tmpAccount = account;
|
||||
if (account.getAcct().equals(elementTargeted)) {
|
||||
accounts.remove(position);
|
||||
accountsListAdapter.notifyItemRemoved(position);
|
||||
break;
|
||||
}
|
||||
position++;
|
||||
}
|
||||
if (tmpAccount != null) {
|
||||
accounts.remove(position);
|
||||
accountsListAdapter.notifyItemRemoved(position);
|
||||
}
|
||||
if (accounts.size() == 0) {
|
||||
allAccountsRemoved.onAllAccountsRemoved();
|
||||
}
|
||||
|
@ -156,19 +140,11 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
void onAllAccountsRemoved();
|
||||
}
|
||||
|
||||
public interface EditAlertDialog {
|
||||
void show(Account account);
|
||||
}
|
||||
|
||||
private static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
ImageView account_pp;
|
||||
TextView account_ac;
|
||||
TextView account_dn;
|
||||
TextView account_ds;
|
||||
TextView account_fgc;
|
||||
TextView account_frc;
|
||||
ImageButton more_actions;
|
||||
LinearLayout account_info;
|
||||
FloatingActionButton account_action;
|
||||
LinearLayout account_container;
|
||||
|
||||
|
@ -177,12 +153,7 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
account_pp = itemView.findViewById(R.id.account_pp);
|
||||
account_dn = itemView.findViewById(R.id.account_dn);
|
||||
account_ac = itemView.findViewById(R.id.account_ac);
|
||||
account_ds = itemView.findViewById(R.id.account_ds);
|
||||
account_fgc = itemView.findViewById(R.id.account_fgc);
|
||||
account_frc = itemView.findViewById(R.id.account_frc);
|
||||
account_action = itemView.findViewById(R.id.account_action);
|
||||
account_info = itemView.findViewById(R.id.account_info);
|
||||
more_actions = itemView.findViewById(R.id.more_actions);
|
||||
account_container = itemView.findViewById(R.id.account_container);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,12 +17,9 @@ package app.fedilab.fedilabtube.drawer;
|
|||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.Html;
|
||||
import android.text.util.Linkify;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -70,19 +67,13 @@ public class ChannelListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
|||
final ViewHolder holder = (ViewHolder) viewHolder;
|
||||
final Channel channel = channels.get(position);
|
||||
holder.account_dn.setText(channel.getDisplayName());
|
||||
holder.account_ac.setText(channel.getName());
|
||||
holder.account_ac.setText(String.format("@%s", channel.getAcct()));
|
||||
if (channel.getDescription() == null) {
|
||||
channel.setDescription("");
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
holder.account_ds.setText(Html.fromHtml(channel.getDescription(), Html.FROM_HTML_MODE_LEGACY));
|
||||
else
|
||||
holder.account_ds.setText(Html.fromHtml(channel.getDescription()));
|
||||
holder.account_ds.setAutoLinkMask(Linkify.WEB_URLS);
|
||||
holder.account_fgc.setText(Helper.withSuffix(channel.getFollowingCount()));
|
||||
holder.account_frc.setText(Helper.withSuffix(channel.getFollowersCount()));
|
||||
|
||||
//Profile picture
|
||||
Helper.loadGiF(context, channel.getAvatar().getPath(), holder.account_pp);
|
||||
Helper.loadGiF(context, channel.getAvatar() != null ? channel.getAvatar().getPath() : null, holder.account_pp);
|
||||
|
||||
|
||||
holder.more_actions.setOnClickListener(view -> {
|
||||
|
@ -164,11 +155,7 @@ public class ChannelListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
|||
ImageView account_pp;
|
||||
TextView account_ac;
|
||||
TextView account_dn;
|
||||
TextView account_ds;
|
||||
TextView account_fgc;
|
||||
TextView account_frc;
|
||||
ImageButton more_actions;
|
||||
LinearLayout account_info;
|
||||
LinearLayout account_container;
|
||||
|
||||
ViewHolder(View itemView) {
|
||||
|
@ -176,10 +163,6 @@ public class ChannelListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
|||
account_pp = itemView.findViewById(R.id.account_pp);
|
||||
account_dn = itemView.findViewById(R.id.account_dn);
|
||||
account_ac = itemView.findViewById(R.id.account_ac);
|
||||
account_ds = itemView.findViewById(R.id.account_ds);
|
||||
account_fgc = itemView.findViewById(R.id.account_fgc);
|
||||
account_frc = itemView.findViewById(R.id.account_frc);
|
||||
account_info = itemView.findViewById(R.id.account_info);
|
||||
more_actions = itemView.findViewById(R.id.more_actions);
|
||||
account_container = itemView.findViewById(R.id.account_container);
|
||||
}
|
||||
|
|
|
@ -34,19 +34,24 @@ import app.fedilab.fedilabtube.PeertubeActivity;
|
|||
import app.fedilab.fedilabtube.PeertubeEditUploadActivity;
|
||||
import app.fedilab.fedilabtube.R;
|
||||
import app.fedilab.fedilabtube.ShowChannelActivity;
|
||||
import app.fedilab.fedilabtube.client.data.AccountData.Account;
|
||||
import app.fedilab.fedilabtube.client.data.VideoData;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
|
||||
|
||||
public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private List<VideoData.Video> peertubes;
|
||||
private List<VideoData.Video> videos;
|
||||
private Context context;
|
||||
private boolean myVideos;
|
||||
|
||||
public PeertubeAdapter(List<VideoData.Video> peertubes) {
|
||||
this.peertubes = peertubes;
|
||||
public PeertubeAdapter(List<VideoData.Video> videos, boolean myVideos) {
|
||||
this.videos = videos;
|
||||
this.myVideos = myVideos;
|
||||
}
|
||||
|
||||
public PeertubeAdapter(List<VideoData.Video> videos) {
|
||||
this.videos = videos;
|
||||
this.myVideos = false;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -62,39 +67,42 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
|
||||
|
||||
final PeertubeAdapter.ViewHolder holder = (PeertubeAdapter.ViewHolder) viewHolder;
|
||||
final VideoData.Video peertube = peertubes.get(position);
|
||||
final VideoData.Video video = videos.get(position);
|
||||
|
||||
Account account = peertube.getAccount();
|
||||
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, "");
|
||||
|
||||
boolean ownVideos = peertube.getAccount().getHost().compareTo(Helper.getLiveInstance(context)) == 0 && userId != null && peertube.getAccount().getId() != null && peertube.getAccount().getId().compareTo(userId) == 0;
|
||||
assert userId != null;
|
||||
|
||||
if (peertube.getChannel() == null) {
|
||||
holder.peertube_account_name.setText(account.getAcct());
|
||||
Helper.loadGiF(context, account.getAvatar().getPath(), holder.peertube_profile);
|
||||
|
||||
boolean ownVideos;
|
||||
if (myVideos) {
|
||||
ownVideos = true;
|
||||
} else {
|
||||
holder.peertube_account_name.setText(peertube.getChannel().getAcct());
|
||||
Helper.loadGiF(context, peertube.getChannel().getAvatar() != null ? peertube.getChannel().getAvatar().getPath() : null, holder.peertube_profile);
|
||||
ownVideos = video.getAccount() != null && video.getAccount().getId() != null && video.getAccount().getHost().compareTo(Helper.getLiveInstance(context)) == 0 && video.getAccount().getId().compareTo(userId) == 0;
|
||||
}
|
||||
holder.peertube_title.setText(peertube.getName());
|
||||
holder.peertube_duration.setText(Helper.secondsToString(peertube.getDuration()));
|
||||
holder.peertube_date.setText(String.format(" - %s", Helper.dateDiff(context, peertube.getCreatedAt())));
|
||||
holder.peertube_views.setText(context.getString(R.string.number_view_video, Helper.withSuffix(peertube.getViews())));
|
||||
|
||||
Helper.loadGiF(context, peertube.getThumbnailPath(), holder.peertube_video_image);
|
||||
holder.peertube_account_name.setText(video.getChannel().getAcct());
|
||||
Helper.loadGiF(context, video.getChannel().getAvatar() != null ? video.getChannel().getAvatar().getPath() : null, holder.peertube_profile);
|
||||
|
||||
holder.peertube_title.setText(video.getName());
|
||||
holder.peertube_duration.setText(Helper.secondsToString(video.getDuration()));
|
||||
holder.peertube_date.setText(String.format(" - %s", Helper.dateDiff(context, video.getCreatedAt())));
|
||||
holder.peertube_views.setText(context.getString(R.string.number_view_video, Helper.withSuffix(video.getViews())));
|
||||
|
||||
Helper.loadGiF(context, video.getThumbnailPath(), holder.peertube_video_image);
|
||||
|
||||
//For Overview Videos: boolean values for displaying title is managed in the fragment
|
||||
if (peertube.isHasTitle()) {
|
||||
if (video.isHasTitle()) {
|
||||
holder.header_title.setVisibility(View.VISIBLE);
|
||||
switch (peertube.getTitleType()) {
|
||||
switch (video.getTitleType()) {
|
||||
case TAG:
|
||||
holder.header_title.setText(String.format("#%s", peertube.getTitle()));
|
||||
holder.header_title.setText(String.format("#%s", video.getTitle()));
|
||||
break;
|
||||
case CHANNEL:
|
||||
case CATEGORY:
|
||||
holder.header_title.setText(String.format("%s", peertube.getTitle()));
|
||||
holder.header_title.setText(String.format("%s", video.getTitle()));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
|
@ -105,7 +113,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
holder.peertube_profile.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(context, ShowChannelActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
b.putParcelable("channel", peertube.getChannel());
|
||||
b.putParcelable("channel", video.getChannel());
|
||||
intent.putExtras(b);
|
||||
context.startActivity(intent);
|
||||
});
|
||||
|
@ -116,7 +124,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
holder.bottom_container.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(context, PeertubeActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
b.putString("video_id", peertube.getUuid());
|
||||
b.putString("video_id", video.getUuid());
|
||||
intent.putExtras(b);
|
||||
context.startActivity(intent);
|
||||
});
|
||||
|
@ -124,7 +132,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
holder.bottom_container.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(context, PeertubeEditUploadActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
b.putString("video_id", peertube.getUuid());
|
||||
b.putString("video_id", video.getUuid());
|
||||
intent.putExtras(b);
|
||||
context.startActivity(intent);
|
||||
});
|
||||
|
@ -132,7 +140,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
holder.peertube_video_image.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(context, PeertubeActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
b.putString("video_id", peertube.getUuid());
|
||||
b.putString("video_id", video.getUuid());
|
||||
intent.putExtras(b);
|
||||
context.startActivity(intent);
|
||||
});
|
||||
|
@ -146,7 +154,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return peertubes.size();
|
||||
return videos.size();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -34,8 +34,10 @@ import java.util.List;
|
|||
import app.fedilab.fedilabtube.LoginActivity;
|
||||
import app.fedilab.fedilabtube.PeertubeActivity;
|
||||
import app.fedilab.fedilabtube.R;
|
||||
import app.fedilab.fedilabtube.ShowAccountActivity;
|
||||
import app.fedilab.fedilabtube.ShowChannelActivity;
|
||||
import app.fedilab.fedilabtube.client.data.AccountData;
|
||||
import app.fedilab.fedilabtube.client.data.ChannelData;
|
||||
import app.fedilab.fedilabtube.client.data.NotificationData.Notification;
|
||||
import app.fedilab.fedilabtube.client.entities.Actor;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
|
@ -68,8 +70,9 @@ public class PeertubeNotificationsListAdapter extends RecyclerView.Adapter<Recyc
|
|||
|
||||
|
||||
AccountData.Account accountAction = null;
|
||||
ChannelData.Channel channelAction = null;
|
||||
if (notification.getActorFollow() != null) {
|
||||
String profileUrl = notification.getActorFollow().getFollower().getAvatar().getPath();
|
||||
String profileUrl = notification.getActorFollow().getFollower().getAvatar() != null ? notification.getActorFollow().getFollower().getAvatar().getPath() : null;
|
||||
Helper.loadGiF(context, profileUrl, holder.peertube_notif_pp);
|
||||
Actor accountActionFollow = notification.getActorFollow().getFollower();
|
||||
String type = notification.getActorFollow().getFollowing().getType();
|
||||
|
@ -91,7 +94,7 @@ public class PeertubeNotificationsListAdapter extends RecyclerView.Adapter<Recyc
|
|||
context.startActivity(intent);
|
||||
});
|
||||
} else if (notification.getComment() != null) { //Comment Notification
|
||||
String profileUrl = notification.getComment().getAccount().getAvatar().getPath();
|
||||
String profileUrl = notification.getComment().getAccount().getAvatar() != null ? notification.getComment().getAccount().getAvatar().getPath() : null;
|
||||
Helper.loadGiF(context, profileUrl, holder.peertube_notif_pp);
|
||||
accountAction = notification.getComment().getAccount();
|
||||
String message = context.getString(R.string.peertube_comment_on_video, accountAction.getDisplayName(), accountAction.getUsername());
|
||||
|
@ -110,9 +113,10 @@ public class PeertubeNotificationsListAdapter extends RecyclerView.Adapter<Recyc
|
|||
context.startActivity(intent);
|
||||
});
|
||||
} else {
|
||||
String profileUrl = notification.getVideo().getAccount().getAvatar().getPath();
|
||||
String profileUrl = notification.getVideo() != null && notification.getVideo().getChannel().getAvatar() != null ? notification.getVideo().getChannel().getAvatar().getPath() : null;
|
||||
Helper.loadGiF(context, profileUrl, holder.peertube_notif_pp);
|
||||
accountAction = notification.getVideo().getAccount();
|
||||
|
||||
|
||||
String message = "";
|
||||
if (notification.getVideo() != null) {
|
||||
|
||||
|
@ -123,7 +127,8 @@ public class PeertubeNotificationsListAdapter extends RecyclerView.Adapter<Recyc
|
|||
} else if (notification.getType() == LoginActivity.MY_VIDEO_IMPORT_SUCCESS) {
|
||||
message = context.getString(R.string.peertube_video_import_success, notification.getVideo().getName());
|
||||
} else if (notification.getType() == LoginActivity.NEW_VIDEO_FROM_SUBSCRIPTION) {
|
||||
message = context.getString(R.string.peertube_video_from_subscription, accountAction.getDisplayName(), notification.getVideo().getName());
|
||||
channelAction = notification.getVideo().getChannel();
|
||||
message = context.getString(R.string.peertube_video_from_subscription, channelAction.getDisplayName(), notification.getVideo().getName());
|
||||
} else if (notification.getType() == LoginActivity.BLACKLIST_ON_MY_VIDEO) {
|
||||
message = context.getString(R.string.peertube_video_blacklist, notification.getVideo().getName());
|
||||
} else if (notification.getType() == LoginActivity.UNBLACKLIST_ON_MY_VIDEO) {
|
||||
|
@ -146,11 +151,18 @@ public class PeertubeNotificationsListAdapter extends RecyclerView.Adapter<Recyc
|
|||
holder.peertube_notif_date.setText(Helper.dateDiff(context, notification.getCreatedAt()));
|
||||
|
||||
AccountData.Account finalAccountAction = accountAction;
|
||||
ChannelData.Channel finalChannelAction = channelAction;
|
||||
holder.peertube_notif_pp.setOnClickListener(v -> {
|
||||
Bundle b = new Bundle();
|
||||
Intent intent = null;
|
||||
if (finalAccountAction != null) {
|
||||
Intent intent = new Intent(context, ShowChannelActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
b.putString("channelId", finalAccountAction.getUsername() + "@" + finalAccountAction.getHost());
|
||||
intent = new Intent(context, ShowAccountActivity.class);
|
||||
b.putString("channel", finalAccountAction.getAcct());
|
||||
} else if (finalChannelAction != null) {
|
||||
intent = new Intent(context, ShowChannelActivity.class);
|
||||
b.putParcelable("channel", finalChannelAction);
|
||||
}
|
||||
if (intent != null) {
|
||||
intent.putExtras(b);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
|
|
@ -33,8 +33,6 @@ import androidx.lifecycle.LifecycleOwner;
|
|||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.lifecycle.ViewModelStoreOwner;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import app.fedilab.fedilabtube.AllPlaylistsActivity;
|
||||
|
@ -42,6 +40,7 @@ import app.fedilab.fedilabtube.PlaylistsActivity;
|
|||
import app.fedilab.fedilabtube.R;
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.data.PlaylistData.Playlist;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.viewmodel.PlaylistsVM;
|
||||
|
||||
|
||||
|
@ -94,11 +93,7 @@ public class PlaylistAdapter extends BaseAdapter {
|
|||
holder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
if (playlist.getOwnerAccount() != null) {
|
||||
Glide.with(context)
|
||||
.load("https://" + playlist.getOwnerAccount() + playlist.getThumbnailPath())
|
||||
.into(holder.preview_playlist);
|
||||
}
|
||||
Helper.loadGiF(context, playlist.getThumbnailPath(), holder.preview_playlist);
|
||||
|
||||
holder.preview_title.setText(playlist.getDisplayName());
|
||||
if (playlist.getDescription() != null && playlist.getDescription().trim().compareTo("null") != 0 && playlist.getDescription().length() > 0) {
|
||||
|
|
|
@ -37,7 +37,8 @@ import java.util.List;
|
|||
import app.fedilab.fedilabtube.R;
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.data.AccountData;
|
||||
import app.fedilab.fedilabtube.client.data.AccountData.Account;
|
||||
import app.fedilab.fedilabtube.client.data.BlockData;
|
||||
import app.fedilab.fedilabtube.drawer.AccountsListAdapter;
|
||||
import app.fedilab.fedilabtube.viewmodel.AccountsVM;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
@ -49,7 +50,7 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
|
|||
private Context context;
|
||||
private AccountsListAdapter accountsListAdapter;
|
||||
private String max_id;
|
||||
private List<AccountData.Account> accounts;
|
||||
private List<Account> accounts;
|
||||
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
|
||||
private boolean firstLoad;
|
||||
private SwipeRefreshLayout swipeRefreshLayout;
|
||||
|
@ -124,6 +125,12 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
|
|||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (getActivity() != null && getActivity() != null) {
|
||||
View action_button = getActivity().findViewById(R.id.action_button);
|
||||
if (action_button != null) {
|
||||
action_button.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -165,7 +172,15 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
|
|||
return;
|
||||
}
|
||||
flag_loading = (apiResponse.getMax_id() == null);
|
||||
List<AccountData.Account> accounts = apiResponse.getAccounts();
|
||||
List<Account> accounts = apiResponse.getAccounts();
|
||||
if (accountFetch == RetrofitPeertubeAPI.DataType.MUTED) {
|
||||
accounts = new ArrayList<>();
|
||||
List<BlockData.Block> blockList = apiResponse.getMuted();
|
||||
for (BlockData.Block block : blockList) {
|
||||
accounts.add(block.getBlockedAccount());
|
||||
}
|
||||
}
|
||||
|
||||
if (!swiped && firstLoad && (accounts == null || accounts.size() == 0))
|
||||
textviewNoAction.setVisibility(View.VISIBLE);
|
||||
else
|
||||
|
|
|
@ -84,7 +84,6 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap
|
|||
|
||||
swipeRefreshLayout = rootView.findViewById(R.id.swipeContainer);
|
||||
|
||||
|
||||
if (getActivity() != null) {
|
||||
action_button = getActivity().findViewById(R.id.action_button);
|
||||
action_button.setVisibility(View.VISIBLE);
|
||||
|
@ -103,20 +102,29 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap
|
|||
channelListAdapter.editAlertDialog = this;
|
||||
lv_channels.setAdapter(channelListAdapter);
|
||||
|
||||
|
||||
final LinearLayoutManager mLayoutManager;
|
||||
mLayoutManager = new LinearLayoutManager(context);
|
||||
lv_channels.setLayoutManager(mLayoutManager);
|
||||
|
||||
swipeRefreshLayout.setOnRefreshListener(this::pullToRefresh);
|
||||
ChannelsVM viewModel = new ViewModelProvider(this).get(ChannelsVM.class);
|
||||
viewModel.get(RetrofitPeertubeAPI.DataType.CHANNELS_FOR_ACCOUNT, name).observe(DisplayChannelsFragment.this.requireActivity(), this::manageViewChannels);
|
||||
if (name != null) {
|
||||
viewModel.get(RetrofitPeertubeAPI.DataType.CHANNELS_FOR_ACCOUNT, name).observe(DisplayChannelsFragment.this.requireActivity(), this::manageViewChannels);
|
||||
} else {
|
||||
viewModel.get(RetrofitPeertubeAPI.DataType.MY_CHANNELS, null).observe(DisplayChannelsFragment.this.requireActivity(), this::manageViewChannels);
|
||||
}
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (getActivity() != null && getActivity() != null) {
|
||||
View action_button = getActivity().findViewById(R.id.action_button);
|
||||
if (action_button != null) {
|
||||
action_button.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -130,7 +138,6 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap
|
|||
super.onCreate(saveInstance);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onAttach(@NonNull Context context) {
|
||||
super.onAttach(context);
|
||||
|
@ -181,7 +188,11 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap
|
|||
swiped = true;
|
||||
swipeRefreshLayout.setRefreshing(true);
|
||||
ChannelsVM viewModel = new ViewModelProvider(this).get(ChannelsVM.class);
|
||||
viewModel.get(RetrofitPeertubeAPI.DataType.CHANNELS_FOR_ACCOUNT, name).observe(DisplayChannelsFragment.this.requireActivity(), this::manageViewChannels);
|
||||
if (name != null) {
|
||||
viewModel.get(RetrofitPeertubeAPI.DataType.CHANNELS_FOR_ACCOUNT, name).observe(DisplayChannelsFragment.this.requireActivity(), this::manageViewChannels);
|
||||
} else {
|
||||
viewModel.get(RetrofitPeertubeAPI.DataType.MY_CHANNELS, null).observe(DisplayChannelsFragment.this.requireActivity(), this::manageViewChannels);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -223,10 +234,11 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap
|
|||
channelCreation.setDescription(description.getText().toString().trim());
|
||||
}
|
||||
new Thread(() -> {
|
||||
APIResponse apiResponse;
|
||||
if (oldChannelValues == null) {
|
||||
new RetrofitPeertubeAPI(context).createOrUpdateChannel(ChannelsVM.action.CREATE_CHANNEL, null, channelCreation);
|
||||
apiResponse = new RetrofitPeertubeAPI(context).createOrUpdateChannel(ChannelsVM.action.CREATE_CHANNEL, null, channelCreation);
|
||||
} else {
|
||||
new RetrofitPeertubeAPI(context).createOrUpdateChannel(ChannelsVM.action.UPDATE_CHANNEL, channelCreation.getName() + "@" + Helper.getLiveInstance(context), channelCreation);
|
||||
apiResponse = new RetrofitPeertubeAPI(context).createOrUpdateChannel(ChannelsVM.action.UPDATE_CHANNEL, channelCreation.getName() + "@" + Helper.getLiveInstance(context), channelCreation);
|
||||
}
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> {
|
||||
|
@ -235,6 +247,7 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap
|
|||
return;
|
||||
if (oldChannelValues == null) {
|
||||
ChannelData.Channel channel = new ChannelData.Channel();
|
||||
channel.setId(apiResponse.getActionReturn());
|
||||
channel.setName(channelCreation.getName());
|
||||
channel.setDisplayName(channelCreation.getDisplayName());
|
||||
channel.setDescription(channelCreation.getDescription());
|
||||
|
|
|
@ -196,8 +196,8 @@ public class DisplayOverviewFragment extends Fragment implements AccountsHorizon
|
|||
//hide loaders
|
||||
mainLoader.setVisibility(View.GONE);
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
//handle other API error but discards 404 - error which can often happen due to toots which have been deleted
|
||||
if (this.peertubes == null || apiResponse == null || apiResponse.getOverviewVideo() == null || (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404 && apiResponse.getError().getStatusCode() != 501)) {
|
||||
//handle other API error
|
||||
if (this.peertubes == null || apiResponse == null || apiResponse.getOverviewVideo() == null || (apiResponse.getError() != null)) {
|
||||
if (apiResponse == null || apiResponse.getError() == null)
|
||||
Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
||||
else {
|
||||
|
|
|
@ -68,7 +68,7 @@ import es.dmoral.toasty.Toasty;
|
|||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
import static app.fedilab.fedilabtube.MainActivity.peertubeInformation;
|
||||
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.DataType.CHANNELS_FOR_ACCOUNT;
|
||||
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.DataType.MY_CHANNELS;
|
||||
|
||||
|
||||
public class DisplayPlaylistsFragment extends Fragment {
|
||||
|
@ -135,7 +135,7 @@ public class DisplayPlaylistsFragment extends Fragment {
|
|||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
final String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
ChannelsVM viewModelC = new ViewModelProvider(this).get(ChannelsVM.class);
|
||||
viewModelC.get(CHANNELS_FOR_ACCOUNT, userId).observe(DisplayPlaylistsFragment.this.requireActivity(), this::manageVIewChannels);
|
||||
viewModelC.get(MY_CHANNELS, null).observe(DisplayPlaylistsFragment.this.requireActivity(), this::manageVIewChannels);
|
||||
|
||||
display_name.setFilters(new InputFilter[]{new InputFilter.LengthFilter(120)});
|
||||
description.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1000)});
|
||||
|
|
|
@ -131,7 +131,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||
mainLoader.setVisibility(View.VISIBLE);
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
|
||||
peertubeAdapater = new PeertubeAdapter(this.peertubes);
|
||||
peertubeAdapater = new PeertubeAdapter(this.peertubes, type == TimelineVM.TimelineType.MY_VIDEOS);
|
||||
lv_status.setAdapter(peertubeAdapater);
|
||||
|
||||
accountsHorizontalListAdapter = new AccountsHorizontalListAdapter(this.accounts, this);
|
||||
|
@ -295,8 +295,8 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||
//hide loaders
|
||||
mainLoader.setVisibility(View.GONE);
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
//handle other API error but discards 404 - error which can often happen due to toots which have been deleted
|
||||
if (this.peertubes == null || apiResponse == null || (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404 && apiResponse.getError().getStatusCode() != 501)) {
|
||||
//handle other API error
|
||||
if (this.peertubes == null || apiResponse == null || (apiResponse.getError() != null)) {
|
||||
if (apiResponse == null)
|
||||
Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
||||
else {
|
||||
|
@ -318,7 +318,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||
this.peertubes.addAll(apiResponse.getPeertubes());
|
||||
//If no item were inserted previously the adapter is created
|
||||
if (previousPosition == 0) {
|
||||
peertubeAdapater = new PeertubeAdapter(this.peertubes);
|
||||
peertubeAdapater = new PeertubeAdapter(this.peertubes, type == TimelineVM.TimelineType.MY_VIDEOS);
|
||||
lv_status.setAdapter(peertubeAdapater);
|
||||
} else
|
||||
peertubeAdapater.notifyItemRangeInserted(previousPosition, apiResponse.getPeertubes().size());
|
||||
|
|
|
@ -16,6 +16,7 @@ package app.fedilab.fedilabtube.sqlite;
|
|||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
|
||||
|
@ -132,22 +133,27 @@ public class AccountDAO {
|
|||
/**
|
||||
* Update an Account token in database
|
||||
*
|
||||
* @param oldToken String
|
||||
* @param token Token
|
||||
* @return boolean
|
||||
*/
|
||||
public int updateAccountToken(String oldToken, Token token) {
|
||||
public int updateAccountToken(Token token) {
|
||||
ContentValues values = new ContentValues();
|
||||
|
||||
|
||||
if (token.getRefresh_token() != null) {
|
||||
values.put(Sqlite.COL_REFRESH_TOKEN, token.getRefresh_token());
|
||||
}
|
||||
if (token.getAccess_token() != null)
|
||||
values.put(Sqlite.COL_OAUTHTOKEN, token.getAccess_token());
|
||||
return db.update(Sqlite.TABLE_USER_ACCOUNT,
|
||||
values, Sqlite.COL_OAUTHTOKEN + " = ? ",
|
||||
new String[]{oldToken});
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = Helper.getLiveInstance(context);
|
||||
try {
|
||||
return db.update(Sqlite.TABLE_USER_ACCOUNT,
|
||||
values, Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =?",
|
||||
new String[]{userId, instance});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -46,9 +46,15 @@ public class AccountsVM extends AndroidViewModel {
|
|||
new Thread(() -> {
|
||||
try {
|
||||
RetrofitPeertubeAPI retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext);
|
||||
APIResponse apiResponse = retrofitPeertubeAPI.getAccountData(dataType, element);
|
||||
APIResponse apiResponse = new APIResponse();
|
||||
if (dataType == RetrofitPeertubeAPI.DataType.SUBSCRIBER) {
|
||||
apiResponse = retrofitPeertubeAPI.getSubscribtions(element);
|
||||
} else if (dataType == RetrofitPeertubeAPI.DataType.MUTED) {
|
||||
apiResponse = retrofitPeertubeAPI.getMuted(element);
|
||||
}
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);
|
||||
APIResponse finalApiResponse = apiResponse;
|
||||
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(finalApiResponse);
|
||||
mainHandler.post(myRunnable);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -16,6 +16,8 @@ package app.fedilab.fedilabtube.viewmodel;
|
|||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
|
@ -26,6 +28,12 @@ import androidx.lifecycle.MutableLiveData;
|
|||
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.data.AccountData;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.sqlite.AccountDAO;
|
||||
import app.fedilab.fedilabtube.sqlite.Sqlite;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
|
||||
|
||||
public class ChannelsVM extends AndroidViewModel {
|
||||
|
@ -44,9 +52,18 @@ public class ChannelsVM extends AndroidViewModel {
|
|||
private void getChannels(RetrofitPeertubeAPI.DataType type, String element) {
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
String finalElement = element;
|
||||
try {
|
||||
if (type == RetrofitPeertubeAPI.DataType.MY_CHANNELS) {
|
||||
SharedPreferences sharedpreferences = _mContext.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
SQLiteDatabase db = Sqlite.getInstance(_mContext.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
String instance = Helper.getLiveInstance(_mContext);
|
||||
AccountData.Account account = new AccountDAO(_mContext, db).getAccountByToken(token);
|
||||
finalElement = account.getUsername() + "@" + account.getHost();
|
||||
}
|
||||
RetrofitPeertubeAPI retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext);
|
||||
APIResponse apiResponse = retrofitPeertubeAPI.getChannelData(type, element);
|
||||
APIResponse apiResponse = retrofitPeertubeAPI.getChannelData(type, finalElement);
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);
|
||||
mainHandler.post(myRunnable);
|
||||
|
|
|
@ -87,7 +87,7 @@ public class PlaylistsVM extends AndroidViewModel {
|
|||
apiResponse = new APIResponse();
|
||||
apiResponse.setPlaylists(new ArrayList<>());
|
||||
} else {
|
||||
apiResponse = new RetrofitPeertubeAPI(_mContext).playlistAction(apiAction, playlist!=null?playlist.getId():null, videoId, account.getAcct());
|
||||
apiResponse = new RetrofitPeertubeAPI(_mContext).playlistAction(apiAction, playlist != null ? playlist.getUuid() : null, videoId, account.getAcct());
|
||||
}
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
if (apiResponse != null) {
|
||||
|
|
|
@ -48,7 +48,12 @@ public class RelationshipVM extends AndroidViewModel {
|
|||
new Thread(() -> {
|
||||
try {
|
||||
RetrofitPeertubeAPI api = new RetrofitPeertubeAPI(_mContext);
|
||||
APIResponse apiResponse = api.isFollowing(uris);
|
||||
APIResponse apiResponse;
|
||||
if (uris.size() == 1) {
|
||||
apiResponse = api.isFollowing(uris.get(0));
|
||||
} else {
|
||||
apiResponse = api.areFollowing(uris);
|
||||
}
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);
|
||||
mainHandler.post(myRunnable);
|
||||
|
|
|
@ -51,7 +51,13 @@ public class TimelineVM extends AndroidViewModel {
|
|||
|
||||
public LiveData<APIResponse> getVideo(String videoId) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
getSingle(videoId);
|
||||
getSingle(videoId, false);
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> getMyVideo(String videoId) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
getSingle(videoId, true);
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
|
@ -76,13 +82,13 @@ public class TimelineVM extends AndroidViewModel {
|
|||
}).start();
|
||||
}
|
||||
|
||||
private void getSingle(String videoId) {
|
||||
private void getSingle(String videoId, boolean myVideo) {
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
RetrofitPeertubeAPI retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext);
|
||||
APIResponse apiResponse = retrofitPeertubeAPI.getVideos(videoId);
|
||||
if (Helper.isLoggedIn(_mContext)) {
|
||||
APIResponse apiResponse = retrofitPeertubeAPI.getVideos(videoId, myVideo);
|
||||
if (Helper.isLoggedIn(_mContext) && !myVideo) {
|
||||
if (apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0 && apiResponse.getPeertubes().get(0) != null) {
|
||||
APIResponse response = new RetrofitPeertubeAPI(_mContext).getRating(videoId);
|
||||
if (response != null)
|
||||
|
|
|
@ -156,5 +156,14 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/action_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="@dimen/fab_margin_button"
|
||||
android:src="@drawable/ic_baseline_add_24"
|
||||
android:tint="@android:color/white"
|
||||
android:visibility="gone" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
|
@ -51,68 +51,10 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:ellipsize="end"
|
||||
android:singleLine="true"
|
||||
android:textSize="16sp"
|
||||
android:visibility="gone" />
|
||||
android:textSize="16sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/account_info"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:baselineAligned="false"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:text="@string/following" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/account_fgc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:text="@string/followers" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/account_frc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/account_ds"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:animateLayoutChanges="true"
|
||||
android:autoLink="web" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
see <http://www.gnu.org/licenses>.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/main_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -52,68 +51,8 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:singleLine="true"
|
||||
android:textSize="16sp"
|
||||
android:visibility="gone" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/account_info"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:baselineAligned="false"
|
||||
android:orientation="horizontal">
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:text="@string/following" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/account_fgc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:text="@string/followers" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/account_frc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/account_ds"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:animateLayoutChanges="true"
|
||||
android:autoLink="web" />
|
||||
</LinearLayout>
|
||||
android:ellipsize="end"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -125,6 +64,6 @@
|
|||
android:layout_gravity="center"
|
||||
android:contentDescription="@string/display_more"
|
||||
android:src="@drawable/ic_baseline_more_vert_24"
|
||||
android:visibility="gone" />
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue