diff --git a/app/src/main/java/app/fedilab/fedilabtube/LoginActivity.java b/app/src/main/java/app/fedilab/fedilabtube/LoginActivity.java index 09d4dcb..d56435b 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/LoginActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/LoginActivity.java @@ -8,13 +8,13 @@ import android.text.SpannableString; import android.text.Spanned; import android.text.style.ForegroundColorSpan; import android.text.style.UnderlineSpan; +import android.util.Log; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; -import android.widget.ImageView; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; @@ -62,11 +62,7 @@ public class LoginActivity extends AppCompatActivity { 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(), - Spanned.SPAN_INCLUSIVE_EXCLUSIVE); - create_an_account_peertube.setText(content_create); + create_an_account_peertube.setOnClickListener(v -> { Intent mainActivity = new Intent(LoginActivity.this, PeertubeRegisterActivity.class); @@ -90,6 +86,12 @@ public class LoginActivity extends AppCompatActivity { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { host = Helper.academies[position]; + SpannableString content_create = new SpannableString(getString(R.string.join_peertube_on, host)); + 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(), + Spanned.SPAN_INCLUSIVE_EXCLUSIVE); + create_an_account_peertube.setText(content_create); + retrievesClientId(); } @Override @@ -98,8 +100,6 @@ public class LoginActivity extends AppCompatActivity { } }); - ImageView main_logo = findViewById(R.id.main_logo); - main_logo.setImageResource(R.drawable.ic_launcher); connectionButton.setEnabled(false); @@ -125,9 +125,9 @@ public class LoginActivity extends AppCompatActivity { host = url.getHost(); } catch (MalformedURLException ignored) { } - host = Helper.getPeertubeUrl(host); + instance = Helper.getPeertubeUrl(host); try { - instance = URLEncoder.encode(host, "utf-8"); + instance = URLEncoder.encode(instance, "utf-8"); } catch (UnsupportedEncodingException e) { Toasty.error(LoginActivity.this, getString(R.string.client_error), Toast.LENGTH_LONG).show(); } @@ -168,7 +168,9 @@ public class LoginActivity extends AppCompatActivity { }); } }).start(); + String finalHost = host; connectionButton.setOnClickListener(v -> { + connectionButton.setEnabled(false); parameters.clear(); SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); @@ -202,12 +204,7 @@ public class LoginActivity extends AppCompatActivity { editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token); editor.apply(); //Update the account with the token; - if (instance != null) { - new UpdateAccountInfoAsyncTask(LoginActivity.this, token, client_id, client_secret, refresh_token, instance).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else { - connectionButton.setEnabled(true); - Toasty.error(LoginActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); - } + new UpdateAccountInfoAsyncTask(LoginActivity.this, token, client_id, client_secret, refresh_token, finalHost).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } catch (JSONException e) { e.printStackTrace(); } diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeRegisterActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeRegisterActivity.java index 3eb4e6d..573f341 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeRegisterActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeRegisterActivity.java @@ -13,6 +13,8 @@ import android.widget.TextView; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; +import java.util.Arrays; + import app.fedilab.fedilabtube.asynctasks.CreatePeertubeAccountAsyncTask; import app.fedilab.fedilabtube.client.APIResponse; import app.fedilab.fedilabtube.client.entities.AccountCreation; @@ -61,6 +63,7 @@ public class PeertubeRegisterActivity extends AppCompatActivity implements OnPos Toasty.error(PeertubeRegisterActivity.this, getString(R.string.all_field_filled)).show(); return; } + if (!password.getText().toString().trim().equals(password_confirm.getText().toString().trim())) { Toasty.error(PeertubeRegisterActivity.this, getString(R.string.password_error)).show(); return; @@ -69,6 +72,11 @@ public class PeertubeRegisterActivity extends AppCompatActivity implements OnPos Toasty.error(PeertubeRegisterActivity.this, getString(R.string.email_error)).show(); return; } + String[] emailArray = email.getText().toString().split("@"); + if( emailArray.length > 1 && !Arrays.asList(Helper.valideEmails).contains(emailArray[1])) { + Toasty.error(PeertubeRegisterActivity.this, getString(R.string.email_error_domain, emailArray[1])).show(); + return; + } if (password.getText().toString().trim().length() < 8) { Toasty.error(PeertubeRegisterActivity.this, getString(R.string.password_too_short)).show(); return; @@ -90,8 +98,8 @@ public class PeertubeRegisterActivity extends AppCompatActivity implements OnPos String tos = getString(R.string.tos); String serverrules = getString(R.string.server_rules); String content_agreement = getString(R.string.agreement_check, - "" + serverrules + "", - "" + tos + "" + "" + serverrules + "", + "" + tos + "" ); agreement_text.setMovementMethod(LinkMovementMethod.getInstance()); agreement_text.setText(Html.fromHtml(content_agreement)); diff --git a/app/src/main/java/app/fedilab/fedilabtube/asynctasks/UpdateAccountInfoAsyncTask.java b/app/src/main/java/app/fedilab/fedilabtube/asynctasks/UpdateAccountInfoAsyncTask.java index 02c406f..a4a1df9 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/asynctasks/UpdateAccountInfoAsyncTask.java +++ b/app/src/main/java/app/fedilab/fedilabtube/asynctasks/UpdateAccountInfoAsyncTask.java @@ -6,6 +6,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.database.sqlite.SQLiteDatabase; import android.os.AsyncTask; +import android.util.Log; import java.io.UnsupportedEncodingException; import java.lang.ref.WeakReference; @@ -22,13 +23,13 @@ import app.fedilab.fedilabtube.sqlite.Sqlite; public class UpdateAccountInfoAsyncTask extends AsyncTask { private String token, client_id, client_secret, refresh_token; - private String instance; + private String host; private WeakReference contextReference; - public UpdateAccountInfoAsyncTask(Context context, String token, String client_id, String client_secret, String refresh_token, String instance) { + public UpdateAccountInfoAsyncTask(Context context, String token, String client_id, String client_secret, String refresh_token, String host) { this.contextReference = new WeakReference<>(context); this.token = token; - this.instance = instance; + this.host = host; this.client_id = client_id; this.client_secret = client_secret; this.refresh_token = refresh_token; @@ -40,6 +41,7 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask { if (this.contextReference == null) { return null; } + String instance = Helper.getPeertubeUrl(host); account = new PeertubeAPI(this.contextReference.get(), instance, null).verifyCredentials(); if (account == null) return null; @@ -61,7 +63,7 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask { editor.putString(Helper.PREF_KEY_ID, account.getId()); editor.putBoolean(Helper.PREF_IS_MODERATOR, account.isModerator()); editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, account.isAdmin()); - editor.putString(Helper.PREF_INSTANCE, instance); + editor.putString(Helper.PREF_INSTANCE, host); editor.apply(); if (userExists) new AccountDAO(this.contextReference.get(), db).updateAccountCredential(account); diff --git a/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java b/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java index a402a08..29c6d4f 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java +++ b/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java @@ -15,6 +15,7 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Environment; +import android.util.Log; import android.util.TypedValue; import android.view.View; import android.view.WindowManager; @@ -131,13 +132,9 @@ public class Helper { "ac-dijon.fr", "ac-grenoble.fr", "education.fr", - // "ac-guadeloupe.fr", - // "ac-guyane.fr", - // "ac-reunion.fr", "ac-lille.fr", "ac-limoges.fr", "ac-lyon.fr", - // "ac-martinique.fr", "ac-mayotte.fr", "ac-montpellier.fr", "ac-nancy.fr", @@ -148,12 +145,50 @@ public class Helper { "ac-poitiers.fr", "outremer.fr", "ac-rennes.fr", - // "ac-spm.fr", "ac-strasbourg.fr", "ac-toulouse.fr", "ac-versailles.fr" }; + + public static String[] valideEmails = { + "ac-aix-marseille.fr", + "ac-amiens.fr", + "ac-besancon.fr", + "ac-bordeaux.fr", + "clermont-ferrand.fr", + "ac-corse.fr", + "ac-creteil.fr", + "ac-dijon.fr", + "ac-grenoble.fr", + "education.fr", + "ac-guadeloupe.fr", + "ac-guyane.fr", + "ac-reunion.fr", + "ac-lille.fr", + "ac-limoges.fr", + "ac-lyon.fr", + "ac-martinique.fr", + "ac-mayotte.fr", + "ac-montpellier.fr", + "ac-nancy.fr", + "ac-nantes.fr", + "ac-normandie.fr", + "ac-orleans-tours.fr", + "ac-paris.fr", + "ac-poitiers.fr", + "ac-rennes.fr", + "ac-spm.fr", + "ac-strasbourg.fr", + "ac-toulouse.fr", + "ac-versailles.fr", + "ac-wf.wf", + "monvr.pf", + "ac-noumea.nc", + "education.gouv.fr", + "igesr.gouv.fr" + }; + /** * Returns the peertube URL depending of the academic domain name * diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml deleted file mode 100644 index 2b068d1..0000000 --- a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher.png b/app/src/main/res/drawable/ic_launcher.png deleted file mode 100644 index 5c7ff54..0000000 Binary files a/app/src/main/res/drawable/ic_launcher.png and /dev/null differ diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index fb0e5fb..f61a817 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -22,25 +22,20 @@ android:layout_gravity="center_horizontal" android:layout_marginTop="20dp" android:contentDescription="@string/app_logo" - app:layout_constraintEnd_toEndOf="parent" + android:src="@drawable/ic_launcher_foreground" + app:layout_constraintEnd_toStartOf="@+id/info_instance" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> - - - + app:layout_constraintStart_toEndOf="@+id/main_logo" + app:layout_constraintTop_toTopOf="@+id/main_logo" + app:layout_constraintBottom_toBottomOf="@+id/main_logo" + /> + app:layout_constraintTop_toBottomOf="@id/main_logo" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 14564e6..72762d0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -143,5 +143,7 @@ conditions de service règles du serveur J\'accepte les %1$s et les %2$s + Rejoindre %1$s + Les adresses mails %1$s ne sont pas autorisées ! \ No newline at end of file