diff --git a/app/src/fdroid/java/app/fedilab/android/activities/BasePeertubeActivity.java b/app/src/fdroid/java/app/fedilab/android/activities/BasePeertubeActivity.java
index 22995631..ff9f4549 100644
--- a/app/src/fdroid/java/app/fedilab/android/activities/BasePeertubeActivity.java
+++ b/app/src/fdroid/java/app/fedilab/android/activities/BasePeertubeActivity.java
@@ -130,7 +130,7 @@ public class BasePeertubeActivity extends BaseBarActivity {
} else {
b.putInt("displayed", 1);
- b.putParcelable("castedTube", peertube);
+ b.putSerializable("castedTube", peertube);
intentBC.putExtras(b);
LocalBroadcastManager.getInstance(BasePeertubeActivity.this).sendBroadcast(intentBC);
try {
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 3c314c57..be9a9a63 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -286,19 +286,6 @@
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/settings"
android:theme="@style/AppThemeBar" />
-
-
-
@@ -310,11 +297,6 @@
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/Transparent" />
-
-
-
-
-
+ */
+ public List getPeertubeAccounts() {
+
+ try {
+ Cursor c = db.query(Sqlite.TABLE_USER_ACCOUNT, null, Sqlite.COL_API + " = 'PEERTUBE' AND " + Sqlite.COL_TOKEN + " IS NOT NULL", null, null, null, Sqlite.COL_INSTANCE + " ASC", null);
+ return cursorToListUserWithOwner(c);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
/**
* Insert or update a user
*
@@ -144,6 +196,9 @@ public class Account extends BaseAccount implements Serializable {
if (account.mastodon_account != null) {
values.put(Sqlite.COL_ACCOUNT, mastodonAccountToStringStorage(account.mastodon_account));
}
+ if (account.peertube_account != null) {
+ values.put(Sqlite.COL_ACCOUNT, peertubeAccountToStringStorage(account.peertube_account));
+ }
values.put(Sqlite.COL_CREATED_AT, Helper.dateToString(new Date()));
values.put(Sqlite.COL_UPDATED_AT, Helper.dateToString(new Date()));
//Inserts token
@@ -181,6 +236,9 @@ public class Account extends BaseAccount implements Serializable {
if (account.mastodon_account != null) {
values.put(Sqlite.COL_ACCOUNT, mastodonAccountToStringStorage(account.mastodon_account));
}
+ if (account.peertube_account != null) {
+ values.put(Sqlite.COL_ACCOUNT, peertubeAccountToStringStorage(account.peertube_account));
+ }
values.put(Sqlite.COL_UPDATED_AT, Helper.dateToString(new Date()));
//Inserts token
try {
@@ -193,6 +251,33 @@ public class Account extends BaseAccount implements Serializable {
}
}
+ /**
+ * Update an account in db
+ *
+ * @param token {@link Token}
+ * @return long - db id
+ * @throws DBException exception with database
+ */
+ public long updatePeertubeToken(Token token) throws DBException {
+ 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_TOKEN, token.getAccess_token());
+ SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
+ String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
+ String instance = HelperInstance.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;
+ }
+
/**
* Check if a user exists in db
*
@@ -454,6 +539,7 @@ public class Account extends BaseAccount implements Serializable {
FRIENDICA,
PLEROMA,
PIXELFED,
+ PEERTUBE,
UNKNOWN
}
}
diff --git a/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/BaseAccount.java b/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/BaseAccount.java
index 0f30a2c2..8c67e611 100644
--- a/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/BaseAccount.java
+++ b/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/BaseAccount.java
@@ -19,6 +19,8 @@ import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
import java.util.Date;
+import app.fedilab.android.peertube.client.data.AccountData;
+
/**
* Class that manages Accounts from database
* Accounts details are serialized and can be for different softwares
@@ -51,6 +53,8 @@ public class BaseAccount implements Serializable {
public Date updated_at;
@SerializedName("mastodon_account")
public app.fedilab.android.mastodon.client.entities.api.Account mastodon_account;
+ @SerializedName("peertube_account")
+ public AccountData.PeertubeAccount peertube_account;
@SerializedName("admin")
public boolean admin;
diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/AccountActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/AccountActivity.java
index 03fda14e..aa782a1b 100644
--- a/app/src/main/java/app/fedilab/android/peertube/activities/AccountActivity.java
+++ b/app/src/main/java/app/fedilab/android/peertube/activities/AccountActivity.java
@@ -18,7 +18,6 @@ import static app.fedilab.android.peertube.activities.PeertubeMainActivity.badge
import android.content.Intent;
import android.content.SharedPreferences;
-import android.database.sqlite.SQLiteDatabase;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
@@ -46,15 +45,16 @@ import org.jetbrains.annotations.NotNull;
import app.fedilab.android.R;
import app.fedilab.android.databinding.ActivityAccountPeertubeBinding;
import app.fedilab.android.mastodon.activities.BaseBarActivity;
+import app.fedilab.android.mastodon.client.entities.app.Account;
+import app.fedilab.android.mastodon.client.entities.app.BaseAccount;
+import app.fedilab.android.mastodon.exception.DBException;
import app.fedilab.android.peertube.client.RetrofitPeertubeAPI;
-import app.fedilab.android.peertube.client.data.AccountData.Account;
+import app.fedilab.android.peertube.client.data.AccountData;
import app.fedilab.android.peertube.fragment.DisplayAccountsFragment;
import app.fedilab.android.peertube.fragment.DisplayChannelsFragment;
import app.fedilab.android.peertube.fragment.DisplayNotificationsFragment;
import app.fedilab.android.peertube.helper.Helper;
import app.fedilab.android.peertube.helper.SwitchAccountHelper;
-import app.fedilab.android.peertube.sqlite.AccountDAO;
-import app.fedilab.android.peertube.sqlite.Sqlite;
public class AccountActivity extends BaseBarActivity {
@@ -78,16 +78,21 @@ public class AccountActivity extends BaseBarActivity {
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
- SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
- Account account = new AccountDAO(AccountActivity.this, db).getAccountByToken(token);
- if (account == null) {
- Helper.logoutCurrentUser(AccountActivity.this, null);
+ BaseAccount baseAccount = null;
+ try {
+ baseAccount = new Account(AccountActivity.this).getAccountByToken(token);
+ } catch (DBException e) {
+ e.printStackTrace();
+ }
+ if (baseAccount == null) {
+ finish();
return;
}
+ AccountData.PeertubeAccount account = baseAccount.peertube_account;
setTitle(String.format("@%s", account.getUsername()));
@@ -97,11 +102,12 @@ public class AccountActivity extends BaseBarActivity {
binding.instance.setText(account.getHost());
+ BaseAccount finalBaseAccount = baseAccount;
binding.logoutButton.setOnClickListener(v -> {
AlertDialog.Builder dialogBuilderLogoutAccount = new AlertDialog.Builder(AccountActivity.this);
dialogBuilderLogoutAccount.setMessage(getString(R.string.logout_account_confirmation, account.getUsername(), account.getHost()));
dialogBuilderLogoutAccount.setPositiveButton(R.string.action_logout, (dialog, id) -> {
- Helper.logoutCurrentUser(AccountActivity.this, account);
+ Helper.logoutCurrentUser(AccountActivity.this, finalBaseAccount);
dialog.dismiss();
});
dialogBuilderLogoutAccount.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
@@ -215,9 +221,9 @@ public class AccountActivity extends BaseBarActivity {
binding.remoteAccount.setVisibility(View.VISIBLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
- binding.remoteAccount.setText(Html.fromHtml(getString(R.string.remote_account_from, account.getSoftware()), Html.FROM_HTML_MODE_LEGACY));
+ binding.remoteAccount.setText(Html.fromHtml(getString(R.string.remote_account_from, baseAccount.software), Html.FROM_HTML_MODE_LEGACY));
else
- binding.remoteAccount.setText(Html.fromHtml(getString(R.string.remote_account_from, account.getSoftware())));
+ binding.remoteAccount.setText(Html.fromHtml(getString(R.string.remote_account_from, baseAccount.software)));
}
}
diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/AllLocalPlaylistsActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/AllLocalPlaylistsActivity.java
index d06eaadb..0733a923 100644
--- a/app/src/main/java/app/fedilab/android/peertube/activities/AllLocalPlaylistsActivity.java
+++ b/app/src/main/java/app/fedilab/android/peertube/activities/AllLocalPlaylistsActivity.java
@@ -21,7 +21,6 @@ import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
-import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
@@ -35,7 +34,6 @@ import app.fedilab.android.mastodon.activities.BaseBarActivity;
import app.fedilab.android.peertube.client.data.PlaylistData.Playlist;
import app.fedilab.android.peertube.client.data.VideoPlaylistData;
import app.fedilab.android.peertube.drawer.PlaylistAdapter;
-import app.fedilab.android.peertube.viewmodel.PlaylistsVM;
public class AllLocalPlaylistsActivity extends BaseBarActivity implements PlaylistAdapter.AllPlaylistRemoved {
@@ -63,8 +61,6 @@ public class AllLocalPlaylistsActivity extends BaseBarActivity implements Playli
mainLoader.setVisibility(View.VISIBLE);
nextElementLoader.setVisibility(View.GONE);
- PlaylistsVM viewModel = new ViewModelProvider(AllLocalPlaylistsActivity.this).get(PlaylistsVM.class);
- viewModel.localePlaylist().observe(AllLocalPlaylistsActivity.this, this::manageVIewPlaylists);
FloatingActionButton add_new = findViewById(R.id.add_new);
add_new.setVisibility(View.GONE);
diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/LoginActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/LoginActivity.java
index 869017ba..dd890d3a 100644
--- a/app/src/main/java/app/fedilab/android/peertube/activities/LoginActivity.java
+++ b/app/src/main/java/app/fedilab/android/peertube/activities/LoginActivity.java
@@ -38,11 +38,10 @@ import app.fedilab.android.R;
import app.fedilab.android.databinding.ActivityLoginPeertubeBinding;
import app.fedilab.android.mastodon.activities.BaseBarActivity;
import app.fedilab.android.peertube.client.RetrofitPeertubeAPI;
+import app.fedilab.android.peertube.client.entities.Error;
import app.fedilab.android.peertube.client.entities.Oauth;
import app.fedilab.android.peertube.client.entities.OauthParams;
import app.fedilab.android.peertube.client.entities.Token;
-import app.fedilab.android.peertube.client.entities.WellKnownNodeinfo;
-import app.fedilab.android.peertube.client.mastodon.RetrofitMastodonAPI;
import app.fedilab.android.peertube.helper.Helper;
import es.dmoral.toasty.Toasty;
@@ -53,7 +52,7 @@ public class LoginActivity extends BaseBarActivity {
private static String client_id;
private static String client_secret;
private ActivityLoginPeertubeBinding binding;
-
+ private String instance;
@SuppressLint("SetTextI18n")
@Override
@@ -62,6 +61,13 @@ public class LoginActivity extends BaseBarActivity {
binding = ActivityLoginPeertubeBinding.inflate(getLayoutInflater());
View view = binding.getRoot();
setContentView(view);
+ Bundle b = getIntent().getExtras();
+ if (b != null) {
+ instance = b.getString(app.fedilab.android.mastodon.helper.Helper.ARG_INSTANCE, null);
+ }
+ if (instance == null) {
+ finish();
+ }
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
@@ -77,15 +83,13 @@ public class LoginActivity extends BaseBarActivity {
binding.createAnAccountPeertube.setOnClickListener(v -> {
Intent mainActivity = new Intent(LoginActivity.this, PeertubeRegisterActivity.class);
- Bundle b = new Bundle();
- mainActivity.putExtras(b);
startActivity(mainActivity);
});
binding.loginInstanceContainer.setVisibility(View.VISIBLE);
-
+ binding.loginInstance.setText(instance);
if (Helper.isTablet(LoginActivity.this)) {
ViewGroup.LayoutParams layoutParamsI = binding.loginInstanceContainer.getLayoutParams();
@@ -137,10 +141,7 @@ public class LoginActivity extends BaseBarActivity {
return;
}
String finalInstance = instance;
- new Thread(() -> {
- WellKnownNodeinfo.NodeInfo instanceNodeInfo = null;
- connectToFediverse(finalInstance, instanceNodeInfo);
- }).start();
+ new Thread(() -> connectToFediverse(finalInstance)).start();
});
}
@@ -149,28 +150,8 @@ public class LoginActivity extends BaseBarActivity {
*
* @param finalInstance String
*/
- private void connectToFediverse(String finalInstance, WellKnownNodeinfo.NodeInfo instanceNodeInfo) {
- Oauth oauth = null;
- String software;
- if (instanceNodeInfo != null) {
- software = instanceNodeInfo.getSoftware().getName().toUpperCase().trim();
- switch (software) {
- case "MASTODON":
- case "PLEROMA":
- oauth = new RetrofitMastodonAPI(LoginActivity.this, finalInstance, null).oauthClient(Helper.CLIENT_NAME_VALUE, Helper.REDIRECT_CONTENT_WEB, Helper.OAUTH_SCOPES_MASTODON, Helper.WEBSITE_VALUE);
- break;
-
- case "FRIENDICA":
-
- break;
-
- default:
- oauth = new RetrofitPeertubeAPI(LoginActivity.this, finalInstance, null).oauthClient(Helper.CLIENT_NAME_VALUE, Helper.WEBSITE_VALUE, Helper.OAUTH_SCOPES_PEERTUBE, Helper.WEBSITE_VALUE);
- }
- } else {
- oauth = new RetrofitPeertubeAPI(LoginActivity.this, finalInstance, null).oauthClient(Helper.CLIENT_NAME_VALUE, Helper.WEBSITE_VALUE, Helper.OAUTH_SCOPES_PEERTUBE, Helper.WEBSITE_VALUE);
- software = "PEERTUBE";
- }
+ private void connectToFediverse(String finalInstance) {
+ Oauth oauth = new RetrofitPeertubeAPI(LoginActivity.this, finalInstance, null).oauthClient(Helper.CLIENT_NAME_VALUE, Helper.WEBSITE_VALUE, Helper.OAUTH_SCOPES_PEERTUBE, Helper.WEBSITE_VALUE);
if (oauth == null) {
runOnUiThread(() -> {
binding.loginButton.setEnabled(true);
@@ -190,12 +171,7 @@ public class LoginActivity extends BaseBarActivity {
oauthParams.setClient_id(client_id);
oauthParams.setClient_secret(client_secret);
oauthParams.setGrant_type("password");
- final boolean isMastodonAPI = software.compareTo("MASTODON") == 0 || software.compareTo("PLEROMA") == 0;
- if (software.compareTo("PEERTUBE") == 0) {
- oauthParams.setScope("user");
- } else if (isMastodonAPI) {
- oauthParams.setScope("read write follow");
- }
+ oauthParams.setScope("user");
if (binding.loginUid.getText() != null) {
oauthParams.setUsername(binding.loginUid.getText().toString().trim());
}
@@ -203,45 +179,29 @@ public class LoginActivity extends BaseBarActivity {
oauthParams.setPassword(binding.loginPasswd.getText().toString());
}
try {
- Token token = null;
- if (software.compareTo("PEERTUBE") == 0) {
- token = new RetrofitPeertubeAPI(LoginActivity.this, finalInstance, null).manageToken(oauthParams);
- } else if (isMastodonAPI) {
- Intent i = new Intent(LoginActivity.this, MastodonWebviewConnectActivity.class);
- i.putExtra("software", software);
- i.putExtra("instance", finalInstance);
- i.putExtra("client_id", client_id);
- i.putExtra("client_secret", client_secret);
- startActivity(i);
- return;
- }
- proceedLogin(token, finalInstance, software.compareTo("PEERTUBE") == 0 ? null : software);
+ Token token = new RetrofitPeertubeAPI(LoginActivity.this, finalInstance, null).manageToken(oauthParams);
+ proceedLogin(token, finalInstance);
} catch (final Exception e) {
oauthParams.setUsername(binding.loginUid.getText().toString().toLowerCase().trim());
- if (software.compareTo("PEERTUBE") == 0) {
- Token token = new RetrofitPeertubeAPI(LoginActivity.this, finalInstance, null).manageToken(oauthParams);
- proceedLogin(token, finalInstance, software.compareTo("PEERTUBE") == 0 ? null : software);
+ Token token = null;
+ try {
+ token = new RetrofitPeertubeAPI(LoginActivity.this, finalInstance, null).manageToken(oauthParams);
+ } catch (Error ex) {
+ ex.printStackTrace();
}
+ proceedLogin(token, finalInstance);
+ } catch (Error e) {
+ e.printStackTrace();
}
}
@SuppressLint("ApplySharedPref")
- private void proceedLogin(Token token, String host, String software) {
+ private void proceedLogin(Token token, String host) {
runOnUiThread(() -> {
if (token != null) {
- boolean remote_account = software != null && software.toUpperCase().trim().compareTo("PEERTUBE") != 0;
- 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_SOFTWARE, remote_account ? software : null);
- editor.putString(Helper.PREF_REMOTE_INSTANCE, remote_account ? host : null);
- if (!remote_account) {
- editor.putString(Helper.PREF_INSTANCE, host);
- }
- editor.commit();
//Update the account with the token;
- updateCredential(LoginActivity.this, token.getAccess_token(), client_id, client_secret, token.getRefresh_token(), host, software);
+ updateCredential(LoginActivity.this, token.getAccess_token(), client_id, client_secret, token.getRefresh_token(), host, null);
} else {
binding.loginButton.setEnabled(true);
}
diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/ManageInstancesActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/ManageInstancesActivity.java
index ef1221cf..8a3bb93b 100644
--- a/app/src/main/java/app/fedilab/android/peertube/activities/ManageInstancesActivity.java
+++ b/app/src/main/java/app/fedilab/android/peertube/activities/ManageInstancesActivity.java
@@ -39,9 +39,9 @@ import app.fedilab.android.peertube.client.RetrofitPeertubeAPI;
import app.fedilab.android.peertube.client.data.InstanceData;
import app.fedilab.android.peertube.drawer.AboutInstanceAdapter;
import app.fedilab.android.peertube.helper.Helper;
-import app.fedilab.android.peertube.sqlite.Sqlite;
import app.fedilab.android.peertube.sqlite.StoredInstanceDAO;
import app.fedilab.android.peertube.viewmodel.InfoInstanceVM;
+import app.fedilab.android.sqlite.Sqlite;
public class ManageInstancesActivity extends BaseBarActivity implements AboutInstanceAdapter.AllInstancesRemoved {
diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/MastodonWebviewConnectActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/MastodonWebviewConnectActivity.java
deleted file mode 100644
index b3084567..00000000
--- a/app/src/main/java/app/fedilab/android/peertube/activities/MastodonWebviewConnectActivity.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/* 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 . */
-
-package app.fedilab.android.peertube.activities;
-
-
-import android.annotation.SuppressLint;
-import android.content.Context;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.net.Uri;
-import android.os.Build;
-import android.os.Bundle;
-import android.view.MenuItem;
-import android.webkit.CookieManager;
-import android.webkit.CookieSyncManager;
-import android.webkit.WebChromeClient;
-import android.webkit.WebView;
-import android.webkit.WebViewClient;
-import android.widget.ProgressBar;
-import android.widget.Toast;
-
-import androidx.appcompat.app.AlertDialog;
-
-import app.fedilab.android.R;
-import app.fedilab.android.mastodon.activities.BaseBarActivity;
-import app.fedilab.android.peertube.client.entities.OauthParams;
-import app.fedilab.android.peertube.client.entities.Token;
-import app.fedilab.android.peertube.client.mastodon.RetrofitMastodonAPI;
-import app.fedilab.android.peertube.helper.Helper;
-import es.dmoral.toasty.Toasty;
-
-
-public class MastodonWebviewConnectActivity extends BaseBarActivity {
-
-
- private WebView webView;
- private AlertDialog alert;
- private String clientId, clientSecret;
- private String instance, software;
-
- @SuppressWarnings("deprecation")
- public static void clearCookies(Context context) {
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
- CookieManager.getInstance().removeAllCookies(null);
- CookieManager.getInstance().flush();
- } else {
- CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context);
- cookieSyncMngr.startSync();
- CookieManager cookieManager = CookieManager.getInstance();
- cookieManager.removeAllCookie();
- cookieManager.removeSessionCookie();
- cookieSyncMngr.stopSync();
- cookieSyncMngr.sync();
- }
- }
-
- private static String redirectUserToAuthorizeAndLogin(String clientId, String instance) {
- String queryString = Helper.CLIENT_ID + "=" + clientId;
- queryString += "&" + Helper.REDIRECT_URI + "=" + Uri.encode(Helper.REDIRECT_CONTENT_WEB);
- queryString += "&response_type=code";
- queryString += "&scope=read write follow";
- return "https://" + instance + "/oauth/authorize?" + queryString;
- }
-
- @SuppressLint("SetJavaScriptEnabled")
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_webview_connect);
- Bundle b = getIntent().getExtras();
- if (b != null) {
- instance = b.getString("instance");
- clientId = b.getString("client_id");
- clientSecret = b.getString("client_secret");
- software = b.getString("software");
- }
- if (instance == null)
- finish();
- if (getSupportActionBar() != null)
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- setTitle(R.string.login);
- webView = findViewById(R.id.webviewConnect);
- clearCookies(MastodonWebviewConnectActivity.this);
- webView.getSettings().setJavaScriptEnabled(true);
-
- CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
-
- final ProgressBar pbar = findViewById(R.id.progress_bar);
- webView.setWebChromeClient(new WebChromeClient() {
- @Override
- public void onProgressChanged(WebView view, int progress) {
- if (progress < 100 && pbar.getVisibility() == ProgressBar.GONE) {
- pbar.setVisibility(ProgressBar.VISIBLE);
- }
- pbar.setProgress(progress);
- if (progress == 100) {
- pbar.setVisibility(ProgressBar.GONE);
- }
- }
- });
-
- if (instance == null) {
- finish();
- }
- webView.setWebViewClient(new WebViewClient() {
- @Override
- public boolean shouldOverrideUrlLoading(WebView view, String url) {
- super.shouldOverrideUrlLoading(view, url);
- if (url.contains(Helper.REDIRECT_CONTENT_WEB)) {
- String[] val = url.split("code=");
- if (val.length < 2) {
- Toasty.error(MastodonWebviewConnectActivity.this, getString(R.string.toast_code_error), Toast.LENGTH_LONG).show();
- Intent myIntent = new Intent(MastodonWebviewConnectActivity.this, LoginActivity.class);
- startActivity(myIntent);
- finish();
- return false;
- }
- String code = val[1];
- if (code.contains("&")) {
- code = code.split("&")[0];
- }
- OauthParams oauthParams = new OauthParams();
- oauthParams.setClient_id(clientId);
- oauthParams.setClient_secret(clientSecret);
- oauthParams.setGrant_type("authorization_code");
- oauthParams.setCode(code);
- oauthParams.setRedirect_uri(Helper.REDIRECT_CONTENT_WEB);
-
- new Thread(() -> {
- try {
- Token token = new RetrofitMastodonAPI(MastodonWebviewConnectActivity.this, instance, null).manageToken(oauthParams);
- SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
- SharedPreferences.Editor editor = sharedpreferences.edit();
- editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token.getAccess_token());
- editor.apply();
- new RetrofitMastodonAPI(MastodonWebviewConnectActivity.this, instance, token.getAccess_token()).updateCredential(MastodonWebviewConnectActivity.this, clientId, clientSecret, token.getRefresh_token(), software);
- } catch (Exception | Error ignored) {
- }
- }).start();
- return true;
- }
- return false;
- }
-
- });
- webView.loadUrl(redirectUserToAuthorizeAndLogin(clientId, instance));
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- int itemId = item.getItemId();
- if (itemId == android.R.id.home) {
- finish();
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
-
- @Override
- public void onBackPressed() {
- if (webView != null && webView.canGoBack()) {
- webView.goBack();
- } else {
- super.onBackPressed();
- }
- }
-
- @Override
- public void onDestroy() {
- super.onDestroy();
- if (alert != null) {
- alert.dismiss();
- alert = null;
- }
- if (webView != null) {
- webView.destroy();
- }
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/MyAccountActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/MyAccountActivity.java
index 8a8ed1ce..11ffd307 100644
--- a/app/src/main/java/app/fedilab/android/peertube/activities/MyAccountActivity.java
+++ b/app/src/main/java/app/fedilab/android/peertube/activities/MyAccountActivity.java
@@ -51,6 +51,7 @@ import app.fedilab.android.R;
import app.fedilab.android.databinding.ActivityMyAccountSettingsPeertubeBinding;
import app.fedilab.android.mastodon.activities.BaseBarActivity;
import app.fedilab.android.peertube.client.RetrofitPeertubeAPI;
+import app.fedilab.android.peertube.client.entities.Error;
import app.fedilab.android.peertube.client.entities.NotificationSettings;
import app.fedilab.android.peertube.client.entities.UserMe;
import app.fedilab.android.peertube.client.entities.UserSettings;
diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeActivity.java
index 2389c29c..640bdc5c 100644
--- a/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeActivity.java
+++ b/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeActivity.java
@@ -124,10 +124,10 @@ import java.util.regex.Pattern;
import app.fedilab.android.R;
import app.fedilab.android.activities.BasePeertubeActivity;
import app.fedilab.android.databinding.ActivityPeertubeBinding;
+import app.fedilab.android.mastodon.exception.DBException;
import app.fedilab.android.peertube.client.APIResponse;
import app.fedilab.android.peertube.client.MenuItemVideo;
import app.fedilab.android.peertube.client.RetrofitPeertubeAPI;
-import app.fedilab.android.peertube.client.data.AccountData.Account;
import app.fedilab.android.peertube.client.data.CaptionData.Caption;
import app.fedilab.android.peertube.client.data.CommentData;
import app.fedilab.android.peertube.client.data.CommentData.Comment;
@@ -147,8 +147,6 @@ import app.fedilab.android.peertube.drawer.MenuItemAdapter;
import app.fedilab.android.peertube.helper.CacheDataSourceFactory;
import app.fedilab.android.peertube.helper.Helper;
import app.fedilab.android.peertube.helper.HelperInstance;
-import app.fedilab.android.peertube.sqlite.AccountDAO;
-import app.fedilab.android.peertube.sqlite.Sqlite;
import app.fedilab.android.peertube.viewmodel.CaptionsVM;
import app.fedilab.android.peertube.viewmodel.CommentVM;
import app.fedilab.android.peertube.viewmodel.PlaylistsVM;
@@ -159,6 +157,7 @@ import app.fedilab.android.peertube.viewmodel.mastodon.MastodonPostActionsVM;
import app.fedilab.android.peertube.webview.CustomWebview;
import app.fedilab.android.peertube.webview.MastalabWebChromeClient;
import app.fedilab.android.peertube.webview.MastalabWebViewClient;
+import app.fedilab.android.sqlite.Sqlite;
import es.dmoral.toasty.Toasty;
@@ -224,7 +223,12 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
if (Helper.canMakeAction(PeertubeActivity.this) && !sepiaSearch) {
- Account account = new AccountDAO(PeertubeActivity.this, db).getAccountByToken(token);
+ Account account = null;
+ try {
+ account = new app.fedilab.android.mastodon.client.entities.app.Account(PeertubeActivity.this).getAccountByToken(token);
+ } catch (DBException e) {
+ e.printStackTrace();
+ }
loadAvatar(PeertubeActivity.this, account, binding.myPp);
}
isRemote = false;
@@ -973,7 +977,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
binding.ppChannel.setOnClickListener(v -> {
Intent intent = new Intent(PeertubeActivity.this, ShowChannelActivity.class);
Bundle b = new Bundle();
- b.putParcelable("channel", peertube.getChannel());
+ b.putSerializable("channel", peertube.getChannel());
b.putBoolean("sepia_search", sepiaSearch);
if (sepiaSearch) {
b.putString("peertube_instance", peertube.getAccount().getHost());
@@ -2201,7 +2205,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
if (nextVideo != null) {
Intent intent = new Intent(PeertubeActivity.this, PeertubeActivity.class);
Bundle b = new Bundle();
- b.putParcelable("video", nextVideo);
+ b.putSerializable("video", nextVideo);
b.putString("video_id", nextVideo.getId());
b.putString("video_uuid", nextVideo.getUuid());
playedVideos.add(nextVideo.getId());
diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeMainActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeMainActivity.java
index aa6ce867..5cbeb190 100644
--- a/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeMainActivity.java
+++ b/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeMainActivity.java
@@ -61,8 +61,10 @@ import app.fedilab.android.R;
import app.fedilab.android.activities.AboutActivity;
import app.fedilab.android.activities.PeertubeBaseMainActivity;
import app.fedilab.android.databinding.ActivityMainPeertubeBinding;
+import app.fedilab.android.mastodon.client.entities.app.Account;
+import app.fedilab.android.mastodon.client.entities.app.BaseAccount;
+import app.fedilab.android.mastodon.exception.DBException;
import app.fedilab.android.peertube.client.RetrofitPeertubeAPI;
-import app.fedilab.android.peertube.client.data.AccountData.Account;
import app.fedilab.android.peertube.client.data.InstanceData;
import app.fedilab.android.peertube.client.entities.AcadInstances;
import app.fedilab.android.peertube.client.entities.Error;
@@ -79,10 +81,9 @@ import app.fedilab.android.peertube.helper.HelperAcadInstance;
import app.fedilab.android.peertube.helper.HelperInstance;
import app.fedilab.android.peertube.helper.SwitchAccountHelper;
import app.fedilab.android.peertube.services.RetrieveInfoService;
-import app.fedilab.android.peertube.sqlite.AccountDAO;
-import app.fedilab.android.peertube.sqlite.Sqlite;
import app.fedilab.android.peertube.sqlite.StoredInstanceDAO;
import app.fedilab.android.peertube.viewmodel.TimelineVM;
+import app.fedilab.android.sqlite.Sqlite;
import es.dmoral.toasty.Toasty;
@@ -219,7 +220,6 @@ public abstract class PeertubeMainActivity extends PeertubeBaseMainActivity {
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayShowTitleEnabled(false);
}
- checkIfConnectedUsers();
recentFragment = new DisplayVideosFragment();
Bundle bundle = new Bundle();
@@ -354,18 +354,27 @@ public abstract class PeertubeMainActivity extends PeertubeBaseMainActivity {
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
String instanceShar = sharedpreferences.getString(Helper.PREF_INSTANCE, null);
String userIdShar = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
- Account account = new AccountDAO(PeertubeMainActivity.this, db).getAccountByToken(tokenStr);
+ BaseAccount account = null;
+ try {
+ account = new Account(PeertubeMainActivity.this).getAccountByToken(tokenStr);
+ } catch (DBException e) {
+ e.printStackTrace();
+ }
if (account == null) {
- account = new AccountDAO(PeertubeMainActivity.this, db).getAccountByIdInstance(userIdShar, instanceShar);
+ try {
+ account = new Account(PeertubeMainActivity.this).getUniqAccount(userIdShar, instanceShar);
+ } catch (DBException e) {
+ e.printStackTrace();
+ }
}
if (account != null) {
- Account finalAccount = account;
+ BaseAccount finalAccount = account;
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());
+ oauthParams.setClient_id(account.client_id);
+ oauthParams.setClient_secret(account.client_secret);
+ oauthParams.setRefresh_token(account.refresh_token);
+ oauthParams.setAccess_token(account.token);
try {
Token token = new RetrofitPeertubeAPI(PeertubeMainActivity.this).manageToken(oauthParams);
if (token == null) {
@@ -383,10 +392,15 @@ public abstract class PeertubeMainActivity extends PeertubeBaseMainActivity {
userMe = new RetrofitPeertubeAPI(PeertubeMainActivity.this, instance, token.getAccess_token()).verifyCredentials();
if (userMe != null && userMe.getAccount() != null) {
- new AccountDAO(PeertubeMainActivity.this, db).updateAccount(userMe.getAccount());
+ account.peertube_account = userMe.getAccount();
+ try {
+ new Account(PeertubeMainActivity.this).insertOrUpdate(account);
+ } catch (DBException e) {
+ e.printStackTrace();
+ }
SharedPreferences.Editor editor = sharedpreferences.edit();
- editor.putString(Helper.PREF_KEY_ID, account.getId());
- editor.putString(Helper.PREF_KEY_NAME, account.getUsername());
+ editor.putString(Helper.PREF_KEY_ID, account.user_id);
+ editor.putString(Helper.PREF_KEY_NAME, account.peertube_account.getUsername());
editor.putBoolean(getString(R.string.set_autoplay_choice), userMe.isAutoPlayVideo());
editor.putBoolean(getString(R.string.set_store_in_history), userMe.isVideosHistoryEnabled());
editor.putBoolean(getString(R.string.set_autoplay_next_video_choice), userMe.isAutoPlayNextVideo());
@@ -540,25 +554,6 @@ public abstract class PeertubeMainActivity extends PeertubeBaseMainActivity {
}
- private void checkIfConnectedUsers() {
- new Thread(() -> {
- try {
- typeOfConnection = TypeOfConnection.NORMAL;
- if (!Helper.canMakeAction(PeertubeMainActivity.this)) {
- SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
- List accounts = new AccountDAO(PeertubeMainActivity.this, db).getAllAccount();
- if (accounts != null && accounts.size() > 0) {
- //The user is not authenticated and there accounts in db. That means the user is surfing some other instances
- typeOfConnection = TypeOfConnection.SURFING;
- }
- }
- runOnUiThread(this::invalidateOptionsMenu);
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }).start();
- }
@Override
@@ -623,11 +618,7 @@ public abstract class PeertubeMainActivity extends PeertubeBaseMainActivity {
type = HelperAcadInstance.MOSTLIKED;
} else if (item.getItemId() == R.id.action_playlist) {
Intent intent;
- if (Helper.isLoggedIn(PeertubeMainActivity.this)) {
- intent = new Intent(PeertubeMainActivity.this, AllPlaylistsActivity.class);
- } else {
- intent = new Intent(PeertubeMainActivity.this, AllLocalPlaylistsActivity.class);
- }
+ intent = new Intent(PeertubeMainActivity.this, AllPlaylistsActivity.class);
startActivity(intent);
} else if (item.getItemId() == R.id.action_sepia_search) {
Intent intent = new Intent(PeertubeMainActivity.this, SepiaSearchActivity.class);
diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/PlaylistsActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/PlaylistsActivity.java
index a2320599..fcecdd16 100644
--- a/app/src/main/java/app/fedilab/android/peertube/activities/PlaylistsActivity.java
+++ b/app/src/main/java/app/fedilab/android/peertube/activities/PlaylistsActivity.java
@@ -14,7 +14,6 @@ package app.fedilab.android.peertube.activities;
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see . */
-import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.Toast;
@@ -26,14 +25,12 @@ import app.fedilab.android.mastodon.activities.BaseBarActivity;
import app.fedilab.android.peertube.client.data.PlaylistData;
import app.fedilab.android.peertube.fragment.DisplayVideosFragment;
import app.fedilab.android.peertube.helper.Helper;
-import app.fedilab.android.peertube.helper.PlaylistExportHelper;
import app.fedilab.android.peertube.viewmodel.TimelineVM;
import es.dmoral.toasty.Toasty;
public class PlaylistsActivity extends BaseBarActivity {
- private final int PICK_IMPORT = 5556;
@Override
@@ -70,22 +67,6 @@ public class PlaylistsActivity extends BaseBarActivity {
}
- @Override
- protected void onActivityResult(int requestCode, int resultCode,
- Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if (requestCode == PICK_IMPORT && resultCode == RESULT_OK) {
- if (data == null || data.getData() == null) {
- Toasty.error(PlaylistsActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
- return;
- }
- PlaylistExportHelper.manageIntentUrl(PlaylistsActivity.this, data);
-
- } else if (requestCode == PICK_IMPORT) {
- Toasty.error(PlaylistsActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
- }
- }
-
@Override
public boolean onOptionsItemSelected(MenuItem item) {
diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/SepiaSearchActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/SepiaSearchActivity.java
index 4d28125f..57e3d849 100644
--- a/app/src/main/java/app/fedilab/android/peertube/activities/SepiaSearchActivity.java
+++ b/app/src/main/java/app/fedilab/android/peertube/activities/SepiaSearchActivity.java
@@ -311,7 +311,7 @@ public class SepiaSearchActivity extends BaseBarActivity {
sepiaSearchVideo.setSearch(binding.searchBar.getText());
DisplaySepiaSearchFragment displaySepiaSearchFragment = new DisplaySepiaSearchFragment();
Bundle bundle = new Bundle();
- bundle.putParcelable("sepiaSearchVideo", sepiaSearchVideo);
+ bundle.putSerializable("sepiaSearchVideo", sepiaSearchVideo);
displaySepiaSearchFragment.setArguments(bundle);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(R.id.container, displaySepiaSearchFragment, "SEPIA_SEARCH").commit();
diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/ShowAccountActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/ShowAccountActivity.java
index fa3c702e..2d4fe747 100644
--- a/app/src/main/java/app/fedilab/android/peertube/activities/ShowAccountActivity.java
+++ b/app/src/main/java/app/fedilab/android/peertube/activities/ShowAccountActivity.java
@@ -68,7 +68,7 @@ public class ShowAccountActivity extends BaseBarActivity {
private TextView account_note, subscriber_count;
private ImageView account_pp;
private TextView account_dn;
- private AccountData.Account account;
+ private AccountData.PeertubeAccount account;
private String accountAcct;
@@ -246,7 +246,7 @@ public class ShowAccountActivity extends BaseBarActivity {
public void manageViewAccounts(APIResponse apiResponse) {
if (apiResponse.getAccounts() != null && apiResponse.getAccounts().size() == 1) {
- AccountData.Account account = apiResponse.getAccounts().get(0);
+ AccountData.PeertubeAccount account = apiResponse.getAccounts().get(0);
if (this.account == null) {
this.account = account;
manageAccount();
@@ -257,7 +257,7 @@ public class ShowAccountActivity extends BaseBarActivity {
}
}
- private void manageNotes(AccountData.Account account) {
+ private void manageNotes(AccountData.PeertubeAccount account) {
if (account.getDescription() != null && account.getDescription().compareTo("null") != 0 && account.getDescription().trim().length() > 0) {
SpannableString spannableString;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
@@ -295,7 +295,7 @@ public class ShowAccountActivity extends BaseBarActivity {
}
DisplayVideosFragment displayVideosFragment = new DisplayVideosFragment();
bundle.putSerializable(Helper.TIMELINE_TYPE, TimelineVM.TimelineType.ACCOUNT_VIDEOS);
- bundle.putParcelable("account", account);
+ bundle.putSerializable("account", account);
bundle.putString("peertube_instance", account.getHost());
displayVideosFragment.setArguments(bundle);
return displayVideosFragment;
diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/ShowChannelActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/ShowChannelActivity.java
index 1cf159f9..dc71bd01 100644
--- a/app/src/main/java/app/fedilab/android/peertube/activities/ShowChannelActivity.java
+++ b/app/src/main/java/app/fedilab/android/peertube/activities/ShowChannelActivity.java
@@ -26,7 +26,6 @@ import static app.fedilab.android.peertube.helper.Helper.isLoggedIn;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
-import android.database.sqlite.SQLiteDatabase;
import android.os.Build;
import android.os.Bundle;
import android.text.Html;
@@ -63,14 +62,10 @@ import app.fedilab.android.databinding.ActivityShowChannelBinding;
import app.fedilab.android.mastodon.activities.BaseBarActivity;
import app.fedilab.android.peertube.client.APIResponse;
import app.fedilab.android.peertube.client.RetrofitPeertubeAPI;
-import app.fedilab.android.peertube.client.data.AccountData;
import app.fedilab.android.peertube.client.data.ChannelData.Channel;
-import app.fedilab.android.peertube.drawer.OwnAccountsAdapter;
import app.fedilab.android.peertube.fragment.DisplayAccountsFragment;
import app.fedilab.android.peertube.fragment.DisplayVideosFragment;
import app.fedilab.android.peertube.helper.Helper;
-import app.fedilab.android.peertube.sqlite.AccountDAO;
-import app.fedilab.android.peertube.sqlite.Sqlite;
import app.fedilab.android.peertube.viewmodel.ChannelsVM;
import app.fedilab.android.peertube.viewmodel.PostActionsVM;
import app.fedilab.android.peertube.viewmodel.RelationshipVM;
@@ -116,43 +111,7 @@ public class ShowChannelActivity extends BaseBarActivity {
viewModel.get(sepiaSearch ? peertubeInstance : null, CHANNEL, channelAcct == null ? channel.getAcct() : channelAcct).observe(ShowChannelActivity.this, this::manageViewAccounts);
manageChannel();
- if (PeertubeMainActivity.typeOfConnection == SURFING) {
- binding.accountFollow.setText(getString(R.string.action_follow));
- binding.accountFollow.setEnabled(true);
- new Thread(() -> {
- try {
- SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
- List accounts = new AccountDAO(ShowChannelActivity.this, db).getAllAccount();
- runOnUiThread(() -> {
- binding.accountFollow.setVisibility(View.VISIBLE);
- binding.accountFollow.setOnClickListener(v -> {
- AlertDialog.Builder builderSingle = new AlertDialog.Builder(ShowChannelActivity.this);
- builderSingle.setTitle(getString(R.string.list_of_accounts));
- if (accounts != null && accounts.size() > 0) {
- if (accounts.size() > 1) {
- final OwnAccountsAdapter accountsListAdapter = new OwnAccountsAdapter(ShowChannelActivity.this, accounts);
- builderSingle.setAdapter(accountsListAdapter, (dialog, which) -> new Thread(() -> {
- try {
- RetrofitPeertubeAPI peertubeAPI = new RetrofitPeertubeAPI(ShowChannelActivity.this, accounts.get(which).getHost(), accounts.get(which).getToken());
- peertubeAPI.post(FOLLOW, channel.getAcct(), null);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }).start());
- } else {
- RetrofitPeertubeAPI peertubeAPI = new RetrofitPeertubeAPI(ShowChannelActivity.this, accounts.get(0).getHost(), accounts.get(0).getToken());
- peertubeAPI.post(FOLLOW, channel.getAcct(), null);
- }
- }
- builderSingle.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
- builderSingle.show();
- });
- });
- } catch (Exception e) {
- e.printStackTrace();
- }
- }).start();
- }
+
}
@Override
@@ -204,7 +163,7 @@ public class ShowChannelActivity extends BaseBarActivity {
} else if (item.getItemId() == R.id.action_display_account) {
Bundle b = new Bundle();
Intent intent = new Intent(ShowChannelActivity.this, ShowAccountActivity.class);
- b.putParcelable("account", channel.getOwnerAccount());
+ b.putSerializable("account", channel.getOwnerAccount());
b.putString("accountAcct", channel.getOwnerAccount().getAcct());
intent.putExtras(b);
startActivity(intent);
@@ -449,7 +408,7 @@ public class ShowChannelActivity extends BaseBarActivity {
DisplayVideosFragment displayVideosFragment = new DisplayVideosFragment();
Bundle bundle = new Bundle();
bundle.putSerializable(Helper.TIMELINE_TYPE, TimelineVM.TimelineType.CHANNEL_VIDEOS);
- bundle.putParcelable("channel", channel);
+ bundle.putSerializable("channel", channel);
bundle.putString("peertube_instance", channel.getHost());
bundle.putBoolean("sepia_search", sepiaSearch);
displayVideosFragment.setArguments(bundle);
diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/WebviewConnectActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/WebviewConnectActivity.java
deleted file mode 100644
index f0bb7379..00000000
--- a/app/src/main/java/app/fedilab/android/peertube/activities/WebviewConnectActivity.java
+++ /dev/null
@@ -1,254 +0,0 @@
-package app.fedilab.android.peertube.activities;
-/* 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 . */
-
-import static app.fedilab.android.peertube.client.RetrofitPeertubeAPI.updateCredential;
-
-import android.annotation.SuppressLint;
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.graphics.Bitmap;
-import android.os.Build;
-import android.os.Bundle;
-import android.view.MenuItem;
-import android.webkit.CookieManager;
-import android.webkit.CookieSyncManager;
-import android.webkit.WebChromeClient;
-import android.webkit.WebResourceRequest;
-import android.webkit.WebSettings;
-import android.webkit.WebView;
-import android.webkit.WebViewClient;
-import android.widget.ProgressBar;
-
-import androidx.appcompat.app.AlertDialog;
-
-import java.net.URL;
-import java.util.regex.Matcher;
-
-import app.fedilab.android.R;
-import app.fedilab.android.mastodon.activities.BaseBarActivity;
-import app.fedilab.android.peertube.client.RetrofitPeertubeAPI;
-import app.fedilab.android.peertube.client.entities.OauthParams;
-import app.fedilab.android.peertube.client.entities.Token;
-import app.fedilab.android.peertube.helper.Helper;
-
-
-public class WebviewConnectActivity extends BaseBarActivity {
-
-
- private WebView webView;
- private AlertDialog alert;
- private String clientId, clientSecret;
- private String url;
-
- @SuppressWarnings("deprecation")
- public static void clearCookies(Context context) {
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
- CookieManager.getInstance().removeAllCookies(null);
- CookieManager.getInstance().flush();
- } else {
- CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context);
- cookieSyncMngr.startSync();
- CookieManager cookieManager = CookieManager.getInstance();
- cookieManager.removeAllCookie();
- cookieManager.removeSessionCookie();
- cookieSyncMngr.stopSync();
- cookieSyncMngr.sync();
- }
- }
-
-
- @SuppressLint("SetJavaScriptEnabled")
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
- WebView.setWebContentsDebuggingEnabled(true);
- setContentView(R.layout.activity_webview_connect);
- Bundle b = getIntent().getExtras();
- if (b != null) {
- url = b.getString("url");
- }
- if (url == null)
- finish();
-
- clientId = sharedpreferences.getString(Helper.CLIENT_ID, null);
- clientSecret = sharedpreferences.getString(Helper.CLIENT_SECRET, null);
-
- webView = findViewById(R.id.webviewConnect);
- clearCookies(WebviewConnectActivity.this);
- webView.getSettings().setJavaScriptEnabled(true);
- CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
- webView.getSettings().setUseWideViewPort(true);
- webView.getSettings().setLoadWithOverviewMode(true);
- webView.getSettings().setSupportZoom(true);
- webView.getSettings().setDisplayZoomControls(false);
- webView.getSettings().setBuiltInZoomControls(true);
- webView.getSettings().setAllowContentAccess(true);
- webView.getSettings().setLoadsImagesAutomatically(true);
- webView.getSettings().setSupportMultipleWindows(false);
- webView.getSettings().setDatabaseEnabled(true);
- webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
- webView.getSettings().setMediaPlaybackRequiresUserGesture(true);
- if (getSupportActionBar() != null)
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- setTitle(R.string.login);
-
- final ProgressBar pbar = findViewById(R.id.progress_bar);
- webView.setWebChromeClient(new WebChromeClient() {
- @Override
- public void onProgressChanged(WebView view, int progress) {
- if (progress < 100 && pbar.getVisibility() == ProgressBar.GONE) {
- pbar.setVisibility(ProgressBar.VISIBLE);
- }
- pbar.setProgress(progress);
- if (progress == 100) {
- pbar.setVisibility(ProgressBar.GONE);
- }
- }
- });
-
- webView.setWebViewClient(new WebViewClient() {
-
- @Override
- public void onPageStarted(WebView view, String url, Bitmap favicon) {
- super.onPageStarted(view, url, favicon);
- //Avoid to load first page for academic instances & openid
- if (url.contains("/client")) {
- view.stopLoading();
- }
- }
-
- @Override
- public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
- if (request.getUrl() != null) {
- String url = request.getUrl().toString();
- Matcher matcher = Helper.redirectPattern.matcher(url);
- if (matcher.find()) {
- String externalAuthToken = matcher.group(1);
- String username = matcher.group(2);
- new Thread(() -> {
- try {
- OauthParams oauthParams = new OauthParams();
- oauthParams.setClient_id(sharedpreferences.getString(Helper.CLIENT_ID, null));
- oauthParams.setClient_secret(sharedpreferences.getString(Helper.CLIENT_SECRET, null));
- oauthParams.setGrant_type("password");
- oauthParams.setScope("upload");
- oauthParams.setResponse_type("code");
- oauthParams.setUsername(username);
- oauthParams.setExternalAuthToken(externalAuthToken);
- oauthParams.setPassword(externalAuthToken);
- String instance = new URL(url).getHost();
- Token token = null;
- token = new RetrofitPeertubeAPI(WebviewConnectActivity.this, instance, null).manageToken(oauthParams);
- if (token != null) {
- SharedPreferences.Editor editor = sharedpreferences.edit();
- editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token.getAccess_token());
- editor.putString(Helper.PREF_SOFTWARE, null);
- editor.putString(Helper.PREF_REMOTE_INSTANCE, null);
- editor.putString(Helper.PREF_INSTANCE, instance);
- editor.apply();
- updateCredential(WebviewConnectActivity.this, token.getAccess_token(), clientId, clientSecret, token.getRefresh_token(), new URL(url).getHost(), null);
- finish();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }).start();
- return true;
- }
- }
- return super.shouldOverrideUrlLoading(view, request);
- }
-
- /* @Override
- public void onPageFinished(WebView view, String url) {
- Matcher matcher = Helper.redirectPattern.matcher(url);
- if (matcher.find()) {
- String externalAuthToken = matcher.group(1);
- String username = matcher.group(2);
- new Thread(() -> {
- try {
- OauthParams oauthParams = new OauthParams();
- oauthParams.setClient_id(sharedpreferences.getString(Helper.CLIENT_ID, null));
- oauthParams.setClient_secret(sharedpreferences.getString(Helper.CLIENT_SECRET, null));
- oauthParams.setGrant_type("password");
- oauthParams.setScope("upload");
- oauthParams.setResponse_type("code");
- oauthParams.setUsername(username);
- oauthParams.setExternalAuthToken(externalAuthToken);
- oauthParams.setPassword(externalAuthToken);
- String instance = new URL(url).getHost();
- Token token = null;
- try {
- token = new RetrofitPeertubeAPI(WebviewConnectActivity.this, instance, null).manageToken(oauthParams);
- } catch (Error error) {
- error.printStackTrace();
- 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_SOFTWARE, null);
- editor.putString(Helper.PREF_REMOTE_INSTANCE, null);
- editor.putString(Helper.PREF_INSTANCE, instance);
- editor.apply();
- updateCredential(WebviewConnectActivity.this, token.getAccess_token(), clientId, clientSecret, token.getRefresh_token(), new URL(url).getHost(), null);
- finish();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }).start();
- }
- super.onPageFinished(view, url);
- }*/
- });
- webView.loadUrl(url);
-
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- int itemId = item.getItemId();
- if (itemId == android.R.id.home) {
- finish();
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
-
-
- @Override
- public void onBackPressed() {
- if (webView != null && webView.canGoBack()) {
- webView.goBack();
- } else {
- super.onBackPressed();
- }
- }
-
- @Override
- public void onDestroy() {
- super.onDestroy();
- if (alert != null) {
- alert.dismiss();
- alert = null;
- }
- if (webView != null) {
- webView.destroy();
- }
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/app/fedilab/android/peertube/client/APIResponse.java b/app/src/main/java/app/fedilab/android/peertube/client/APIResponse.java
index 6a533df2..0884dfe9 100644
--- a/app/src/main/java/app/fedilab/android/peertube/client/APIResponse.java
+++ b/app/src/main/java/app/fedilab/android/peertube/client/APIResponse.java
@@ -35,7 +35,7 @@ import app.fedilab.android.peertube.client.entities.Rating;
@SuppressWarnings({"unused", "RedundantSuppression"})
public class APIResponse {
- private List accounts = null;
+ private List accounts = null;
private List channels = null;
private String targetedId = null;
private String actionReturn = null;
@@ -59,11 +59,11 @@ public class APIResponse {
private int statusCode;
private String captionText;
- public List getAccounts() {
+ public List getAccounts() {
return accounts;
}
- public void setAccounts(List accounts) {
+ public void setAccounts(List accounts) {
this.accounts = accounts;
}
diff --git a/app/src/main/java/app/fedilab/android/peertube/client/PeertubeService.java b/app/src/main/java/app/fedilab/android/peertube/client/PeertubeService.java
index b71c0146..5128d605 100644
--- a/app/src/main/java/app/fedilab/android/peertube/client/PeertubeService.java
+++ b/app/src/main/java/app/fedilab/android/peertube/client/PeertubeService.java
@@ -394,7 +394,7 @@ public interface PeertubeService {
//Get a single account
@GET("accounts/{accountHandle}")
- Call getAccount(@Path("accountHandle") String accountHandle);
+ Call getAccount(@Path("accountHandle") String accountHandle);
//Get/Post/Update/Delete playlist
@GET("accounts/{accountHandle}/video-playlists")
diff --git a/app/src/main/java/app/fedilab/android/peertube/client/RetrofitPeertubeAPI.java b/app/src/main/java/app/fedilab/android/peertube/client/RetrofitPeertubeAPI.java
index 98a9ed5b..60a5ae50 100644
--- a/app/src/main/java/app/fedilab/android/peertube/client/RetrofitPeertubeAPI.java
+++ b/app/src/main/java/app/fedilab/android/peertube/client/RetrofitPeertubeAPI.java
@@ -47,6 +47,8 @@ import java.util.Set;
import java.util.concurrent.TimeUnit;
import app.fedilab.android.R;
+import app.fedilab.android.mastodon.client.entities.app.Account;
+import app.fedilab.android.mastodon.exception.DBException;
import app.fedilab.android.peertube.activities.PeertubeMainActivity;
import app.fedilab.android.peertube.client.data.AccountData;
import app.fedilab.android.peertube.client.data.BlockData;
@@ -78,12 +80,11 @@ import app.fedilab.android.peertube.client.entities.VideoParams;
import app.fedilab.android.peertube.client.entities.WellKnownNodeinfo;
import app.fedilab.android.peertube.helper.Helper;
import app.fedilab.android.peertube.helper.HelperInstance;
-import app.fedilab.android.peertube.sqlite.AccountDAO;
-import app.fedilab.android.peertube.sqlite.Sqlite;
import app.fedilab.android.peertube.viewmodel.ChannelsVM;
import app.fedilab.android.peertube.viewmodel.CommentVM;
import app.fedilab.android.peertube.viewmodel.PlaylistsVM;
import app.fedilab.android.peertube.viewmodel.TimelineVM;
+import app.fedilab.android.sqlite.Sqlite;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
@@ -146,11 +147,12 @@ public class RetrofitPeertubeAPI {
public static void updateCredential(Activity activity, String token, String client_id, String client_secret, String refresh_token, String host, String software) {
new Thread(() -> {
- AccountData.Account account;
+ AccountData.PeertubeAccount peertubeAccount;
+ Account account = new Account();
String instance = host;
try {
UserMe userMe = new RetrofitPeertubeAPI(activity, instance, token).verifyCredentials();
- account = userMe.getAccount();
+ peertubeAccount = userMe.getAccount();
} catch (Error error) {
Error.displayError(activity, error);
error.printStackTrace();
@@ -162,27 +164,25 @@ public class RetrofitPeertubeAPI {
} 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);
+ account.token = token;
+ account.client_id = client_id;
+ account.client_secret = client_secret;
+ account.refresh_token = refresh_token;
+ account.instance = instance;
+ account.peertube_account = peertubeAccount;
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());
- editor.putString(Helper.PREF_KEY_NAME, account.getUsername());
- boolean remote_account = software != null && software.toUpperCase().trim().compareTo("PEERTUBE") != 0;
- if (!remote_account) {
+ boolean userExists = false;
+ try {
+ SharedPreferences.Editor editor = sharedpreferences.edit();
+ editor.putString(Helper.PREF_KEY_ID, account.user_id);
+ editor.putString(Helper.PREF_KEY_NAME, peertubeAccount.getUsername());
editor.putString(Helper.PREF_INSTANCE, host);
+ editor.apply();
+ new Account(activity).insertOrUpdate(account);
+ } catch (DBException e) {
+ e.printStackTrace();
}
- editor.apply();
- if (userExists)
- new AccountDAO(activity, db).updateAccountCredential(account);
- else {
- if (account.getUsername() != null && account.getCreatedAt() != null)
- new AccountDAO(activity, db).insertAccount(account, software);
- }
+
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
Intent mainActivity = new Intent(activity, PeertubeMainActivity.class);
@@ -255,7 +255,7 @@ public class RetrofitPeertubeAPI {
editor.putString(Helper.PREF_REMOTE_INSTANCE, null);
editor.apply();
SQLiteDatabase db = Sqlite.getInstance(_context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
- new AccountDAO(_context, db).updateAccountToken(tokenReply);
+ new Account(_context).updatePeertubeToken(tokenReply);
}
return tokenReply;
} else {
@@ -268,7 +268,7 @@ public class RetrofitPeertubeAPI {
}
throw error;
}
- } catch (IOException e) {
+ } catch (IOException | DBException e) {
e.printStackTrace();
}
}
@@ -1356,13 +1356,13 @@ public class RetrofitPeertubeAPI {
*/
public APIResponse getAccount(String accountHandle) {
PeertubeService peertubeService = init();
- Call accountDataCall = peertubeService.getAccount(accountHandle);
+ Call accountDataCall = peertubeService.getAccount(accountHandle);
APIResponse apiResponse = new APIResponse();
if (accountDataCall != null) {
try {
- Response response = accountDataCall.execute();
+ Response response = accountDataCall.execute();
if (response.isSuccessful() && response.body() != null) {
- List accountList = new ArrayList<>();
+ List accountList = new ArrayList<>();
accountList.add(response.body());
apiResponse.setAccounts(accountList);
} else {
diff --git a/app/src/main/java/app/fedilab/android/peertube/client/data/AccountData.java b/app/src/main/java/app/fedilab/android/peertube/client/data/AccountData.java
index 914ad967..72b9462f 100644
--- a/app/src/main/java/app/fedilab/android/peertube/client/data/AccountData.java
+++ b/app/src/main/java/app/fedilab/android/peertube/client/data/AccountData.java
@@ -14,11 +14,10 @@ package app.fedilab.android.peertube.client.data;
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see . */
-import android.os.Parcel;
-import android.os.Parcelable;
import com.google.gson.annotations.SerializedName;
+import java.io.Serializable;
import java.util.Date;
import java.util.List;
@@ -26,25 +25,14 @@ import app.fedilab.android.peertube.client.entities.Avatar;
@SuppressWarnings({"unused", "RedundantSuppression"})
-public class AccountData {
+public class AccountData implements Serializable {
@SerializedName("total")
public int total;
@SerializedName("data")
- public List data;
+ public List data;
- public static class Account implements Parcelable {
- public static final Creator CREATOR = new Creator() {
- @Override
- public Account createFromParcel(Parcel source) {
- return new Account(source);
- }
-
- @Override
- public Account[] newArray(int size) {
- return new Account[size];
- }
- };
+ public static class PeertubeAccount implements Serializable {
@SerializedName("avatar")
private Avatar avatar;
@SerializedName("createdAt")
@@ -73,33 +61,11 @@ public class AccountData {
private String url;
@SerializedName("userId")
private String userId;
- private String token;
- private String client_id;
- private String client_secret;
- private String refresh_token;
- private String software;
- public Account() {
+
+ public PeertubeAccount() {
}
- protected Account(Parcel in) {
- this.avatar = in.readParcelable(Avatar.class.getClassLoader());
- long tmpCreatedAt = in.readLong();
- this.createdAt = tmpCreatedAt == -1 ? null : new Date(tmpCreatedAt);
- this.description = in.readString();
- this.displayName = in.readString();
- this.followersCount = in.readInt();
- this.followingCount = in.readInt();
- 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() {
return avatar;
@@ -201,37 +167,6 @@ public class AccountData {
return name + "@" + host;
}
- public String getToken() {
- return token;
- }
-
- public void setToken(String token) {
- this.token = token;
- }
-
- public String getClient_id() {
- return client_id;
- }
-
- public void setClient_id(String client_id) {
- this.client_id = client_id;
- }
-
- public String getClient_secret() {
- return client_secret;
- }
-
- public void setClient_secret(String client_secret) {
- this.client_secret = client_secret;
- }
-
- public String getRefresh_token() {
- return refresh_token;
- }
-
- public void setRefresh_token(String refresh_token) {
- this.refresh_token = refresh_token;
- }
public String getUserId() {
return userId;
@@ -241,35 +176,5 @@ public class AccountData {
this.userId = userId;
}
- public String getSoftware() {
- return software;
- }
-
- public void setSoftware(String software) {
- this.software = software;
- }
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeParcelable(this.avatar, flags);
- dest.writeLong(this.createdAt != null ? this.createdAt.getTime() : -1);
- dest.writeString(this.description);
- dest.writeString(this.displayName);
- dest.writeInt(this.followersCount);
- dest.writeInt(this.followingCount);
- 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);
- }
}
}
diff --git a/app/src/main/java/app/fedilab/android/peertube/client/data/BlockData.java b/app/src/main/java/app/fedilab/android/peertube/client/data/BlockData.java
index 44ce3826..872f9963 100644
--- a/app/src/main/java/app/fedilab/android/peertube/client/data/BlockData.java
+++ b/app/src/main/java/app/fedilab/android/peertube/client/data/BlockData.java
@@ -46,25 +46,25 @@ public class BlockData {
@SuppressWarnings("unused")
public static class Block {
@SerializedName("blockedAccount")
- private AccountData.Account blockedAccount;
+ private AccountData.PeertubeAccount blockedAccount;
@SerializedName("byAccount")
- private AccountData.Account byAccount;
+ private AccountData.PeertubeAccount byAccount;
@SerializedName("createdAt")
private Date createdAt;
- public AccountData.Account getBlockedAccount() {
+ public AccountData.PeertubeAccount getBlockedAccount() {
return blockedAccount;
}
- public void setBlockedAccount(AccountData.Account blockedAccount) {
+ public void setBlockedAccount(AccountData.PeertubeAccount blockedAccount) {
this.blockedAccount = blockedAccount;
}
- public AccountData.Account getByAccount() {
+ public AccountData.PeertubeAccount getByAccount() {
return byAccount;
}
- public void setByAccount(AccountData.Account byAccount) {
+ public void setByAccount(AccountData.PeertubeAccount byAccount) {
this.byAccount = byAccount;
}
diff --git a/app/src/main/java/app/fedilab/android/peertube/client/data/ChannelData.java b/app/src/main/java/app/fedilab/android/peertube/client/data/ChannelData.java
index fa39829d..d1b612ed 100644
--- a/app/src/main/java/app/fedilab/android/peertube/client/data/ChannelData.java
+++ b/app/src/main/java/app/fedilab/android/peertube/client/data/ChannelData.java
@@ -14,12 +14,10 @@ package app.fedilab.android.peertube.client.data;
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see . */
-import android.os.Parcel;
-import android.os.Parcelable;
import com.google.gson.annotations.SerializedName;
-import java.util.ArrayList;
+import java.io.Serializable;
import java.util.Date;
import java.util.List;
@@ -35,18 +33,8 @@ public class ChannelData {
@SerializedName("data")
public List data;
- public static class Channel implements Parcelable {
- public static final Creator CREATOR = new Creator() {
- @Override
- public Channel createFromParcel(Parcel source) {
- return new Channel(source);
- }
+ public static class Channel implements Serializable {
- @Override
- public Channel[] newArray(int size) {
- return new Channel[size];
- }
- };
@SerializedName("avatar")
private Avatar avatar;
@SerializedName("createdAt")
@@ -70,7 +58,7 @@ public class ChannelData {
@SerializedName("name")
private String name;
@SerializedName("ownerAccount")
- private AccountData.Account ownerAccount;
+ private AccountData.PeertubeAccount ownerAccount;
@SerializedName("support")
private String support;
@SerializedName("updatedAt")
@@ -85,28 +73,6 @@ public class ChannelData {
public Channel() {
}
- protected Channel(Parcel in) {
- this.avatar = in.readParcelable(Avatar.class.getClassLoader());
- long tmpCreatedAt = in.readLong();
- this.createdAt = tmpCreatedAt == -1 ? null : new Date(tmpCreatedAt);
- this.description = in.readString();
- this.displayName = in.readString();
- this.followersCount = in.readInt();
- this.followingCount = in.readInt();
- this.host = in.readString();
- this.hostRedundancyAllowed = in.readByte() != 0;
- this.id = in.readString();
- this.isLocal = in.readByte() != 0;
- this.name = in.readString();
- this.ownerAccount = in.readParcelable(AccountData.Account.class.getClassLoader());
- this.support = in.readString();
- long tmpUpdatedAt = in.readLong();
- this.updatedAt = tmpUpdatedAt == -1 ? null : new Date(tmpUpdatedAt);
- this.url = in.readString();
- this.viewsPerDays = new ArrayList<>();
- in.readList(this.viewsPerDays, ViewsPerDay.class.getClassLoader());
- this.acct = in.readString();
- }
public Avatar getAvatar() {
return avatar;
@@ -204,11 +170,11 @@ public class ChannelData {
this.name = name;
}
- public AccountData.Account getOwnerAccount() {
+ public AccountData.PeertubeAccount getOwnerAccount() {
return ownerAccount;
}
- public void setOwnerAccount(AccountData.Account ownerAccount) {
+ public void setOwnerAccount(AccountData.PeertubeAccount ownerAccount) {
this.ownerAccount = ownerAccount;
}
@@ -251,32 +217,6 @@ public class ChannelData {
public void setSelected(boolean selected) {
this.selected = selected;
}
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeParcelable(this.avatar, flags);
- dest.writeLong(this.createdAt != null ? this.createdAt.getTime() : -1);
- dest.writeString(this.description);
- dest.writeString(this.displayName);
- dest.writeInt(this.followersCount);
- dest.writeInt(this.followingCount);
- dest.writeString(this.host);
- dest.writeByte(this.hostRedundancyAllowed ? (byte) 1 : (byte) 0);
- dest.writeString(this.id);
- dest.writeByte(this.isLocal ? (byte) 1 : (byte) 0);
- dest.writeString(this.name);
- dest.writeParcelable(this.ownerAccount, flags);
- dest.writeString(this.support);
- dest.writeLong(this.updatedAt != null ? this.updatedAt.getTime() : -1);
- dest.writeString(this.url);
- dest.writeList(this.viewsPerDays);
- dest.writeString(this.acct);
- }
}
public static class ChannelCreation {
diff --git a/app/src/main/java/app/fedilab/android/peertube/client/data/CommentData.java b/app/src/main/java/app/fedilab/android/peertube/client/data/CommentData.java
index 3aabf3ca..1c1b156d 100644
--- a/app/src/main/java/app/fedilab/android/peertube/client/data/CommentData.java
+++ b/app/src/main/java/app/fedilab/android/peertube/client/data/CommentData.java
@@ -16,6 +16,7 @@ package app.fedilab.android.peertube.client.data;
import com.google.gson.annotations.SerializedName;
+import java.io.Serializable;
import java.util.Date;
import java.util.List;
@@ -28,10 +29,10 @@ public class CommentData {
public List data;
- public static class Comment {
+ public static class Comment implements Serializable {
@SerializedName("account")
- private AccountData.Account account;
+ private AccountData.PeertubeAccount account;
@SerializedName("createdAt")
private Date createdAt;
@SerializedName("deletedAt")
@@ -60,11 +61,11 @@ public class CommentData {
private boolean isReplyViewOpen = false;
- public AccountData.Account getAccount() {
+ public AccountData.PeertubeAccount getAccount() {
return account;
}
- public void setAccount(AccountData.Account account) {
+ public void setAccount(AccountData.PeertubeAccount account) {
this.account = account;
}
@@ -228,7 +229,7 @@ public class CommentData {
@SerializedName("video")
private VideoData.Video video;
@SerializedName("account")
- private AccountData.Account account;
+ private AccountData.PeertubeAccount account;
public String getId() {
return id;
@@ -254,11 +255,11 @@ public class CommentData {
this.video = video;
}
- public AccountData.Account getAccount() {
+ public AccountData.PeertubeAccount getAccount() {
return account;
}
- public void setAccount(AccountData.Account account) {
+ public void setAccount(AccountData.PeertubeAccount account) {
this.account = account;
}
}
diff --git a/app/src/main/java/app/fedilab/android/peertube/client/data/InstanceData.java b/app/src/main/java/app/fedilab/android/peertube/client/data/InstanceData.java
index 98e10a9a..fa4a1f20 100644
--- a/app/src/main/java/app/fedilab/android/peertube/client/data/InstanceData.java
+++ b/app/src/main/java/app/fedilab/android/peertube/client/data/InstanceData.java
@@ -14,8 +14,7 @@ package app.fedilab.android.peertube.client.data;
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see . */
-import android.os.Parcel;
-import android.os.Parcelable;
+
import android.text.SpannableStringBuilder;
import com.google.gson.annotations.SerializedName;
@@ -25,7 +24,7 @@ import java.util.Date;
import java.util.List;
@SuppressWarnings({"unused", "RedundantSuppression"})
-public class InstanceData {
+public class InstanceData implements Serializable {
@SerializedName("total")
public int total;
@@ -33,7 +32,7 @@ public class InstanceData {
public List data;
- public static class Instance {
+ public static class Instance implements Serializable {
@SerializedName("autoBlacklistUserVideosEnabled")
private boolean autoBlacklistUserVideosEnabled;
@@ -278,19 +277,8 @@ public class InstanceData {
}
}
- public static class AboutInstance implements Parcelable, Serializable {
+ public static class AboutInstance implements Serializable {
- public static final Creator CREATOR = new Creator() {
- @Override
- public AboutInstance createFromParcel(Parcel in) {
- return new AboutInstance(in);
- }
-
- @Override
- public AboutInstance[] newArray(int size) {
- return new AboutInstance[size];
- }
- };
@SerializedName("name")
private String name;
@SerializedName("shortDescription")
@@ -305,13 +293,6 @@ public class InstanceData {
public AboutInstance() {
}
- protected AboutInstance(Parcel in) {
- name = in.readString();
- shortDescription = in.readString();
- description = in.readString();
- terms = in.readString();
- host = in.readString();
- }
public String getName() {
return name;
@@ -361,23 +342,11 @@ public class InstanceData {
this.truncatedDescription = truncatedDescription;
}
- @Override
- public int describeContents() {
- return 0;
- }
- @Override
- public void writeToParcel(Parcel parcel, int i) {
- parcel.writeString(name);
- parcel.writeString(shortDescription);
- parcel.writeString(description);
- parcel.writeString(terms);
- parcel.writeString(host);
- }
}
- public static class InstanceConfig {
+ public static class InstanceConfig implements Serializable {
@SerializedName("user")
private User user;
@SerializedName("plugin")
@@ -401,7 +370,7 @@ public class InstanceData {
}
- public static class User {
+ public static class User implements Serializable {
@SerializedName("videoQuota")
private long videoQuota;
@SerializedName("videoQuotaDaily")
diff --git a/app/src/main/java/app/fedilab/android/peertube/client/data/NotificationData.java b/app/src/main/java/app/fedilab/android/peertube/client/data/NotificationData.java
index 7517008b..d6dd3008 100644
--- a/app/src/main/java/app/fedilab/android/peertube/client/data/NotificationData.java
+++ b/app/src/main/java/app/fedilab/android/peertube/client/data/NotificationData.java
@@ -51,7 +51,7 @@ public class NotificationData {
@SerializedName("videoBlacklist")
private VideoBlacklist videoBlacklist;
@SerializedName("account")
- private AccountData.Account account;
+ private AccountData.PeertubeAccount account;
@SerializedName("actorFollow")
private ActorFollow actorFollow;
@SerializedName("createdAt")
@@ -124,11 +124,11 @@ public class NotificationData {
this.videoBlacklist = videoBlacklist;
}
- public AccountData.Account getAccount() {
+ public AccountData.PeertubeAccount getAccount() {
return account;
}
- public void setAccount(AccountData.Account account) {
+ public void setAccount(AccountData.PeertubeAccount account) {
this.account = account;
}
diff --git a/app/src/main/java/app/fedilab/android/peertube/client/data/PlaylistData.java b/app/src/main/java/app/fedilab/android/peertube/client/data/PlaylistData.java
index cb4d3828..7d56671a 100644
--- a/app/src/main/java/app/fedilab/android/peertube/client/data/PlaylistData.java
+++ b/app/src/main/java/app/fedilab/android/peertube/client/data/PlaylistData.java
@@ -14,11 +14,10 @@ package app.fedilab.android.peertube.client.data;
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see . */
-import android.os.Parcel;
-import android.os.Parcelable;
import com.google.gson.annotations.SerializedName;
+import java.io.Serializable;
import java.util.Date;
import java.util.List;
@@ -32,18 +31,8 @@ public class PlaylistData {
@SerializedName("data")
public List data;
- public static class Playlist implements Parcelable {
- public static final Creator CREATOR = new Creator() {
- @Override
- public Playlist createFromParcel(Parcel source) {
- return new Playlist(source);
- }
+ public static class Playlist implements Serializable {
- @Override
- public Playlist[] newArray(int size) {
- return new Playlist[size];
- }
- };
@SerializedName("id")
private String id;
@SerializedName("createdAt")
@@ -67,31 +56,13 @@ public class PlaylistData {
@SerializedName("type")
private Item type;
@SerializedName("ownerAccount")
- private AccountData.Account ownerAccount;
+ private AccountData.PeertubeAccount ownerAccount;
@SerializedName("videoChannel")
private ChannelData.Channel videoChannel;
public Playlist() {
}
- protected Playlist(Parcel in) {
- this.id = in.readString();
- long tmpCreatedAt = in.readLong();
- this.createdAt = tmpCreatedAt == -1 ? null : new Date(tmpCreatedAt);
- long tmpUpdatedAt = in.readLong();
- this.updatedAt = tmpUpdatedAt == -1 ? null : new Date(tmpUpdatedAt);
- this.description = in.readString();
- this.uuid = in.readString();
- this.displayName = in.readString();
- this.isLocal = in.readByte() != 0;
- this.videoLength = in.readLong();
- this.thumbnailPath = in.readString();
- this.privacy = in.readParcelable(Item.class.getClassLoader());
- this.type = in.readParcelable(Item.class.getClassLoader());
- this.ownerAccount = in.readParcelable(AccountData.Account.class.getClassLoader());
- this.videoChannel = in.readParcelable(ChannelData.Channel.class.getClassLoader());
- }
-
public String getId() {
return id;
}
@@ -180,11 +151,11 @@ public class PlaylistData {
this.type = type;
}
- public AccountData.Account getOwnerAccount() {
+ public AccountData.PeertubeAccount getOwnerAccount() {
return ownerAccount;
}
- public void setOwnerAccount(AccountData.Account ownerAccount) {
+ public void setOwnerAccount(AccountData.PeertubeAccount ownerAccount) {
this.ownerAccount = ownerAccount;
}
@@ -196,27 +167,6 @@ public class PlaylistData {
this.videoChannel = videoChannel;
}
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeString(this.id);
- dest.writeLong(this.createdAt != null ? this.createdAt.getTime() : -1);
- dest.writeLong(this.updatedAt != null ? this.updatedAt.getTime() : -1);
- dest.writeString(this.description);
- dest.writeString(this.uuid);
- dest.writeString(this.displayName);
- dest.writeByte(this.isLocal ? (byte) 1 : (byte) 0);
- dest.writeLong(this.videoLength);
- dest.writeString(this.thumbnailPath);
- dest.writeParcelable(this.privacy, flags);
- dest.writeParcelable(this.type, flags);
- dest.writeParcelable(this.ownerAccount, flags);
- dest.writeParcelable(this.videoChannel, flags);
- }
}
}
diff --git a/app/src/main/java/app/fedilab/android/peertube/client/data/VideoData.java b/app/src/main/java/app/fedilab/android/peertube/client/data/VideoData.java
index f600cf99..df3892c8 100644
--- a/app/src/main/java/app/fedilab/android/peertube/client/data/VideoData.java
+++ b/app/src/main/java/app/fedilab/android/peertube/client/data/VideoData.java
@@ -17,16 +17,14 @@ package app.fedilab.android.peertube.client.data;
import android.content.Context;
import android.content.SharedPreferences;
-import android.os.Parcel;
-import android.os.Parcelable;
import com.google.gson.annotations.SerializedName;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
-import app.fedilab.android.peertube.client.data.AccountData.Account;
import app.fedilab.android.peertube.client.entities.File;
import app.fedilab.android.peertube.client.entities.Item;
import app.fedilab.android.peertube.client.entities.ItemStr;
@@ -36,7 +34,7 @@ import app.fedilab.android.peertube.helper.Helper;
@SuppressWarnings({"unused", "RedundantSuppression"})
-public class VideoData {
+public class VideoData implements Serializable {
@SerializedName("total")
public int total;
@@ -44,20 +42,9 @@ public class VideoData {
public List