mirror of
https://framagit.org/tom79/fedilab-tube
synced 2025-04-25 07:28:46 +02:00
open id
This commit is contained in:
parent
235d6ac0aa
commit
2794ff94af
@ -71,11 +71,20 @@
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:label="@string/app_name"
|
||||
android:windowSoftInputMode="stateAlwaysHidden" />
|
||||
<activity
|
||||
android:name=".WebviewActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:label="@string/app_name" />
|
||||
<activity
|
||||
android:name=".WebviewConnectActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:label="@string/app_name" />
|
||||
<activity
|
||||
android:name=".LoginActivity"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:label="@string/app_name"
|
||||
android:windowSoftInputMode="stateAlwaysHidden"></activity>
|
||||
android:windowSoftInputMode="stateAlwaysHidden">
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".PeertubeRegisterActivity"
|
||||
android:configChanges="orientation|screenSize"
|
||||
|
@ -108,7 +108,6 @@ public class LoginActivity extends AppCompatActivity implements OnRetrievePeertu
|
||||
|
||||
TextView create_an_account_peertube = findViewById(R.id.create_an_account_peertube);
|
||||
|
||||
|
||||
SpannableString content_create = new SpannableString(getString(R.string.join_peertube));
|
||||
content_create.setSpan(new UnderlineSpan(), 0, content_create.length(), 0);
|
||||
content_create.setSpan(new ForegroundColorSpan(ContextCompat.getColor(LoginActivity.this, R.color.colorAccent)), 0, content_create.length(),
|
||||
@ -136,7 +135,7 @@ public class LoginActivity extends AppCompatActivity implements OnRetrievePeertu
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(LoginActivity.this));
|
||||
String instance = Helper.getLiveInstance(LoginActivity.this);
|
||||
|
||||
TextView instanceView = findViewById(R.id.instance);
|
||||
Account account = new AccountDAO(LoginActivity.this, db).getUniqAccount(userId, instance);
|
||||
@ -243,7 +242,49 @@ public class LoginActivity extends AppCompatActivity implements OnRetrievePeertu
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
Toasty.error(LoginActivity.this, getString(R.string.client_error), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
|
||||
if (Arrays.asList(Helper.openid).contains(host)) {
|
||||
String finalInstance = instance;
|
||||
new Thread(() -> {
|
||||
try {
|
||||
actionToken = "/api/v1/oauth-clients/local";
|
||||
String response = new HttpsConnection(LoginActivity.this).get("https://" + finalInstance + actionToken, 30, null, null);
|
||||
if (response == null) {
|
||||
runOnUiThread(() -> {
|
||||
connectionButton.setEnabled(true);
|
||||
Toasty.error(LoginActivity.this, getString(R.string.client_error), Toast.LENGTH_LONG).show();
|
||||
});
|
||||
return;
|
||||
}
|
||||
JSONObject resobj;
|
||||
resobj = new JSONObject(response);
|
||||
client_id = resobj.get(Helper.CLIENT_ID).toString();
|
||||
client_secret = resobj.get(Helper.CLIENT_SECRET).toString();
|
||||
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();
|
||||
parameters.clear();
|
||||
parameters.put(Helper.CLIENT_ID, sharedpreferences.getString(Helper.CLIENT_ID, null));
|
||||
parameters.put(Helper.CLIENT_SECRET, sharedpreferences.getString(Helper.CLIENT_SECRET, null));
|
||||
Intent intent = new Intent(LoginActivity.this, WebviewConnectActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
b.putString("url", "https://" + Helper.getPeertubeUrl(host) + "/plugins/auth-openid-connect/0.0.1/auth/openid-connect");
|
||||
intent.putExtras(b);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
runOnUiThread(() -> {
|
||||
connectionButton.setEnabled(true);
|
||||
Toasty.error(LoginActivity.this, getString(R.string.client_error), Toast.LENGTH_LONG).show();
|
||||
});
|
||||
}
|
||||
|
||||
}).start();
|
||||
} else {
|
||||
parameters.clear();
|
||||
parameters.put(Helper.CLIENT_NAME, Helper.CLIENT_NAME_VALUE);
|
||||
parameters.put(Helper.REDIRECT_URIS, Helper.REDIRECT_CONTENT);
|
||||
@ -252,7 +293,15 @@ public class LoginActivity extends AppCompatActivity implements OnRetrievePeertu
|
||||
String finalInstance = instance;
|
||||
new Thread(() -> {
|
||||
try {
|
||||
actionToken = "/api/v1/oauth-clients/local";
|
||||
String response = new HttpsConnection(LoginActivity.this).get("https://" + finalInstance + actionToken, 30, parameters, null);
|
||||
if (response == null) {
|
||||
runOnUiThread(() -> {
|
||||
connectionButton.setEnabled(true);
|
||||
Toasty.error(LoginActivity.this, getString(R.string.client_error), Toast.LENGTH_LONG).show();
|
||||
});
|
||||
return;
|
||||
}
|
||||
JSONObject resobj;
|
||||
try {
|
||||
resobj = new JSONObject(response);
|
||||
@ -332,6 +381,8 @@ public class LoginActivity extends AppCompatActivity implements OnRetrievePeertu
|
||||
});
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -149,7 +149,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
AlertDialog.Builder alt_bld = new AlertDialog.Builder(this);
|
||||
alt_bld.setTitle(R.string.instance_choice);
|
||||
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String acad = sharedpreferences.getString(Helper.PREF_INSTANCE, "tube.ac-lyon.fr");
|
||||
String acad = Helper.getLiveInstance(MainActivity.this);
|
||||
int i = 0;
|
||||
for (String item : academies) {
|
||||
if (item.compareTo(acad) == 0) {
|
||||
|
@ -177,7 +177,7 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee
|
||||
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(PeertubeActivity.this));
|
||||
String instance = Helper.getLiveInstance(PeertubeActivity.this);
|
||||
Account account = new AccountDAO(PeertubeActivity.this, db).getUniqAccount(userId, instance);
|
||||
Helper.loadGiF(PeertubeActivity.this, account, my_pp);
|
||||
Bundle b = getIntent().getExtras();
|
||||
|
@ -221,7 +221,7 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
|
||||
|
||||
PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
|
||||
mPager.setAdapter(mPagerAdapter);
|
||||
if( ischannel) {
|
||||
if (ischannel) {
|
||||
ViewGroup.LayoutParams params = tabLayout.getLayoutParams();
|
||||
params.height = 0;
|
||||
tabLayout.setLayoutParams(params);
|
||||
@ -401,17 +401,17 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
|
||||
}
|
||||
doAction = action.UNFOLLOW;
|
||||
account_follow.setContentDescription(getString(R.string.action_unfollow));
|
||||
if(ischannel) {
|
||||
if (ischannel) {
|
||||
account_follow.setVisibility(View.VISIBLE);
|
||||
}else{
|
||||
} else {
|
||||
account_follow.setVisibility(View.GONE);
|
||||
}
|
||||
} else if (!relationship.isFollowing()) {
|
||||
account_follow.setImageResource(R.drawable.ic_user_plus);
|
||||
doAction = action.FOLLOW;
|
||||
if(ischannel) {
|
||||
if (ischannel) {
|
||||
account_follow.setVisibility(View.VISIBLE);
|
||||
}else{
|
||||
} else {
|
||||
account_follow.setVisibility(View.GONE);
|
||||
}
|
||||
account_follow.setContentDescription(getString(R.string.action_follow));
|
||||
|
@ -0,0 +1,175 @@
|
||||
package app.fedilab.fedilabtube;
|
||||
/* Copyright 2020 Thomas Schneider
|
||||
*
|
||||
* This file is a part of TubeLab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
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 androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import app.fedilab.fedilabtube.asynctasks.UpdateAccountInfoAsyncTask;
|
||||
import app.fedilab.fedilabtube.client.HttpsConnection;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.webview.CustomWebview;
|
||||
|
||||
|
||||
public class WebviewConnectActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
private CustomWebview webView;
|
||||
private AlertDialog alert;
|
||||
private String clientId, clientSecret;
|
||||
private String url;
|
||||
|
||||
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);
|
||||
|
||||
setContentView(R.layout.activity_webview_connect);
|
||||
Bundle b = getIntent().getExtras();
|
||||
if (b != null) {
|
||||
url = b.getString("url");
|
||||
}
|
||||
if (url == null)
|
||||
finish();
|
||||
|
||||
String instance = Uri.parse(url).getHost();
|
||||
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);
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
|
||||
} else {
|
||||
CookieManager.getInstance().setAcceptCookie(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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
webView.setWebViewClient(new WebViewClient() {
|
||||
|
||||
|
||||
@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 {
|
||||
String newUrl = "https://" + new URL(url).getHost() + "/api/v1/users/token";
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
clientId = sharedpreferences.getString(Helper.CLIENT_ID, "null");
|
||||
clientSecret = sharedpreferences.getString(Helper.CLIENT_SECRET, "null");
|
||||
params.put("client_id", clientId);
|
||||
params.put("client_secret", clientSecret);
|
||||
params.put("username", username);
|
||||
params.put("grant_type", "password");
|
||||
params.put("externalAuthToken", externalAuthToken);
|
||||
String response = new HttpsConnection(WebviewConnectActivity.this).post(newUrl, 30, params, null);
|
||||
JSONObject jsonObject = new JSONObject(response);
|
||||
String token = jsonObject.getString("access_token");
|
||||
String refresh_token = jsonObject.getString("refresh_token");
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token);
|
||||
editor.putString(Helper.PREF_INSTANCE, new URL(url).getHost());
|
||||
editor.apply();
|
||||
new UpdateAccountInfoAsyncTask(WebviewConnectActivity.this, token, clientId, clientSecret, refresh_token, new URL(url).getHost()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
finish();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
super.onPageFinished(view, url);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
webView.loadUrl(url);
|
||||
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
}
|
@ -56,7 +56,7 @@ public class ManagePlaylistsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
protected Void doInBackground(Void... params) {
|
||||
SharedPreferences sharedpreferences = contextReference.get().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(contextReference.get()));
|
||||
String instance = Helper.getLiveInstance(contextReference.get());
|
||||
SQLiteDatabase db = Sqlite.getInstance(contextReference.get().getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(contextReference.get(), db).getUniqAccount(userId, instance);
|
||||
if (account == null) {
|
||||
|
@ -49,7 +49,7 @@ public class RetrievePeertubeChannelsAsyncTask extends AsyncTask<Void, Void, Voi
|
||||
SQLiteDatabase db = Sqlite.getInstance(contextReference.get().getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
SharedPreferences sharedpreferences = contextReference.get().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(contextReference.get()));
|
||||
String instance = Helper.getLiveInstance(contextReference.get());
|
||||
Account account = new AccountDAO(contextReference.get(), db).getUniqAccount(userId, instance);
|
||||
if (account == null) {
|
||||
account = new AccountDAO(contextReference.get(), db).getUniqAccount(userId, Helper.getPeertubeUrl(instance));
|
||||
|
@ -54,7 +54,12 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
if (this.contextReference == null) {
|
||||
return null;
|
||||
}
|
||||
String instance = Helper.getPeertubeUrl(host);
|
||||
String instance;
|
||||
if (host.startsWith("tube")) {
|
||||
instance = host;
|
||||
} else {
|
||||
instance = Helper.getPeertubeUrl(host);
|
||||
}
|
||||
account = new PeertubeAPI(this.contextReference.get()).verifyCredentials(token, instance);
|
||||
if (account == null)
|
||||
return null;
|
||||
@ -76,7 +81,9 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
editor.putString(Helper.PREF_KEY_ID, account.getId());
|
||||
editor.putBoolean(Helper.PREF_IS_MODERATOR, account.isModerator());
|
||||
editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, account.isAdmin());
|
||||
if (!host.startsWith("tube")) {
|
||||
editor.putString(Helper.PREF_INSTANCE, host);
|
||||
}
|
||||
editor.apply();
|
||||
if (userExists)
|
||||
new AccountDAO(this.contextReference.get(), db).updateAccountCredential(account);
|
||||
|
@ -731,7 +731,6 @@ public class PeertubeAPI {
|
||||
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
|
||||
if (e.getStatusCode() == 401 || e.getStatusCode() == 403) {
|
||||
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account targetedAccount = new AccountDAO(context, db).getAccountByToken(token);
|
||||
|
@ -20,12 +20,9 @@ import android.app.DownloadManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
@ -43,7 +40,6 @@ import android.widget.Toast;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.browser.customtabs.CustomTabsIntent;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.graphics.drawable.DrawableCompat;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
|
||||
@ -81,15 +77,19 @@ public class Helper {
|
||||
public static final String SET_SHARE_DETAILS = "set_share_details";
|
||||
public static final int DEFAULT_VIDEO_CACHE_MB = 100;
|
||||
public static final String TAG = "mastodon_etalab";
|
||||
public static final String CLIENT_NAME_VALUE = "Fedilab";
|
||||
public static final String OAUTH_SCOPES_PEERTUBE = "user";
|
||||
public static final String ID = "id";
|
||||
public static final String CLIENT_ID = "client_id";
|
||||
public static final String CLIENT_SECRET = "client_secret";
|
||||
public static final String SCOPES = "scopes";
|
||||
public static final String WEBSITE = "website";
|
||||
public static final String WEBSITE_VALUE = "https://fedilab.app";
|
||||
public static final String CLIENT_NAME_VALUE = "TubeLab";
|
||||
public static final String OAUTH_SCOPES_PEERTUBE = "openid profile";
|
||||
public static final String PREF_KEY_OAUTH_TOKEN = "oauth_token";
|
||||
public static final Pattern urlPattern = Pattern.compile(
|
||||
"(?i)\\b((?:[a-z][\\w-]+:(?:/{1,3}|[a-z0-9%])|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,10}/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:'\".,<>?«»“”‘’]))",
|
||||
public static final String REDIRECT_URIS = "redirect_uris";
|
||||
|
||||
Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
|
||||
public static final Pattern hashtagPattern = Pattern.compile("(#[\\w_A-zÀ-ÿ]+)");
|
||||
public static final String LAST_NOTIFICATION_MAX_ID = "last_notification_max_id";
|
||||
public static final Pattern redirectPattern = Pattern.compile("externalAuthToken=(\\w+)&username=([\\w.-]+)");
|
||||
public static final String SET_VIDEO_CACHE = "set_video_cache";
|
||||
//Proxy
|
||||
public static final String SET_PROXY_ENABLED = "set_proxy_enabled";
|
||||
@ -109,13 +109,7 @@ public class Helper {
|
||||
public static final String VIDEO_ID = "video_id_update";
|
||||
public static final String CLIENT_NAME = "client_name";
|
||||
public static final String APP_PREFS = "app_prefs";
|
||||
public static final String ID = "id";
|
||||
public static final String CLIENT_ID = "client_id";
|
||||
public static final String CLIENT_SECRET = "client_secret";
|
||||
public static final String REDIRECT_URIS = "redirect_uris";
|
||||
public static final String SCOPES = "scopes";
|
||||
public static final String WEBSITE = "website";
|
||||
public static final String WEBSITE_VALUE = "https://fedilab.app";
|
||||
|
||||
public static final int VIDEOS_PER_PAGE = 40;
|
||||
public static final String SET_VIDEO_NSFW = "set_video_nsfw";
|
||||
public static final String SET_EMBEDDED_BROWSER = "set_embedded_browser";
|
||||
@ -125,6 +119,13 @@ public class Helper {
|
||||
public static final String SET_UNFOLLOW_VALIDATION = "set_unfollow_validation";
|
||||
//List of available academies
|
||||
|
||||
|
||||
public static String[] openid = {
|
||||
"ac-normandie.fr",
|
||||
//TODO: remove this one used for tests
|
||||
// "ac-orleans-tours.fr"
|
||||
};
|
||||
|
||||
public static String[] academies = {
|
||||
"ac-aix-marseille.fr",
|
||||
"ac-amiens.fr",
|
||||
@ -214,6 +215,10 @@ public class Helper {
|
||||
acad = "outremer.fr";
|
||||
}
|
||||
if (!acad.contains("ac-lyon.fr")) {
|
||||
//TODO: remove hack for test with openid
|
||||
/*if( acad.contains("orleans-tours.fr")) {
|
||||
return "tube-normandie.beta.education.fr";
|
||||
}*/
|
||||
return "tube-" + acad.replaceAll("ac-|\\.fr", "") + ".beta.education.fr";
|
||||
} else {
|
||||
return "tube.ac-lyon.fr";
|
||||
@ -230,8 +235,11 @@ public class Helper {
|
||||
public static String getLiveInstance(Context context) {
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String acad = sharedpreferences.getString(Helper.PREF_INSTANCE, "tube.ac-lyon.fr");
|
||||
if (acad.startsWith("tube-")) {
|
||||
return acad;
|
||||
} else {
|
||||
return getPeertubeUrl(acad);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static String instanceWithProtocol(Context context) {
|
||||
@ -376,15 +384,6 @@ public class Helper {
|
||||
}
|
||||
|
||||
|
||||
public static String dateDiffFull(Date dateToot) {
|
||||
SimpleDateFormat df = (SimpleDateFormat) DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM, Locale.getDefault());
|
||||
try {
|
||||
return df.format(dateToot);
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static String withSuffix(long count) {
|
||||
if (count < 1000) return "" + count;
|
||||
int exp = (int) (Math.log(count) / Math.log(1000));
|
||||
@ -443,7 +442,6 @@ public class Helper {
|
||||
|
||||
|
||||
public static void loadGiF(final Context context, String url, final ImageView imageView) {
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
|
||||
if (url.startsWith("/")) {
|
||||
url = Helper.getLiveInstance(context) + url;
|
||||
@ -632,33 +630,6 @@ public class Helper {
|
||||
return ContextCompat.getColor(context, typedValue.resourceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* change color of a drawable
|
||||
*
|
||||
* @param drawable int the drawable
|
||||
* @param hexaColor example 0xffff00
|
||||
*/
|
||||
public static Drawable changeDrawableColor(Context context, int drawable, int hexaColor) {
|
||||
Drawable mDrawable = ContextCompat.getDrawable(context, drawable);
|
||||
int color;
|
||||
try {
|
||||
color = Color.parseColor(context.getString(hexaColor));
|
||||
} catch (Resources.NotFoundException e) {
|
||||
try {
|
||||
TypedValue typedValue = new TypedValue();
|
||||
Resources.Theme theme = context.getTheme();
|
||||
theme.resolveAttribute(hexaColor, typedValue, true);
|
||||
color = typedValue.data;
|
||||
} catch (Resources.NotFoundException ed) {
|
||||
color = hexaColor;
|
||||
}
|
||||
}
|
||||
assert mDrawable != null;
|
||||
mDrawable.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
|
||||
DrawableCompat.setTint(mDrawable, color);
|
||||
return mDrawable;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns boolean depending if the user is authenticated
|
||||
|
40
app/src/main/res/layout/activity_webview_connect.xml
Normal file
40
app/src/main/res/layout/activity_webview_connect.xml
Normal file
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
Copyright 2020 Thomas Schneider
|
||||
|
||||
This file is a part of TubeLab
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
see <http://www.gnu.org/licenses>.
|
||||
-->
|
||||
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/drawer_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progress_bar"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="10dp"
|
||||
android:padding="2dp" />
|
||||
|
||||
<app.fedilab.fedilabtube.webview.CustomWebview
|
||||
android:id="@+id/webviewConnect"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
</LinearLayout>
|
||||
</androidx.drawerlayout.widget.DrawerLayout>
|
@ -165,4 +165,5 @@
|
||||
<string name="peertube_video_from_subscription"><![CDATA[<b>%1$s</b> a publié une nouvelle vidéo : <b>%2$s</b>]]></string>
|
||||
<string name="peertube_video_blacklist"><![CDATA[Votre vidéo <b>%1$s</b> a été blacklisté]]></string>
|
||||
<string name="peertube_video_unblacklist"><![CDATA[Votre vidéo <b>%1$s</b> n’est plus blacklisté]]></string>
|
||||
<string name="toast_code_error">Une erreur s’est produite ! L’instance n’a retourné aucun code d\autorisation !</string>
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user