mirror of
https://framagit.org/tom79/fedilab-tube
synced 2025-02-16 12:00:42 +01:00
Fix authentication
This commit is contained in:
parent
1bc99b3c46
commit
9dca5fcd3b
@ -96,10 +96,10 @@ public class AccountActivity extends AppCompatActivity {
|
||||
TextView username = findViewById(R.id.username);
|
||||
TextView displayname = findViewById(R.id.displayname);
|
||||
|
||||
setTitle(String.format("@%s", account.getName()));
|
||||
setTitle(String.format("@%s", account.getUsername()));
|
||||
|
||||
Helper.loadGiF(AccountActivity.this, account.getAvatar().getPath(), profile_picture);
|
||||
username.setText(String.format("@%s", account.getName()));
|
||||
username.setText(String.format("@%s", account.getUsername()));
|
||||
displayname.setText(account.getDisplayName());
|
||||
|
||||
instanceView.setText(account.getHost());
|
||||
@ -108,7 +108,7 @@ public class AccountActivity extends AppCompatActivity {
|
||||
Account finalAccount = account;
|
||||
logout_button.setOnClickListener(v -> {
|
||||
AlertDialog.Builder dialogBuilderLogoutAccount = new AlertDialog.Builder(AccountActivity.this);
|
||||
dialogBuilderLogoutAccount.setMessage(getString(R.string.logout_account_confirmation, finalAccount.getName(), finalAccount.getHost()));
|
||||
dialogBuilderLogoutAccount.setMessage(getString(R.string.logout_account_confirmation, finalAccount.getUsername(), finalAccount.getHost()));
|
||||
dialogBuilderLogoutAccount.setPositiveButton(R.string.action_logout, (dialog, id) -> {
|
||||
Helper.logoutCurrentUser(AccountActivity.this, finalAccount);
|
||||
dialog.dismiss();
|
||||
@ -277,7 +277,7 @@ public class AccountActivity extends AppCompatActivity {
|
||||
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.getName() + "@" + account.getHost());
|
||||
bundle.putString("name", account.getUsername() + "@" + account.getHost());
|
||||
bundle.putSerializable("accountFetch", RetrofitPeertubeAPI.DataType.CHANNEL);
|
||||
}
|
||||
displayAccountsFragment.setArguments(bundle);
|
||||
|
@ -270,7 +270,7 @@ public class AllPlaylistsActivity extends AppCompatActivity {
|
||||
channelId[0] = "null";
|
||||
|
||||
for (Account account : channels) {
|
||||
channelName[i] = account.getName();
|
||||
channelName[i] = account.getUsername();
|
||||
channelId[i] = account.getId();
|
||||
i++;
|
||||
}
|
||||
|
@ -35,16 +35,15 @@ import androidx.core.content.ContextCompat;
|
||||
import com.google.android.material.textfield.TextInputEditText;
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Arrays;
|
||||
|
||||
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.entities.Error;
|
||||
import app.fedilab.fedilabtube.client.entities.Oauth;
|
||||
import app.fedilab.fedilabtube.client.entities.OauthParams;
|
||||
import app.fedilab.fedilabtube.client.entities.RefreshToken;
|
||||
import app.fedilab.fedilabtube.client.entities.Token;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
@ -159,7 +158,7 @@ public class LoginActivity extends AppCompatActivity {
|
||||
if (Arrays.asList(Helper.openid).contains(host) && !BuildConfig.full_instances) {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Oauth oauth = new RetrofitPeertubeAPI(LoginActivity.this, instance, null).oauthClient();
|
||||
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);
|
||||
@ -184,7 +183,7 @@ public class LoginActivity extends AppCompatActivity {
|
||||
e.printStackTrace();
|
||||
runOnUiThread(() -> {
|
||||
connectionButton.setEnabled(true);
|
||||
Toasty.error(LoginActivity.this, getString(R.string.client_error), Toast.LENGTH_LONG).show();
|
||||
Toasty.error(LoginActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
||||
});
|
||||
}
|
||||
|
||||
@ -192,7 +191,7 @@ public class LoginActivity extends AppCompatActivity {
|
||||
} else {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Oauth oauth = new RetrofitPeertubeAPI(LoginActivity.this, instance, null).oauthClient();
|
||||
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);
|
||||
@ -203,15 +202,17 @@ public class LoginActivity extends AppCompatActivity {
|
||||
|
||||
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(sharedpreferences.getString(Helper.CLIENT_ID, null));
|
||||
oauthParams.setClient_secret(sharedpreferences.getString(Helper.CLIENT_SECRET, null));
|
||||
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) {
|
||||
@ -224,17 +225,30 @@ public class LoginActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
try {
|
||||
RefreshToken refreshToken = new RetrofitPeertubeAPI(LoginActivity.this, instance, null).manageToken(oauthParams);
|
||||
proceedLogin(refreshToken, host);
|
||||
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 {
|
||||
RefreshToken refreshToken = new RetrofitPeertubeAPI(LoginActivity.this, instance, null).manageToken(oauthParams);
|
||||
proceedLogin(refreshToken, host);
|
||||
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(() -> {
|
||||
@ -245,7 +259,7 @@ public class LoginActivity extends AppCompatActivity {
|
||||
else if (e2.getMessage() != null && e2.getMessage().trim().length() > 0)
|
||||
message = e2.getMessage();
|
||||
else
|
||||
message = getString(R.string.client_error);
|
||||
message = getString(R.string.toast_error);
|
||||
Toasty.error(LoginActivity.this, message, Toast.LENGTH_LONG).show();
|
||||
});
|
||||
}
|
||||
@ -259,7 +273,7 @@ public class LoginActivity extends AppCompatActivity {
|
||||
message = e.getMessage();
|
||||
}
|
||||
if (message == null) {
|
||||
message = getString(R.string.client_error);
|
||||
message = getString(R.string.toast_error);
|
||||
}
|
||||
Toasty.error(LoginActivity.this, message, Toast.LENGTH_LONG).show();
|
||||
});
|
||||
@ -270,16 +284,20 @@ public class LoginActivity extends AppCompatActivity {
|
||||
});
|
||||
}
|
||||
|
||||
private void proceedLogin(RefreshToken refreshToken, String host) {
|
||||
private void proceedLogin(Token token, String host) {
|
||||
runOnUiThread(() -> {
|
||||
JSONObject resobjLogin;
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, refreshToken.getAccess_token());
|
||||
editor.putString(Helper.PREF_INSTANCE, host);
|
||||
editor.apply();
|
||||
//Update the account with the token;
|
||||
updateCredential(LoginActivity.this, refreshToken.getAccess_token(), client_id, client_secret, refreshToken.getRefresh_token(), host);
|
||||
if (token != null) {
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token.getAccess_token());
|
||||
editor.putString(Helper.PREF_INSTANCE, host);
|
||||
|
||||
editor.apply();
|
||||
//Update the account with the token;
|
||||
updateCredential(LoginActivity.this, token.getAccess_token(), client_id, client_secret, token.getRefresh_token(), host);
|
||||
} else {
|
||||
connectionButton.setEnabled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.data.AccountData.Account;
|
||||
import app.fedilab.fedilabtube.client.entities.Error;
|
||||
import app.fedilab.fedilabtube.client.entities.OauthParams;
|
||||
import app.fedilab.fedilabtube.client.entities.PeertubeInformation;
|
||||
import app.fedilab.fedilabtube.client.entities.WellKnownNodeinfo;
|
||||
@ -171,7 +172,14 @@ public class MainActivity extends AppCompatActivity {
|
||||
oauthParams.setClient_id(account.getClient_id());
|
||||
oauthParams.setClient_secret(account.getClient_secret());
|
||||
oauthParams.setRefresh_token(account.getRefresh_token());
|
||||
new Thread(() -> new RetrofitPeertubeAPI(MainActivity.this).manageToken(oauthParams)).start();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
new RetrofitPeertubeAPI(MainActivity.this).manageToken(oauthParams);
|
||||
} catch (Error error) {
|
||||
|
||||
error.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
} else {
|
||||
instanceItem.setVisible(true);
|
||||
@ -184,6 +192,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == R.id.action_change_instance) {
|
||||
|
@ -86,7 +86,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.data.AccountData.Account;
|
||||
@ -105,9 +104,9 @@ import app.fedilab.fedilabtube.sqlite.AccountDAO;
|
||||
import app.fedilab.fedilabtube.sqlite.Sqlite;
|
||||
import app.fedilab.fedilabtube.viewmodel.CaptionsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.CommentVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.TimelineVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.PlaylistsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.PostActionsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.TimelineVM;
|
||||
import app.fedilab.fedilabtube.webview.CustomWebview;
|
||||
import app.fedilab.fedilabtube.webview.MastalabWebChromeClient;
|
||||
import app.fedilab.fedilabtube.webview.MastalabWebViewClient;
|
||||
@ -189,7 +188,7 @@ public class PeertubeActivity extends AppCompatActivity {
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = Helper.getLiveInstance(PeertubeActivity.this);
|
||||
Account account = new AccountDAO(PeertubeActivity.this, db).getUniqAccount(userId, instance);
|
||||
Helper.loadGiF(PeertubeActivity.this, account!=null&&account.getAvatar()!=null?account.getAvatar().getPath():null, my_pp);
|
||||
Helper.loadGiF(PeertubeActivity.this, account != null && account.getAvatar() != null ? account.getAvatar().getPath() : null, my_pp);
|
||||
|
||||
|
||||
if (Helper.isTablet(PeertubeActivity.this)) {
|
||||
@ -608,7 +607,6 @@ public class PeertubeActivity extends AppCompatActivity {
|
||||
});
|
||||
|
||||
|
||||
|
||||
if (mode == Helper.VIDEO_MODE_NORMAL) {
|
||||
|
||||
int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB);
|
||||
|
@ -66,8 +66,8 @@ import app.fedilab.fedilabtube.client.entities.VideoParams;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.viewmodel.ChannelsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.MyVideoVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.TimelineVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.PostActionsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.TimelineVM;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
import mabbas007.tagsedittext.TagsEditText;
|
||||
|
||||
@ -81,6 +81,8 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
|
||||
|
||||
private final int PICK_IMAGE = 50378;
|
||||
private final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 724;
|
||||
Item licenseToSend, privacyToSend, categoryToSend;
|
||||
ItemStr languageToSend;
|
||||
private Button set_upload_submit;
|
||||
private Spinner set_upload_privacy, set_upload_categories, set_upload_licenses, set_upload_languages, set_upload_channel;
|
||||
private EditText p_video_title, p_video_description;
|
||||
@ -94,8 +96,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
|
||||
private VideoParams videoParams;
|
||||
private Video video;
|
||||
private String channelToSendId;
|
||||
Item licenseToSend, privacyToSend, categoryToSend;
|
||||
ItemStr languageToSend;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -251,7 +252,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
|
||||
privacyToSend = video.getPrivacy();
|
||||
categoryToSend = video.getCategory();
|
||||
|
||||
Helper.loadGiF(PeertubeEditUploadActivity.this, video.getThumbnailPath(),p_video_preview);
|
||||
Helper.loadGiF(PeertubeEditUploadActivity.this, video.getThumbnailPath(), p_video_preview);
|
||||
|
||||
|
||||
set_preview.setOnClickListener(v -> {
|
||||
@ -503,7 +504,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
|
||||
videoParams.setDescription(description);
|
||||
videoParams.setNsfw(isNSFW1);
|
||||
videoParams.setCommentsEnabled(commentEnabled1);
|
||||
videoParams.setCategory((int)finalCategoryToSend.getId());
|
||||
videoParams.setCategory((int) finalCategoryToSend.getId());
|
||||
videoParams.setLicence(String.valueOf(finalLicenseToSend.getId()));
|
||||
videoParams.setLanguage(finalLanguageToSend.getId());
|
||||
videoParams.setChannelId(channelToSendId);
|
||||
@ -609,8 +610,8 @@ public class PeertubeEditUploadActivity extends AppCompatActivity {
|
||||
String[] channelName = new String[accounts.size()];
|
||||
int i = 0;
|
||||
for (Account account : accounts) {
|
||||
channels.put(account.getName(), account.getId());
|
||||
channelName[i] = account.getName();
|
||||
channels.put(account.getUsername(), account.getId());
|
||||
channelName[i] = account.getUsername();
|
||||
i++;
|
||||
}
|
||||
ArrayAdapter<String> adapterChannel = new ArrayAdapter<>(PeertubeEditUploadActivity.this,
|
||||
|
@ -169,8 +169,8 @@ public class PeertubeUploadActivity extends AppCompatActivity {
|
||||
String[] channelId = new String[accounts.size()];
|
||||
int i = 0;
|
||||
for (Account account : accounts) {
|
||||
channels.put(account.getName(), account.getId());
|
||||
channelName[i] = account.getName();
|
||||
channels.put(account.getUsername(), account.getId());
|
||||
channelName[i] = account.getUsername();
|
||||
channelId[i] = account.getId();
|
||||
i++;
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ public class ShowAccountActivity extends AppCompatActivity {
|
||||
ChannelsVM viewModel = new ViewModelProvider(ShowAccountActivity.this).get(ChannelsVM.class);
|
||||
|
||||
manageChannel();
|
||||
viewModel.get(CHANNEL, channelAcct==null?channel.getName()+"@"+channel.getHost():channelAcct).observe(ShowAccountActivity.this, this::manageViewAccounts);
|
||||
viewModel.get(CHANNEL, channelAcct == null ? channel.getName() + "@" + channel.getHost() : channelAcct).observe(ShowAccountActivity.this, this::manageViewAccounts);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -240,7 +240,7 @@ public class ShowAccountActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
manageNotes(channel);
|
||||
Helper.loadGiF(ShowAccountActivity.this, channel.getAvatar()!=null?channel.getAvatar().getPath():null, account_pp);
|
||||
Helper.loadGiF(ShowAccountActivity.this, channel.getAvatar() != null ? channel.getAvatar().getPath() : null, account_pp);
|
||||
//Follow button
|
||||
String target = channel.getAcct();
|
||||
|
||||
|
@ -48,7 +48,6 @@ import com.google.android.material.tabs.TabLayout;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -60,9 +59,9 @@ import app.fedilab.fedilabtube.fragment.DisplayAccountsFragment;
|
||||
import app.fedilab.fedilabtube.fragment.DisplayVideosFragment;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.viewmodel.ChannelsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.TimelineVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.PostActionsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.RelationshipVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.TimelineVM;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
import static androidx.core.text.HtmlCompat.FROM_HTML_MODE_LEGACY;
|
||||
@ -117,7 +116,7 @@ public class ShowChannelActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
ChannelsVM viewModel = new ViewModelProvider(ShowChannelActivity.this).get(ChannelsVM.class);
|
||||
viewModel.get(CHANNEL, channelAcct==null?channel.getAcct():channelAcct).observe(ShowChannelActivity.this, this::manageViewAccounts);
|
||||
viewModel.get(CHANNEL, channelAcct == null ? channel.getAcct() : channelAcct).observe(ShowChannelActivity.this, this::manageViewAccounts);
|
||||
manageChannel();
|
||||
}
|
||||
|
||||
@ -240,7 +239,7 @@ public class ShowChannelActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
manageNotes(channel);
|
||||
Helper.loadGiF(ShowChannelActivity.this, channel.getAvatar()!=null?channel.getAvatar().getPath():null, account_pp);
|
||||
Helper.loadGiF(ShowChannelActivity.this, channel.getAvatar() != null ? channel.getAvatar().getPath() : null, account_pp);
|
||||
//Follow button
|
||||
String target = channel.getAcct();
|
||||
|
||||
|
@ -28,12 +28,14 @@ import android.widget.ProgressBar;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.entities.Error;
|
||||
import app.fedilab.fedilabtube.client.entities.OauthParams;
|
||||
import app.fedilab.fedilabtube.client.entities.RefreshToken;
|
||||
import app.fedilab.fedilabtube.client.entities.Token;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.webview.CustomWebview;
|
||||
|
||||
@ -123,14 +125,20 @@ public class WebviewConnectActivity extends AppCompatActivity {
|
||||
oauthParams.setUsername(username);
|
||||
oauthParams.setExternalAuthToken(externalAuthToken);
|
||||
String instance = new URL(url).getHost();
|
||||
RefreshToken refreshToken = new RetrofitPeertubeAPI(WebviewConnectActivity.this, instance, null).manageToken(oauthParams);
|
||||
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, refreshToken.getAccess_token());
|
||||
editor.putString(Helper.PREF_INSTANCE, instance);
|
||||
editor.apply();
|
||||
updateCredential(WebviewConnectActivity.this, refreshToken.getAccess_token(), clientId, clientSecret, refreshToken.getRefresh_token(), new URL(url).getHost());
|
||||
finish();
|
||||
Token token = null;
|
||||
try {
|
||||
token = new RetrofitPeertubeAPI(WebviewConnectActivity.this, instance, null).manageToken(oauthParams);
|
||||
} catch (Error error) {
|
||||
Error.displayError(WebviewConnectActivity.this, error);
|
||||
}
|
||||
if (token != null) {
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token.getAccess_token());
|
||||
editor.putString(Helper.PREF_INSTANCE, instance);
|
||||
editor.apply();
|
||||
updateCredential(WebviewConnectActivity.this, token.getAccess_token(), clientId, clientSecret, token.getRefresh_token(), new URL(url).getHost());
|
||||
finish();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -28,19 +28,20 @@ import app.fedilab.fedilabtube.client.data.VideoData;
|
||||
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.OauthParams;
|
||||
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.RefreshToken;
|
||||
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 retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.DELETE;
|
||||
import retrofit2.http.Field;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Header;
|
||||
import retrofit2.http.POST;
|
||||
@ -86,8 +87,14 @@ public interface PeertubeService {
|
||||
|
||||
//TOKEN
|
||||
//Refresh
|
||||
@FormUrlEncoded
|
||||
@POST("users/token")
|
||||
Call<RefreshToken> manageToken(@Body OauthParams oauthParams);
|
||||
Call<Token> createToken(
|
||||
@Field("client_id") String client_id,
|
||||
@Field("client_secret") String client_secret,
|
||||
@Field("grant_type") String grant_type,
|
||||
@Field("username") String username,
|
||||
@Field("password") String password);
|
||||
|
||||
@GET("users/me")
|
||||
Call<AccountData.Account> verifyCredentials(@Header("Authorization") String credentials);
|
||||
@ -123,7 +130,7 @@ public interface PeertubeService {
|
||||
|
||||
//Search
|
||||
@GET("search/videos")
|
||||
Call<List<VideoData.Video>> searchVideos(@Query("search") String search, @Query("start") String maxId);
|
||||
Call<VideoData> searchVideos(@Query("search") String search, @Query("start") String maxId);
|
||||
|
||||
//Get notifications
|
||||
@GET("users/me/notifications")
|
||||
@ -151,7 +158,7 @@ public interface PeertubeService {
|
||||
|
||||
|
||||
@GET("oauth-clients/local")
|
||||
Call<Oauth> getOauth();
|
||||
Call<Oauth> getOauth(@Query("client_name") String client_name, @Query("redirect_uris") String redirect_uris, @Query("scopes") String scopes, @Query("website") String website);
|
||||
|
||||
|
||||
//Post/Update/Delete channel
|
||||
|
@ -33,6 +33,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import app.fedilab.fedilabtube.BuildConfig;
|
||||
import app.fedilab.fedilabtube.MainActivity;
|
||||
import app.fedilab.fedilabtube.R;
|
||||
import app.fedilab.fedilabtube.client.data.AccountData;
|
||||
@ -41,7 +42,6 @@ import app.fedilab.fedilabtube.client.data.ChannelData;
|
||||
import app.fedilab.fedilabtube.client.data.CommentData;
|
||||
import app.fedilab.fedilabtube.client.data.InstanceData;
|
||||
import app.fedilab.fedilabtube.client.data.NotificationData;
|
||||
import app.fedilab.fedilabtube.client.entities.OverviewVideo;
|
||||
import app.fedilab.fedilabtube.client.data.PlaylistData;
|
||||
import app.fedilab.fedilabtube.client.data.VideoData;
|
||||
import app.fedilab.fedilabtube.client.entities.AccountCreation;
|
||||
@ -50,11 +50,12 @@ import app.fedilab.fedilabtube.client.entities.Error;
|
||||
import app.fedilab.fedilabtube.client.entities.InstanceParams;
|
||||
import app.fedilab.fedilabtube.client.entities.Oauth;
|
||||
import app.fedilab.fedilabtube.client.entities.OauthParams;
|
||||
import app.fedilab.fedilabtube.client.entities.OverviewVideo;
|
||||
import app.fedilab.fedilabtube.client.entities.PeertubeInformation;
|
||||
import app.fedilab.fedilabtube.client.entities.PlaylistParams;
|
||||
import app.fedilab.fedilabtube.client.entities.Rating;
|
||||
import app.fedilab.fedilabtube.client.entities.RefreshToken;
|
||||
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 app.fedilab.fedilabtube.helper.Helper;
|
||||
@ -93,13 +94,67 @@ public class RetrofitPeertubeAPI {
|
||||
finalUrl = "https://" + instance + "/api/v1/";
|
||||
}
|
||||
|
||||
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;
|
||||
String instance;
|
||||
if (host.startsWith("tube") || BuildConfig.full_instances) {
|
||||
instance = host;
|
||||
} else {
|
||||
instance = Helper.getPeertubeUrl(host);
|
||||
}
|
||||
try {
|
||||
account = new RetrofitPeertubeAPI(activity, instance, token).verifyCredentials();
|
||||
} catch (Error error) {
|
||||
Error.displayError(activity, error);
|
||||
error.printStackTrace();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
//At the state the instance can be encoded
|
||||
instance = URLDecoder.decode(instance, "utf-8");
|
||||
} catch (UnsupportedEncodingException ignored) {
|
||||
}
|
||||
SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
account.setToken(token);
|
||||
account.setClient_id(client_id);
|
||||
account.setClient_secret(client_secret);
|
||||
account.setRefresh_token(refresh_token);
|
||||
account.setHost(instance);
|
||||
SQLiteDatabase db = Sqlite.getInstance(activity.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
boolean userExists = new AccountDAO(activity, db).userExist(account);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.PREF_KEY_ID, account.getId());
|
||||
if (!host.startsWith("tube")) {
|
||||
editor.putString(Helper.PREF_INSTANCE, host);
|
||||
}
|
||||
editor.apply();
|
||||
if (userExists)
|
||||
new AccountDAO(activity, db).updateAccountCredential(account);
|
||||
else {
|
||||
if (account.getUsername() != null && account.getCreatedAt() != null)
|
||||
new AccountDAO(activity, db).insertAccount(account);
|
||||
}
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> {
|
||||
Intent mainActivity = new Intent(activity, MainActivity.class);
|
||||
mainActivity.putExtra(Helper.INTENT_ACTION, Helper.ADD_USER_INTENT);
|
||||
activity.startActivity(mainActivity);
|
||||
activity.finish();
|
||||
};
|
||||
mainHandler.post(myRunnable);
|
||||
}).start();
|
||||
}
|
||||
|
||||
private PeertubeService init() {
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.baseUrl(finalUrl)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build();
|
||||
SharedPreferences sharedpreferences = _context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
if (token == null) {
|
||||
token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
}
|
||||
selection = sharedpreferences.getStringSet(_context.getString(R.string.set_video_language_choice), null);
|
||||
return retrofit.create(PeertubeService.class);
|
||||
}
|
||||
@ -112,29 +167,34 @@ public class RetrofitPeertubeAPI {
|
||||
return retrofit.create(PeertubeService.class);
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* Verifiy credential of the authenticated user *synchronously*
|
||||
* @return Account
|
||||
*/
|
||||
public RefreshToken manageToken(OauthParams oauthParams) {
|
||||
public Token manageToken(OauthParams oauthParams) throws Error {
|
||||
PeertubeService peertubeService = init();
|
||||
Call<RefreshToken> refreshTokenCall = peertubeService.manageToken(oauthParams);
|
||||
try {
|
||||
Response<RefreshToken> response = refreshTokenCall.execute();
|
||||
if (response.isSuccessful()) {
|
||||
return response.body();
|
||||
} else {
|
||||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
if (response.errorBody() != null) {
|
||||
error.setError(response.message());
|
||||
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());
|
||||
}
|
||||
if (refreshTokenCall != null) {
|
||||
try {
|
||||
Response<Token> response = refreshTokenCall.execute();
|
||||
if (response.isSuccessful()) {
|
||||
return response.body();
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
if (response.errorBody() != null) {
|
||||
error.setError(response.errorBody().string());
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -173,9 +233,9 @@ public class RetrofitPeertubeAPI {
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get caption content
|
||||
*
|
||||
* @param path String path to caption
|
||||
* @return APIResponse
|
||||
*/
|
||||
@ -206,12 +266,11 @@ public class RetrofitPeertubeAPI {
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get videos in a channel
|
||||
*
|
||||
* @param channelId String id of the channel
|
||||
* @param max_id String pagination
|
||||
* @param max_id String pagination
|
||||
* @return APIResponse
|
||||
*/
|
||||
public APIResponse getVideosForChannel(String channelId, String max_id) {
|
||||
@ -243,13 +302,11 @@ public class RetrofitPeertubeAPI {
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public APIResponse getTL(TimelineVM.TimelineType timelineType, String max_id) {
|
||||
APIResponse apiResponse = new APIResponse();
|
||||
PeertubeService peertubeService = init();
|
||||
Call<VideoData> videoCall = null;
|
||||
ArrayList<String> filter = selection!=null?new ArrayList<>(selection):null;
|
||||
ArrayList<String> filter = selection != null ? new ArrayList<>(selection) : null;
|
||||
switch (timelineType) {
|
||||
case MY_VIDEOS:
|
||||
videoCall = peertubeService.getMyVideo(token, max_id);
|
||||
@ -307,7 +364,7 @@ public class RetrofitPeertubeAPI {
|
||||
public APIResponse getOverviewVideo(String page) {
|
||||
APIResponse apiResponse = new APIResponse();
|
||||
PeertubeService peertubeService = init();
|
||||
ArrayList<String> filter = selection!=null?new ArrayList<>(selection):null;
|
||||
ArrayList<String> filter = selection != null ? new ArrayList<>(selection) : null;
|
||||
Call<OverviewVideo> overviewVideoCall = peertubeService.getOverviewVideos(page, filter);
|
||||
try {
|
||||
Response<OverviewVideo> response = overviewVideoCall.execute();
|
||||
@ -374,7 +431,7 @@ public class RetrofitPeertubeAPI {
|
||||
Call<CaptionData> captions = peertubeService.getCaptions(videoId);
|
||||
try {
|
||||
Response<CaptionData> response = captions.execute();
|
||||
if (response.isSuccessful() && response.body() !=null) {
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
apiResponse.setCaptions(response.body().data);
|
||||
} else {
|
||||
Error error = new Error();
|
||||
@ -558,12 +615,12 @@ public class RetrofitPeertubeAPI {
|
||||
*/
|
||||
public APIResponse searchPeertube(String query, String max_id) {
|
||||
PeertubeService peertubeService = init();
|
||||
Call<List<VideoData.Video>> searchVideosCall = peertubeService.searchVideos(query, max_id);
|
||||
Call<VideoData> searchVideosCall = peertubeService.searchVideos(query, max_id);
|
||||
APIResponse apiResponse = new APIResponse();
|
||||
try {
|
||||
Response<List<VideoData.Video>> response = searchVideosCall.execute();
|
||||
if (response.isSuccessful()) {
|
||||
apiResponse.setPeertubes(response.body());
|
||||
Response<VideoData> response = searchVideosCall.execute();
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
apiResponse.setPeertubes(response.body().data);
|
||||
} else {
|
||||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
@ -587,13 +644,13 @@ public class RetrofitPeertubeAPI {
|
||||
* Verifiy credential of the authenticated user *synchronously*
|
||||
* @return Account
|
||||
*/
|
||||
public AccountData.Account verifyCredentials(String token, String instance) {
|
||||
public AccountData.Account verifyCredentials() throws Error {
|
||||
PeertubeService peertubeService = init();
|
||||
Call<AccountData.Account> accountCall = peertubeService.verifyCredentials(token);
|
||||
Call<AccountData.Account> accountCall = peertubeService.verifyCredentials("Bearer " + token);
|
||||
APIResponse apiResponse = new APIResponse();
|
||||
try {
|
||||
Response<AccountData.Account> response = accountCall.execute();
|
||||
if (response.isSuccessful()) {
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
return response.body();
|
||||
} else {
|
||||
Error error = new Error();
|
||||
@ -603,7 +660,7 @@ public class RetrofitPeertubeAPI {
|
||||
} else {
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
}
|
||||
apiResponse.setError(error);
|
||||
throw error;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Error error = new Error();
|
||||
@ -652,7 +709,7 @@ public class RetrofitPeertubeAPI {
|
||||
public APIResponse updateVideo(String videoId, VideoParams videoParams, File thumbnail, File previewfile) {
|
||||
PeertubeService peertubeService = init();
|
||||
MultipartBody.Part bodyThumbnail = null;
|
||||
MultipartBody.Part bodyPreviewfile= null;
|
||||
MultipartBody.Part bodyPreviewfile = null;
|
||||
if (thumbnail != null) {
|
||||
RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), thumbnail);
|
||||
bodyThumbnail = MultipartBody.Part.createFormData("image", thumbnail.getName(), requestFile);
|
||||
@ -854,17 +911,17 @@ public class RetrofitPeertubeAPI {
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Oauth
|
||||
*
|
||||
* @return APIResponse
|
||||
*/
|
||||
public Oauth oauthClient() {
|
||||
public Oauth oauthClient(String client_name, String redirect_uris, String scopes, String website) {
|
||||
PeertubeService peertubeService = init();
|
||||
try {
|
||||
Call<Oauth> oauth = peertubeService.getOauth();
|
||||
Call<Oauth> oauth = peertubeService.getOauth(client_name, redirect_uris, scopes, website);
|
||||
Response<Oauth> response = oauth.execute();
|
||||
if( response.isSuccessful() && response.body() != null) {
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
return response.body();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@ -873,10 +930,9 @@ public class RetrofitPeertubeAPI {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get NodeInfo
|
||||
*
|
||||
* @param instance String
|
||||
* @return APIResponse
|
||||
*/
|
||||
@ -885,7 +941,7 @@ public class RetrofitPeertubeAPI {
|
||||
try {
|
||||
Call<WellKnownNodeinfo> wellKnownNodeinfoCall = peertubeService.getWellKnownNodeinfo();
|
||||
Response<WellKnownNodeinfo> response = wellKnownNodeinfoCall.execute();
|
||||
if( response.isSuccessful() && response.body() != null) {
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
if (response.body().getHref() != null) {
|
||||
Call<WellKnownNodeinfo.NodeInfo> nodeinfo = peertubeService.getNodeinfo(response.body().getHref());
|
||||
Response<WellKnownNodeinfo.NodeInfo> responseNodeInfo = nodeinfo.execute();
|
||||
@ -898,9 +954,6 @@ public class RetrofitPeertubeAPI {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get channel data
|
||||
*
|
||||
@ -916,7 +969,7 @@ public class RetrofitPeertubeAPI {
|
||||
case MY_CHANNELS:
|
||||
case CHANNELS_FOR_ACCOUNT:
|
||||
Call<List<ChannelData.Channel>> channelDataCall;
|
||||
if( accountDataType == DataType.MY_CHANNELS) {
|
||||
if (accountDataType == DataType.MY_CHANNELS) {
|
||||
channelDataCall = peertubeService.getMyChannels(token);
|
||||
} else {
|
||||
channelDataCall = peertubeService.getChannelsForAccount(element);
|
||||
@ -933,7 +986,7 @@ public class RetrofitPeertubeAPI {
|
||||
}
|
||||
apiResponse.setError(error);
|
||||
} else {
|
||||
apiResponse.setChannels( response.body());
|
||||
apiResponse.setChannels(response.body());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Error error = new Error();
|
||||
@ -1286,56 +1339,6 @@ public class RetrofitPeertubeAPI {
|
||||
|
||||
}
|
||||
|
||||
public static void updateCredential(Context _mContext, String token, String client_id, String client_secret, String refresh_token, String host) {
|
||||
new Thread(() -> {
|
||||
AccountData.Account account;
|
||||
String instance;
|
||||
if (host.startsWith("tube")) {
|
||||
instance = host;
|
||||
} else {
|
||||
instance = Helper.getPeertubeUrl(host);
|
||||
}
|
||||
account = new RetrofitPeertubeAPI(_mContext).verifyCredentials(token, instance);
|
||||
if (account == null)
|
||||
return;
|
||||
try {
|
||||
//At the state the instance can be encoded
|
||||
instance = URLDecoder.decode(instance, "utf-8");
|
||||
} catch (UnsupportedEncodingException ignored) {
|
||||
}
|
||||
SharedPreferences sharedpreferences = _mContext.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
account.setToken(token);
|
||||
account.setClient_id(client_id);
|
||||
account.setClient_secret(client_secret);
|
||||
account.setRefresh_token(refresh_token);
|
||||
account.setHost(instance);
|
||||
SQLiteDatabase db = Sqlite.getInstance(_mContext.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
boolean userExists = new AccountDAO(_mContext, db).userExist(account);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.PREF_KEY_ID, account.getId());
|
||||
if (!host.startsWith("tube")) {
|
||||
editor.putString(Helper.PREF_INSTANCE, host);
|
||||
}
|
||||
editor.apply();
|
||||
if (userExists)
|
||||
new AccountDAO(_mContext, db).updateAccountCredential(account);
|
||||
else {
|
||||
if (account.getName() != null && account.getCreatedAt() != null)
|
||||
new AccountDAO(_mContext, db).insertAccount(account);
|
||||
}
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> {
|
||||
Intent mainActivity = new Intent(_mContext, MainActivity.class);
|
||||
mainActivity.putExtra(Helper.INTENT_ACTION, Helper.ADD_USER_INTENT);
|
||||
_mContext.startActivity(mainActivity);
|
||||
((Activity) _mContext).finish();
|
||||
};
|
||||
mainHandler.post(myRunnable);
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public enum DataType {
|
||||
SUBSCRIBER,
|
||||
|
@ -63,13 +63,12 @@ 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;
|
||||
private String acct;
|
||||
private String token;
|
||||
private String client_id;
|
||||
private String client_secret;
|
||||
@ -90,7 +89,7 @@ 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();
|
||||
@ -168,12 +167,12 @@ public class AccountData {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
public void setUsername(String name) {
|
||||
this.username = name;
|
||||
}
|
||||
|
||||
public Date getUpdatedAt() {
|
||||
@ -201,12 +200,9 @@ public class AccountData {
|
||||
}
|
||||
|
||||
public String getAcct() {
|
||||
return acct;
|
||||
return username + "@" + host;
|
||||
}
|
||||
|
||||
public void setAcct(String acct) {
|
||||
this.acct = acct;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
@ -256,7 +252,7 @@ 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);
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ public class ChannelData {
|
||||
}
|
||||
|
||||
public String getAcct() {
|
||||
return name+"@"+host;
|
||||
return name + "@" + host;
|
||||
}
|
||||
|
||||
public void setAcct(String acct) {
|
||||
|
@ -43,6 +43,17 @@ public class VideoData {
|
||||
public List<Video> data;
|
||||
|
||||
public static class Video implements Parcelable {
|
||||
public static final Creator<Video> CREATOR = new Creator<Video>() {
|
||||
@Override
|
||||
public Video createFromParcel(Parcel source) {
|
||||
return new Video(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Video[] newArray(int size) {
|
||||
return new Video[size];
|
||||
}
|
||||
};
|
||||
@SerializedName("account")
|
||||
private Account account;
|
||||
@SerializedName("blacklisted")
|
||||
@ -113,25 +124,61 @@ public class VideoData {
|
||||
private int views;
|
||||
@SerializedName("waitTranscoding")
|
||||
private boolean waitTranscoding;
|
||||
|
||||
private String myRating;
|
||||
|
||||
//Dedicated to overview videos to reuse the logic of videos
|
||||
private boolean hasTitle = false;
|
||||
private String title;
|
||||
private titleType titleType;
|
||||
|
||||
|
||||
public enum titleType{
|
||||
TAG,
|
||||
CATEGORY,
|
||||
CHANNEL
|
||||
}
|
||||
|
||||
public Video() {
|
||||
}
|
||||
|
||||
|
||||
protected Video(Parcel in) {
|
||||
this.account = in.readParcelable(Account.class.getClassLoader());
|
||||
this.blacklisted = in.readByte() != 0;
|
||||
this.blacklistedReason = in.readString();
|
||||
this.category = in.readParcelable(Item.class.getClassLoader());
|
||||
this.channel = in.readParcelable(ChannelData.Channel.class.getClassLoader());
|
||||
this.commentsEnabled = in.readByte() != 0;
|
||||
long tmpCreatedAt = in.readLong();
|
||||
this.createdAt = tmpCreatedAt == -1 ? null : new Date(tmpCreatedAt);
|
||||
this.description = in.readString();
|
||||
this.descriptionPath = in.readString();
|
||||
this.dislikes = in.readInt();
|
||||
this.downloadEnabled = in.readByte() != 0;
|
||||
this.duration = in.readInt();
|
||||
this.embedPath = in.readString();
|
||||
this.files = new ArrayList<>();
|
||||
in.readList(this.files, File.class.getClassLoader());
|
||||
this.id = in.readString();
|
||||
this.isLocal = in.readByte() != 0;
|
||||
this.language = in.readParcelable(ItemStr.class.getClassLoader());
|
||||
this.licence = in.readParcelable(Item.class.getClassLoader());
|
||||
this.likes = in.readInt();
|
||||
this.name = in.readString();
|
||||
this.nsfw = in.readByte() != 0;
|
||||
long tmpOriginallyPublishedAt = in.readLong();
|
||||
this.originallyPublishedAt = tmpOriginallyPublishedAt == -1 ? null : new Date(tmpOriginallyPublishedAt);
|
||||
this.previewPath = in.readString();
|
||||
this.privacy = in.readParcelable(Item.class.getClassLoader());
|
||||
long tmpPublishedAt = in.readLong();
|
||||
this.publishedAt = tmpPublishedAt == -1 ? null : new Date(tmpPublishedAt);
|
||||
this.state = in.readParcelable(Item.class.getClassLoader());
|
||||
this.streamingPlaylists = new ArrayList<>();
|
||||
in.readList(this.streamingPlaylists, StreamingPlaylists.class.getClassLoader());
|
||||
this.support = in.readString();
|
||||
this.tags = in.createStringArrayList();
|
||||
this.thumbnailPath = in.readString();
|
||||
this.trackerUrls = in.createStringArrayList();
|
||||
long tmpUpdatedAt = in.readLong();
|
||||
this.updatedAt = tmpUpdatedAt == -1 ? null : new Date(tmpUpdatedAt);
|
||||
this.uuid = in.readString();
|
||||
this.views = in.readInt();
|
||||
this.waitTranscoding = in.readByte() != 0;
|
||||
this.myRating = in.readString();
|
||||
}
|
||||
|
||||
public String getFileUrl(String resolution, Context context) {
|
||||
|
||||
if (resolution != null) {
|
||||
@ -539,62 +586,11 @@ public class VideoData {
|
||||
dest.writeString(this.myRating);
|
||||
}
|
||||
|
||||
protected Video(Parcel in) {
|
||||
this.account = in.readParcelable(Account.class.getClassLoader());
|
||||
this.blacklisted = in.readByte() != 0;
|
||||
this.blacklistedReason = in.readString();
|
||||
this.category = in.readParcelable(Item.class.getClassLoader());
|
||||
this.channel = in.readParcelable(ChannelData.Channel.class.getClassLoader());
|
||||
this.commentsEnabled = in.readByte() != 0;
|
||||
long tmpCreatedAt = in.readLong();
|
||||
this.createdAt = tmpCreatedAt == -1 ? null : new Date(tmpCreatedAt);
|
||||
this.description = in.readString();
|
||||
this.descriptionPath = in.readString();
|
||||
this.dislikes = in.readInt();
|
||||
this.downloadEnabled = in.readByte() != 0;
|
||||
this.duration = in.readInt();
|
||||
this.embedPath = in.readString();
|
||||
this.files = new ArrayList<>();
|
||||
in.readList(this.files, File.class.getClassLoader());
|
||||
this.id = in.readString();
|
||||
this.isLocal = in.readByte() != 0;
|
||||
this.language = in.readParcelable(ItemStr.class.getClassLoader());
|
||||
this.licence = in.readParcelable(Item.class.getClassLoader());
|
||||
this.likes = in.readInt();
|
||||
this.name = in.readString();
|
||||
this.nsfw = in.readByte() != 0;
|
||||
long tmpOriginallyPublishedAt = in.readLong();
|
||||
this.originallyPublishedAt = tmpOriginallyPublishedAt == -1 ? null : new Date(tmpOriginallyPublishedAt);
|
||||
this.previewPath = in.readString();
|
||||
this.privacy = in.readParcelable(Item.class.getClassLoader());
|
||||
long tmpPublishedAt = in.readLong();
|
||||
this.publishedAt = tmpPublishedAt == -1 ? null : new Date(tmpPublishedAt);
|
||||
this.state = in.readParcelable(Item.class.getClassLoader());
|
||||
this.streamingPlaylists = new ArrayList<>();
|
||||
in.readList(this.streamingPlaylists, StreamingPlaylists.class.getClassLoader());
|
||||
this.support = in.readString();
|
||||
this.tags = in.createStringArrayList();
|
||||
this.thumbnailPath = in.readString();
|
||||
this.trackerUrls = in.createStringArrayList();
|
||||
long tmpUpdatedAt = in.readLong();
|
||||
this.updatedAt = tmpUpdatedAt == -1 ? null : new Date(tmpUpdatedAt);
|
||||
this.uuid = in.readString();
|
||||
this.views = in.readInt();
|
||||
this.waitTranscoding = in.readByte() != 0;
|
||||
this.myRating = in.readString();
|
||||
public enum titleType {
|
||||
TAG,
|
||||
CATEGORY,
|
||||
CHANNEL
|
||||
}
|
||||
|
||||
public static final Creator<Video> CREATOR = new Creator<Video>() {
|
||||
@Override
|
||||
public Video createFromParcel(Parcel source) {
|
||||
return new Video(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Video[] newArray(int size) {
|
||||
return new Video[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static class VideoImport {
|
||||
@ -650,6 +646,5 @@ public class VideoData {
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -14,11 +14,33 @@ package app.fedilab.fedilabtube.client.entities;
|
||||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
public class Error {
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.widget.Toast;
|
||||
|
||||
import app.fedilab.fedilabtube.R;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
public class Error extends Throwable {
|
||||
|
||||
private String error = null;
|
||||
private int statusCode = -1;
|
||||
|
||||
public static void displayError(Context context, Error error) {
|
||||
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> {
|
||||
String message;
|
||||
if (error.getError() != null && error.getError().trim().length() > 0)
|
||||
message = error.getError();
|
||||
else
|
||||
message = context.getString(R.string.toast_error);
|
||||
Toasty.error(context, message, Toast.LENGTH_LONG).show();
|
||||
};
|
||||
mainHandler.post(myRunnable);
|
||||
}
|
||||
|
||||
public String getError() {
|
||||
return error;
|
||||
}
|
||||
@ -34,4 +56,5 @@ public class Error {
|
||||
public void setStatusCode(int statusCode) {
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,11 +22,31 @@ import com.google.gson.annotations.SerializedName;
|
||||
@SuppressWarnings("unused")
|
||||
public class ItemStr implements Parcelable {
|
||||
|
||||
public static final Creator<ItemStr> CREATOR = new Creator<ItemStr>() {
|
||||
@Override
|
||||
public ItemStr createFromParcel(Parcel source) {
|
||||
return new ItemStr(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStr[] newArray(int size) {
|
||||
return new ItemStr[size];
|
||||
}
|
||||
};
|
||||
@SerializedName("id")
|
||||
private String id;
|
||||
@SerializedName("label")
|
||||
private String label;
|
||||
|
||||
public ItemStr() {
|
||||
}
|
||||
|
||||
|
||||
protected ItemStr(Parcel in) {
|
||||
this.id = in.readString();
|
||||
this.label = in.readString();
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
@ -35,8 +55,6 @@ public class ItemStr implements Parcelable {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
@ -55,24 +73,4 @@ public class ItemStr implements Parcelable {
|
||||
dest.writeString(this.id);
|
||||
dest.writeString(this.label);
|
||||
}
|
||||
|
||||
public ItemStr() {
|
||||
}
|
||||
|
||||
protected ItemStr(Parcel in) {
|
||||
this.id = in.readString();
|
||||
this.label = in.readString();
|
||||
}
|
||||
|
||||
public static final Creator<ItemStr> CREATOR = new Creator<ItemStr>() {
|
||||
@Override
|
||||
public ItemStr createFromParcel(Parcel source) {
|
||||
return new ItemStr(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStr[] newArray(int size) {
|
||||
return new ItemStr[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -18,12 +18,13 @@ import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class OauthParams {
|
||||
|
||||
@SerializedName("grant_type")
|
||||
private String grant_type;
|
||||
@SerializedName("client_secret")
|
||||
private String client_secret;
|
||||
|
||||
@SerializedName("client_id")
|
||||
private String client_id;
|
||||
@SerializedName("client_secret")
|
||||
private String client_secret;
|
||||
@SerializedName("grant_type")
|
||||
private String grant_type;
|
||||
@SerializedName("username")
|
||||
private String username;
|
||||
@SerializedName("password")
|
||||
|
@ -13,6 +13,7 @@ package app.fedilab.fedilabtube.client.entities;
|
||||
*
|
||||
* 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;
|
||||
@ -81,7 +82,7 @@ public class StreamingPlaylists {
|
||||
this.redundancies = redundancies;
|
||||
}
|
||||
|
||||
public static class Redundancies{
|
||||
public static class Redundancies {
|
||||
@SerializedName("baseUrl")
|
||||
private String baseUrl;
|
||||
|
||||
|
@ -16,7 +16,7 @@ package app.fedilab.fedilabtube.client.entities;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class RefreshToken {
|
||||
public class Token {
|
||||
|
||||
@SerializedName("access_token")
|
||||
private String access_token;
|
@ -63,7 +63,7 @@ public class WellKnownNodeinfo {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Software{
|
||||
public static class Software {
|
||||
@SerializedName("name")
|
||||
private String name;
|
||||
@SerializedName("version")
|
||||
|
@ -62,7 +62,7 @@ public class AccountsHorizontalListAdapter extends RecyclerView.Adapter<Recycler
|
||||
if (account.getDisplayName() != null && !account.getDisplayName().trim().equals(""))
|
||||
holder.account_dn.setText(account.getDisplayName());
|
||||
else
|
||||
holder.account_dn.setText(account.getName().replace("@", ""));
|
||||
holder.account_dn.setText(account.getUsername().replace("@", ""));
|
||||
|
||||
//Profile picture
|
||||
Helper.loadGiF(context, account.getAvatar().getPath(), holder.account_pp, 270);
|
||||
|
@ -86,7 +86,7 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
}
|
||||
|
||||
holder.account_dn.setText(account.getDisplayName());
|
||||
holder.account_ac.setText(String.format("@%s", account.getName()));
|
||||
holder.account_ac.setText(String.format("@%s", account.getUsername()));
|
||||
if (account.getDescription() == null) {
|
||||
account.setDescription("");
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ public class CommentListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
||||
|
||||
holder.status_account_displayname.setVisibility(View.GONE);
|
||||
if (comment.getAccount() != null) {
|
||||
holder.status_account_displayname_owner.setText(comment.getAccount().getName().replace("@", ""), TextView.BufferType.SPANNABLE);
|
||||
holder.status_account_displayname_owner.setText(comment.getAccount().getUsername().replace("@", ""), TextView.BufferType.SPANNABLE);
|
||||
Spannable wordtoSpan;
|
||||
Pattern hashAcct;
|
||||
wordtoSpan = new SpannableString("@" + comment.getAccount().getAcct());
|
||||
|
@ -76,7 +76,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||
Helper.loadGiF(context, account.getAvatar().getPath(), holder.peertube_profile);
|
||||
} else {
|
||||
holder.peertube_account_name.setText(peertube.getChannel().getAcct());
|
||||
Helper.loadGiF(context, peertube.getChannel().getAvatar()!=null?peertube.getChannel().getAvatar().getPath():null, holder.peertube_profile);
|
||||
Helper.loadGiF(context, peertube.getChannel().getAvatar() != null ? peertube.getChannel().getAvatar().getPath() : null, holder.peertube_profile);
|
||||
}
|
||||
holder.peertube_title.setText(peertube.getName());
|
||||
holder.peertube_duration.setText(Helper.secondsToString(peertube.getDuration()));
|
||||
@ -86,9 +86,9 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||
Helper.loadGiF(context, peertube.getThumbnailPath(), holder.peertube_video_image);
|
||||
|
||||
//For Overview Videos: boolean values for displaying title is managed in the fragment
|
||||
if( peertube.isHasTitle()) {
|
||||
if (peertube.isHasTitle()) {
|
||||
holder.header_title.setVisibility(View.VISIBLE);
|
||||
switch (peertube.getTitleType()){
|
||||
switch (peertube.getTitleType()) {
|
||||
case TAG:
|
||||
holder.header_title.setText(String.format("#%s", peertube.getTitle()));
|
||||
break;
|
||||
@ -97,7 +97,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||
holder.header_title.setText(String.format("%s", peertube.getTitle()));
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
holder.header_title.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ public class PeertubeNotificationsListAdapter extends RecyclerView.Adapter<Recyc
|
||||
String profileUrl = notification.getComment().getAccount().getAvatar().getPath();
|
||||
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.getName());
|
||||
String message = context.getString(R.string.peertube_comment_on_video, accountAction.getDisplayName(), accountAction.getUsername());
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
holder.peertube_notif_message.setText(Html.fromHtml(message, Html.FROM_HTML_MODE_LEGACY));
|
||||
@ -150,7 +150,7 @@ public class PeertubeNotificationsListAdapter extends RecyclerView.Adapter<Recyc
|
||||
if (finalAccountAction != null) {
|
||||
Intent intent = new Intent(context, ShowChannelActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
b.putString("channelId", finalAccountAction.getName() + "@" + finalAccountAction.getHost());
|
||||
b.putString("channelId", finalAccountAction.getUsername() + "@" + finalAccountAction.getHost());
|
||||
intent.putExtras(b);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
@ -31,8 +31,6 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -91,8 +89,6 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
|
||||
accountsListAdapter = new AccountsListAdapter(accountFetch, this.accounts);
|
||||
accountsListAdapter.allAccountsRemoved = this;
|
||||
lv_accounts.setAdapter(accountsListAdapter);
|
||||
FloatingActionButton action_button = rootView.findViewById(R.id.action_button);
|
||||
action_button.setVisibility(View.GONE);
|
||||
TextView no_action_text = rootView.findViewById(R.id.no_action_text);
|
||||
if (accountFetch == RetrofitPeertubeAPI.DataType.MUTED) {
|
||||
no_action_text.setText(context.getString(R.string.no_muted));
|
||||
|
@ -40,8 +40,8 @@ import java.util.List;
|
||||
|
||||
import app.fedilab.fedilabtube.R;
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.entities.OverviewVideo;
|
||||
import app.fedilab.fedilabtube.client.data.VideoData;
|
||||
import app.fedilab.fedilabtube.client.entities.OverviewVideo;
|
||||
import app.fedilab.fedilabtube.drawer.AccountsHorizontalListAdapter;
|
||||
import app.fedilab.fedilabtube.drawer.PeertubeAdapter;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
@ -192,7 +192,6 @@ public class DisplayOverviewFragment extends Fragment implements AccountsHorizon
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void manageVIewVideos(APIResponse apiResponse) {
|
||||
//hide loaders
|
||||
mainLoader.setVisibility(View.GONE);
|
||||
@ -211,7 +210,7 @@ public class DisplayOverviewFragment extends Fragment implements AccountsHorizon
|
||||
OverviewVideo overviewVideos = apiResponse.getOverviewVideo();
|
||||
int totalAdded = 0;
|
||||
int previousPosition = this.peertubes.size();
|
||||
if( overviewVideos.getCategories() != null) {
|
||||
if (overviewVideos.getCategories().size() > 0 && overviewVideos.getCategories() != null) {
|
||||
String categoryTitle = overviewVideos.getCategories().get(0).getCategory().getLabel();
|
||||
List<VideoData.Video> videoCategories = overviewVideos.getCategories().get(0).getVideos();
|
||||
int i = 0;
|
||||
@ -226,7 +225,7 @@ public class DisplayOverviewFragment extends Fragment implements AccountsHorizon
|
||||
totalAdded++;
|
||||
}
|
||||
}
|
||||
if( overviewVideos.getTags().get(0) != null) {
|
||||
if (overviewVideos.getTags().size() > 0 && overviewVideos.getTags().get(0) != null) {
|
||||
String tagTitle = overviewVideos.getTags().get(0).getTag();
|
||||
List<VideoData.Video> videoTags = overviewVideos.getTags().get(0).getVideos();
|
||||
int i = 0;
|
||||
@ -241,7 +240,7 @@ public class DisplayOverviewFragment extends Fragment implements AccountsHorizon
|
||||
totalAdded++;
|
||||
}
|
||||
}
|
||||
if( overviewVideos.getChannels().get(0).getChannels() != null) {
|
||||
if (overviewVideos.getChannels().size() > 0 && overviewVideos.getChannels().get(0).getChannels() != null) {
|
||||
String channelTitle = overviewVideos.getChannels().get(0).getChannels().getAcct();
|
||||
List<VideoData.Video> videoChannels = overviewVideos.getChannels().get(0).getVideos();
|
||||
int i = 0;
|
||||
@ -320,6 +319,15 @@ public class DisplayOverviewFragment extends Fragment implements AccountsHorizon
|
||||
pullToRefresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage timeline load
|
||||
*
|
||||
* @param page String pagination
|
||||
*/
|
||||
private void loadTimeline(int page) {
|
||||
viewModelFeeds.getOverviewVideos(String.valueOf(page)).observe(DisplayOverviewFragment.this.requireActivity(), this::manageVIewVideos);
|
||||
}
|
||||
|
||||
static class GridSpacingItemDecoration extends RecyclerView.ItemDecoration {
|
||||
|
||||
private int spanCount;
|
||||
@ -354,13 +362,4 @@ public class DisplayOverviewFragment extends Fragment implements AccountsHorizon
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Manage timeline load
|
||||
* @param page String pagination
|
||||
*/
|
||||
private void loadTimeline(int page) {
|
||||
viewModelFeeds.getOverviewVideos(String.valueOf(page)).observe(DisplayOverviewFragment.this.requireActivity(), this::manageVIewVideos);
|
||||
}
|
||||
}
|
||||
|
@ -281,8 +281,8 @@ public class DisplayPlaylistsFragment extends Fragment {
|
||||
channelId[0] = "";
|
||||
channels = new HashMap<>();
|
||||
for (Account account : accounts) {
|
||||
channels.put(account.getName(), account.getId());
|
||||
channelName[i] = account.getName();
|
||||
channels.put(account.getUsername(), account.getId());
|
||||
channelName[i] = account.getUsername();
|
||||
channelId[i] = account.getId();
|
||||
i++;
|
||||
}
|
||||
|
@ -51,8 +51,8 @@ import app.fedilab.fedilabtube.drawer.AccountsHorizontalListAdapter;
|
||||
import app.fedilab.fedilabtube.drawer.PeertubeAdapter;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.viewmodel.AccountsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.TimelineVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.SearchVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.TimelineVM;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
|
||||
@ -383,6 +383,23 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
||||
pullToRefresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage timeline load
|
||||
*
|
||||
* @param max_id String pagination
|
||||
*/
|
||||
private void loadTimeline(String max_id) {
|
||||
if (search_peertube == null) { //Not a Peertube search
|
||||
if (type == TimelineVM.TimelineType.USER_VIDEOS) {
|
||||
viewModelFeeds.getVideosInChannel(channelId, max_id).observe(this.requireActivity(), this::manageVIewVideos);
|
||||
} else {
|
||||
viewModelFeeds.getVideos(type, max_id).observe(this.requireActivity(), this::manageVIewVideos);
|
||||
}
|
||||
} else {
|
||||
viewModelSearch.getVideos(max_id, search_peertube).observe(this.requireActivity(), this::manageVIewVideos);
|
||||
}
|
||||
}
|
||||
|
||||
static class GridSpacingItemDecoration extends RecyclerView.ItemDecoration {
|
||||
|
||||
private int spanCount;
|
||||
@ -417,21 +434,4 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Manage timeline load
|
||||
* @param max_id String pagination
|
||||
*/
|
||||
private void loadTimeline(String max_id) {
|
||||
if (search_peertube == null) { //Not a Peertube search
|
||||
if( type == TimelineVM.TimelineType.USER_VIDEOS){
|
||||
viewModelFeeds.getVideosInChannel(channelId, max_id).observe(this.requireActivity(), this::manageVIewVideos);
|
||||
}else {
|
||||
viewModelFeeds.getVideos(type, max_id).observe(this.requireActivity(), this::manageVIewVideos);
|
||||
}
|
||||
} else {
|
||||
viewModelSearch.getVideos(max_id, search_peertube).observe(this.requireActivity(), this::manageVIewVideos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,16 +55,22 @@ public class AccountDAO {
|
||||
if (account.getDescription() == null)
|
||||
account.setDescription("");
|
||||
values.put(Sqlite.COL_USER_ID, account.getId());
|
||||
values.put(Sqlite.COL_USERNAME, account.getName());
|
||||
values.put(Sqlite.COL_ACCT, account.getName() + "@" + account.getHost());
|
||||
values.put(Sqlite.COL_DISPLAYED_NAME, account.getDisplayName());
|
||||
values.put(Sqlite.COL_USERNAME, account.getUsername());
|
||||
values.put(Sqlite.COL_ACCT, account.getUsername() + "@" + account.getHost());
|
||||
values.put(Sqlite.COL_DISPLAYED_NAME, account.getDisplayName() != null ? account.getDisplayName() : account.getUsername());
|
||||
values.put(Sqlite.COL_FOLLOWERS_COUNT, account.getFollowersCount());
|
||||
values.put(Sqlite.COL_FOLLOWING_COUNT, account.getFollowingCount());
|
||||
values.put(Sqlite.COL_NOTE, account.getDescription());
|
||||
values.put(Sqlite.COL_URL, account.getUrl());
|
||||
values.put(Sqlite.COL_AVATAR, account.getAvatar().getPath());
|
||||
values.put(Sqlite.COL_AVATAR, account.getAvatar() != null ? account.getAvatar().getPath() : "null");
|
||||
values.put(Sqlite.COL_CREATED_AT, Helper.dateToString(account.getCreatedAt()));
|
||||
values.put(Sqlite.COL_INSTANCE, account.getHost());
|
||||
values.put(Sqlite.COL_LOCKED, false);
|
||||
values.put(Sqlite.COL_STATUSES_COUNT, 0);
|
||||
values.put(Sqlite.COL_URL, "");
|
||||
values.put(Sqlite.COL_AVATAR_STATIC, "");
|
||||
values.put(Sqlite.COL_HEADER, "");
|
||||
values.put(Sqlite.COL_HEADER_STATIC, "");
|
||||
if (account.getClient_id() != null && account.getClient_secret() != null) {
|
||||
values.put(Sqlite.COL_CLIENT_ID, account.getClient_id());
|
||||
values.put(Sqlite.COL_CLIENT_SECRET, account.getClient_secret());
|
||||
@ -98,8 +104,8 @@ public class AccountDAO {
|
||||
account.setCreatedAt(new Date());
|
||||
if (account.getDescription() == null)
|
||||
account.setDescription("");
|
||||
values.put(Sqlite.COL_USERNAME, account.getName());
|
||||
values.put(Sqlite.COL_ACCT, account.getName() + "@" + account.getHost());
|
||||
values.put(Sqlite.COL_USERNAME, account.getUsername());
|
||||
values.put(Sqlite.COL_ACCT, account.getUsername() + "@" + account.getHost());
|
||||
values.put(Sqlite.COL_DISPLAYED_NAME, account.getDisplayName());
|
||||
values.put(Sqlite.COL_FOLLOWERS_COUNT, account.getFollowersCount());
|
||||
values.put(Sqlite.COL_FOLLOWING_COUNT, account.getFollowingCount());
|
||||
@ -134,8 +140,8 @@ public class AccountDAO {
|
||||
account.setCreatedAt(new Date());
|
||||
if (account.getDescription() == null)
|
||||
account.setDescription("");
|
||||
values.put(Sqlite.COL_USERNAME, account.getName());
|
||||
values.put(Sqlite.COL_ACCT, account.getName() + "@" + account.getHost());
|
||||
values.put(Sqlite.COL_USERNAME, account.getUsername());
|
||||
values.put(Sqlite.COL_ACCT, account.getUsername() + "@" + account.getHost());
|
||||
values.put(Sqlite.COL_DISPLAYED_NAME, account.getDisplayName());
|
||||
values.put(Sqlite.COL_FOLLOWERS_COUNT, account.getFollowersCount());
|
||||
values.put(Sqlite.COL_FOLLOWING_COUNT, account.getFollowingCount());
|
||||
@ -239,7 +245,7 @@ public class AccountDAO {
|
||||
*/
|
||||
public boolean userExist(Account account) {
|
||||
Cursor mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_USER_ACCOUNT
|
||||
+ " where " + Sqlite.COL_USERNAME + " = '" + account.getName() + "' AND " + Sqlite.COL_INSTANCE + " = '" + account.getHost() + "'", null);
|
||||
+ " where " + Sqlite.COL_USERNAME + " = '" + account.getUsername() + "' AND " + Sqlite.COL_INSTANCE + " = '" + account.getHost() + "'", null);
|
||||
mCount.moveToFirst();
|
||||
int count = mCount.getInt(0);
|
||||
mCount.close();
|
||||
@ -286,7 +292,7 @@ public class AccountDAO {
|
||||
//New user
|
||||
Account account = new Account();
|
||||
account.setId(c.getString(c.getColumnIndex(Sqlite.COL_USER_ID)));
|
||||
account.setName(c.getString(c.getColumnIndex(Sqlite.COL_USERNAME)));
|
||||
account.setUsername(c.getString(c.getColumnIndex(Sqlite.COL_USERNAME)));
|
||||
account.setDisplayName(c.getString(c.getColumnIndex(Sqlite.COL_DISPLAYED_NAME)));
|
||||
account.setFollowersCount(c.getInt(c.getColumnIndex(Sqlite.COL_FOLLOWERS_COUNT)));
|
||||
account.setFollowingCount(c.getInt(c.getColumnIndex(Sqlite.COL_FOLLOWING_COUNT)));
|
||||
@ -302,7 +308,6 @@ public class AccountDAO {
|
||||
account.setClient_id(c.getString(c.getColumnIndex(Sqlite.COL_CLIENT_ID)));
|
||||
account.setClient_secret(c.getString(c.getColumnIndex(Sqlite.COL_CLIENT_SECRET)));
|
||||
account.setRefresh_token(c.getString(c.getColumnIndex(Sqlite.COL_REFRESH_TOKEN)));
|
||||
account.setAcct(account.getName() + "@" + account.getHost());
|
||||
//Close the cursor
|
||||
c.close();
|
||||
|
||||
|
@ -23,11 +23,11 @@ import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
||||
|
||||
|
||||
|
||||
public class CaptionsVM extends AndroidViewModel {
|
||||
private MutableLiveData<APIResponse> apiResponseMutableLiveData;
|
||||
|
||||
|
@ -82,7 +82,7 @@ public class TimelineVM extends AndroidViewModel {
|
||||
try {
|
||||
RetrofitPeertubeAPI retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext);
|
||||
APIResponse apiResponse = retrofitPeertubeAPI.getVideos(videoId);
|
||||
if(Helper.isLoggedIn(_mContext)) {
|
||||
if (Helper.isLoggedIn(_mContext)) {
|
||||
if (apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0 && apiResponse.getPeertubes().get(0) != null) {
|
||||
APIResponse response = new RetrofitPeertubeAPI(_mContext).getRating(videoId);
|
||||
if (response != null)
|
||||
|
Loading…
x
Reference in New Issue
Block a user