Some fixes

This commit is contained in:
Thomas 2021-01-23 17:03:26 +01:00
parent d5f394dfea
commit edbe65593b
11 changed files with 291 additions and 139 deletions

View File

@ -68,7 +68,7 @@ assembleDebug:
cache: cache:
key: "${CI_COMMIT_TAG}" key: "${CI_COMMIT_TAG}"
paths: paths:
- app/build/outputs/apk/fdroid_peertube_apps_educ/debug/app-fdroid_peertube_apps_educ-debug.apk - app/build/outputs/apk/fdroid_acad/debug/app-fdroid_acad-debug.apk
- app/build/outputs/apk/fdroid_full/debug/app-fdroid_full-debug.apk - app/build/outputs/apk/fdroid_full/debug/app-fdroid_full-debug.apk
policy: push policy: push
script: script:
@ -76,11 +76,11 @@ assembleDebug:
# Basic android and gradle stuff # Basic android and gradle stuff
# Check linting # Check linting
lintfdroid_peertube_apps_educDebug: lintfdroid_acadDebug:
interruptible: true interruptible: true
stage: build stage: build
script: script:
- ./gradlew -Pci --console=plain :app:lintfdroid_peertube_apps_educDebug -PbuildDir=lint - ./gradlew -Pci --console=plain :app:lintfdroid_acadDebug -PbuildDir=lint
except: except:
- tags - tags
@ -110,7 +110,7 @@ putApkOnTags:
cache: cache:
key: "${CI_COMMIT_TAG}" key: "${CI_COMMIT_TAG}"
paths: paths:
- app/build/outputs/apk/fdroid_peertube_apps_educ/debug/app-fdroid_peertube_apps_educ-debug.apk - app/build/outputs/apk/fdroid_acad/debug/app-fdroid_acad-debug.apk
- app/build/outputs/apk/fdroid_full/debug/app-fdroid_full-debug.apk - app/build/outputs/apk/fdroid_full/debug/app-fdroid_full-debug.apk
policy: pull policy: pull
script: script:
@ -120,11 +120,11 @@ putApkOnTags:
- export NC_UPLOAD_URL="${NC_REMOTE_DIR}/${CI_COMMIT_TAG}" - export NC_UPLOAD_URL="${NC_REMOTE_DIR}/${CI_COMMIT_TAG}"
- export NC_DOWNLOAD_URL="${NC_SHARE_URL}/download?path=%2F${CI_COMMIT_TAG}%2F&files=" - export NC_DOWNLOAD_URL="${NC_SHARE_URL}/download?path=%2F${CI_COMMIT_TAG}%2F&files="
- 'export HEADER="Private-Token: ${GITLAB_API_TOKEN}"' - 'export HEADER="Private-Token: ${GITLAB_API_TOKEN}"'
- export acadUrl="${NC_DOWNLOAD_URL}app-fdroid_peertube_apps_educ-debug.apk" - export acadUrl="${NC_DOWNLOAD_URL}app-fdroid_acad-debug.apk"
- export fullUrl="${NC_DOWNLOAD_URL}app-fdroid_full-debug.apk" - export fullUrl="${NC_DOWNLOAD_URL}app-fdroid_full-debug.apk"
- 'curl -s -u "${NC_USER}:${NC_PASSWORD}" -X MKCOL "${NC_UPLOAD_URL}"' - 'curl -s -u "${NC_USER}:${NC_PASSWORD}" -X MKCOL "${NC_UPLOAD_URL}"'
- 'curl -s -u "${NC_USER}:${NC_PASSWORD}" -T app/build/outputs/apk/fdroid_full/debug/app-fdroid_full-debug.apk "${NC_UPLOAD_URL}/app-fdroid_full-debug.apk"' - 'curl -s -u "${NC_USER}:${NC_PASSWORD}" -T app/build/outputs/apk/fdroid_full/debug/app-fdroid_full-debug.apk "${NC_UPLOAD_URL}/app-fdroid_full-debug.apk"'
- 'curl -s -u "${NC_USER}:${NC_PASSWORD}" -T app/build/outputs/apk/fdroid_peertube_apps_educ/debug/app-fdroid_peertube_apps_educ-debug.apk "${NC_UPLOAD_URL}/app-fdroid_peertube_apps_educ-debug.apk"' - 'curl -s -u "${NC_USER}:${NC_PASSWORD}" -T app/build/outputs/apk/fdroid_acad/debug/app-fdroid_acad-debug.apk "${NC_UPLOAD_URL}/app-fdroid_acad-debug.apk"'
- export description=$(curl -s --header "${HEADER}" "${DESCRIPTION_URL}" | jq .release.description | sed -e 's@"@@g') - export description=$(curl -s --header "${HEADER}" "${DESCRIPTION_URL}" | jq .release.description | sed -e 's@"@@g')
- if [[ $description == 'null' ]]; then export METHOD="POST"; echo -e "[Get the acad version](${acadUrl})\n\n[Get the full version](${fullUrl})" > /tmp/text; fi - if [[ $description == 'null' ]]; then export METHOD="POST"; echo -e "[Get the acad version](${acadUrl})\n\n[Get the full version](${fullUrl})" > /tmp/text; fi
- if [[ $description != 'null' ]]; then export METHOD="PUT"; echo -e "${description}\n\n[Get the acad version](${acadUrl})\n\n[Get the full version](${fullUrl})" > /tmp/text; fi - if [[ $description != 'null' ]]; then export METHOD="PUT"; echo -e "${description}\n\n[Get the acad version](${acadUrl})\n\n[Get the full version](${fullUrl})" > /tmp/text; fi

View File

@ -42,7 +42,7 @@ android {
} }
//boolean full_instances if set to false means TubeAcad //boolean full_instances if set to false means TubeAcad
productFlavors { productFlavors {
fdroid_peertube_apps_educ { fdroid_acad {
applicationId "app.fedilab.fedilabtube" applicationId "app.fedilab.fedilabtube"
resValue "string", "app_name", "TubeAcad" resValue "string", "app_name", "TubeAcad"
resValue "string", "app_id", "app.fedilab.fedilabtube" resValue "string", "app_id", "app.fedilab.fedilabtube"
@ -57,7 +57,7 @@ android {
buildConfigField "int", "cast_enabled", "0" buildConfigField "int", "cast_enabled", "0"
buildConfigField "int", "default_theme", "2" buildConfigField "int", "default_theme", "2"
} }
google_peertube_apps_educ { google_acad {
applicationId "app.fedilab.fedilabtube" applicationId "app.fedilab.fedilabtube"
resValue "string", "app_name", "TubeAcad" resValue "string", "app_name", "TubeAcad"
resValue "string", "app_id", "app.fedilab.fedilabtube" resValue "string", "app_id", "app.fedilab.fedilabtube"
@ -68,8 +68,8 @@ android {
buildConfigField "boolean", "sepia_search", "false" buildConfigField "boolean", "sepia_search", "false"
buildConfigField "boolean", "instance_switcher", "true" buildConfigField "boolean", "instance_switcher", "true"
buildConfigField "boolean", "allow_remote_connections", "false" buildConfigField "boolean", "allow_remote_connections", "false"
buildConfigField "boolean", "google_cast_lib", "false" buildConfigField "boolean", "google_cast_lib", "true"
buildConfigField "int", "cast_enabled", "0" buildConfigField "int", "cast_enabled", "1"
buildConfigField "int", "default_theme", "2" buildConfigField "int", "default_theme", "2"
} }
fdroid_full { fdroid_full {
@ -135,13 +135,14 @@ android {
} }
sourceSets { sourceSets {
fdroid_peertube_apps_educ {
fdroid_acad {
res.srcDirs = ['src/main/res', 'src/acad/res', 'src/no_google_cast_lib/res'] res.srcDirs = ['src/main/res', 'src/acad/res', 'src/no_google_cast_lib/res']
java.srcDirs = ['src/main/java', 'src/acad/java', 'src/no_google_donation/java', 'src/no_google_cast_lib/java'] java.srcDirs = ['src/main/java', 'src/acad/java', 'src/no_google_donation/java', 'src/no_google_cast_lib/java']
} }
google_peertube_apps_educ { google_acad {
res.srcDirs = ['src/main/res', 'src/acad/res', 'src/no_google_cast_lib/res'] res.srcDirs = ['src/main/res', 'src/acad/res', 'src/no_google_cast_lib/res']
java.srcDirs = ['src/main/java', 'src/acad/java', 'src/no_google_donation/java', 'src/no_google_cast_lib/java'] java.srcDirs = ['src/main/java', 'src/acad/java', 'src/no_google_donation/java', 'src/google_cast_lib/java']
} }
fdroid_full { fdroid_full {
res.srcDirs = ['src/main/res', 'src/full/res', 'src/no_google_cast_lib/res'] res.srcDirs = ['src/main/res', 'src/full/res', 'src/no_google_cast_lib/res']
@ -221,23 +222,23 @@ dependencies {
//************ MATOMO --> acad instances only **************// //************ MATOMO --> acad instances only **************//
fdroid_peertube_apps_educImplementation 'org.matomo.sdk:tracker:4.1.2' fdroid_acadImplementation 'org.matomo.sdk:tracker:4.1.2'
google_peertube_apps_educImplementation 'org.matomo.sdk:tracker:4.1.2' google_acadImplementation 'org.matomo.sdk:tracker:4.1.2'
//************ CAST **************/// //************ CAST **************///
//---> Google libs (google_full + bittube) //---> Google libs (google_full + bittube)
google_acadImplementation "androidx.mediarouter:mediarouter:1.2.1"
google_acadImplementation 'com.google.android.gms:play-services-cast-framework:19.0.0'
google_fullImplementation "androidx.mediarouter:mediarouter:1.2.1" google_fullImplementation "androidx.mediarouter:mediarouter:1.2.1"
google_fullImplementation 'com.google.android.gms:play-services-cast-framework:19.0.0' google_fullImplementation 'com.google.android.gms:play-services-cast-framework:19.0.0'
bittubeImplementation "androidx.mediarouter:mediarouter:1.2.1" bittubeImplementation "androidx.mediarouter:mediarouter:1.2.1"
bittubeImplementation 'com.google.android.gms:play-services-cast-framework:19.0.0' bittubeImplementation 'com.google.android.gms:play-services-cast-framework:19.0.0'
//----> Other flavors //----> Other flavors
fdroid_peertube_apps_educImplementation 'su.litvak.chromecast:api-v2:0.11.3' fdroid_acadImplementation 'su.litvak.chromecast:api-v2:0.11.3'
fdroid_peertube_apps_educImplementation 'com.fasterxml.jackson.core:jackson-core:2.12.0' fdroid_acadImplementation 'com.fasterxml.jackson.core:jackson-core:2.12.0'
fdroid_peertube_apps_educImplementation 'org.slf4j:slf4j-simple:1.7.30' fdroid_acadImplementation 'org.slf4j:slf4j-simple:1.7.30'
google_peertube_apps_educImplementation 'su.litvak.chromecast:api-v2:0.11.3'
google_peertube_apps_educImplementation 'com.fasterxml.jackson.core:jackson-core:2.12.0'
google_peertube_apps_educImplementation 'org.slf4j:slf4j-simple:1.7.30'
fdroid_fullImplementation 'su.litvak.chromecast:api-v2:0.11.3' fdroid_fullImplementation 'su.litvak.chromecast:api-v2:0.11.3'
fdroid_fullImplementation 'com.fasterxml.jackson.core:jackson-core:2.12.0' fdroid_fullImplementation 'com.fasterxml.jackson.core:jackson-core:2.12.0'
fdroid_fullImplementation 'org.slf4j:slf4j-simple:1.7.30' fdroid_fullImplementation 'org.slf4j:slf4j-simple:1.7.30'

View File

@ -27,16 +27,15 @@
android:host="*" android:host="*"
android:pathPrefix="/videos/watch/" android:pathPrefix="/videos/watch/"
android:scheme="https" /> android:scheme="https" />
</intent-filter>
<meta-data <meta-data
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value=".PeertubeActivity" /> android:value=".PeertubeActivity" />
</intent-filter>
</activity> </activity>
<activity <activity
android:name=".expandedcontrols.ExpandedControlsActivity" android:name=".expandedcontrols.ExpandedControlsActivity"
android:theme="@style/AppThemeNoActionBar" android:theme="@style/AppThemeNoActionBar"
/> />
<meta-data <meta-data

View File

@ -22,6 +22,7 @@ import android.text.SpannableString;
import android.text.Spanned; import android.text.Spanned;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import android.text.style.UnderlineSpan; import android.text.style.UnderlineSpan;
import android.util.Log;
import android.util.Patterns; import android.util.Patterns;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -37,17 +38,16 @@ import androidx.core.content.ContextCompat;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.List;
import java.util.Iterator;
import java.util.Map;
import app.fedilab.fedilabtube.client.mastodon.RetrofitMastodonAPI;
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI; import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
import app.fedilab.fedilabtube.client.entities.AcadInstances;
import app.fedilab.fedilabtube.client.entities.Error; import app.fedilab.fedilabtube.client.entities.Error;
import app.fedilab.fedilabtube.client.entities.Oauth; import app.fedilab.fedilabtube.client.entities.Oauth;
import app.fedilab.fedilabtube.client.entities.OauthParams; import app.fedilab.fedilabtube.client.entities.OauthParams;
import app.fedilab.fedilabtube.client.entities.Token; import app.fedilab.fedilabtube.client.entities.Token;
import app.fedilab.fedilabtube.client.entities.WellKnownNodeinfo; import app.fedilab.fedilabtube.client.entities.WellKnownNodeinfo;
import app.fedilab.fedilabtube.client.mastodon.RetrofitMastodonAPI;
import app.fedilab.fedilabtube.databinding.ActivityLoginBinding; import app.fedilab.fedilabtube.databinding.ActivityLoginBinding;
import app.fedilab.fedilabtube.helper.Helper; import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.helper.HelperAcadInstance; import app.fedilab.fedilabtube.helper.HelperAcadInstance;
@ -120,16 +120,7 @@ public class LoginActivity extends AppCompatActivity {
} }
if (!BuildConfig.full_instances) { if (!BuildConfig.full_instances) {
binding.loginUid.setOnFocusChangeListener((v, hasFocus) -> {
if (!hasFocus) {
if (binding.loginUid.getText() != null && android.util.Patterns.EMAIL_ADDRESS.matcher(binding.loginUid.getText().toString().trim()).matches()) {
String[] emailArray = binding.loginUid.getText().toString().split("@");
if (emailArray.length > 1) {
binding.loginButton.callOnClick();
}
}
}
});
binding.loginUidContainer.setVisibility(View.GONE); binding.loginUidContainer.setVisibility(View.GONE);
binding.loginPasswdContainer.setVisibility(View.GONE); binding.loginPasswdContainer.setVisibility(View.GONE);
binding.loginInstanceContainer.setVisibility(View.GONE); binding.loginInstanceContainer.setVisibility(View.GONE);
@ -137,24 +128,24 @@ public class LoginActivity extends AppCompatActivity {
binding.instancePickerTitle.setVisibility(View.VISIBLE); binding.instancePickerTitle.setVisibility(View.VISIBLE);
binding.instancePicker.setVisibility(View.VISIBLE); binding.instancePicker.setVisibility(View.VISIBLE);
HashMap<String, String> instancesMap = new HashMap<>(HelperAcadInstance.instances_themes);
Iterator<Map.Entry<String, String>> it = instancesMap.entrySet().iterator(); List<AcadInstances> acadInstances = AcadInstances.getInstances();
String[] academiesKey = new String[HelperAcadInstance.instances_themes.size()]; String[] academiesKey = new String[acadInstances.size()];
String[] academiesValue = new String[HelperAcadInstance.instances_themes.size()]; String[] academiesValue = new String[acadInstances.size()];
String acad = HelperInstance.getLiveInstance(LoginActivity.this); String acad = HelperInstance.getLiveInstance(LoginActivity.this);
int position = 0; int position = 0;
int i = 0; int i = 0;
while (it.hasNext()) { for (AcadInstances ac : acadInstances) {
Map.Entry<String, String> pair = it.next(); academiesKey[i] = ac.getName();
academiesKey[i] = pair.getKey(); academiesValue[i] = ac.getUrl();
academiesValue[i] = pair.getValue(); Log.v(Helper.TAG, "url 1: " + ac.getUrl());
if (pair.getValue().compareTo(acad) == 0) { Log.v(Helper.TAG, "url 2: " + acad);
if (ac.getUrl().compareTo(acad) == 0) {
position = i; position = i;
Log.v(Helper.TAG, "ok: " + position);
} }
it.remove();
i++; i++;
} }
binding.instancePicker.setSelection(position, true);
ArrayAdapter<String> adapterChannel = new ArrayAdapter<>(LoginActivity.this, ArrayAdapter<String> adapterChannel = new ArrayAdapter<>(LoginActivity.this,
android.R.layout.simple_spinner_dropdown_item, academiesKey); android.R.layout.simple_spinner_dropdown_item, academiesKey);
binding.instancePicker.setAdapter(adapterChannel); binding.instancePicker.setAdapter(adapterChannel);
@ -162,6 +153,17 @@ public class LoginActivity extends AppCompatActivity {
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
acadInstance = academiesValue[position]; acadInstance = academiesValue[position];
if (acadInstances.get(position).isOpenId()) {
binding.loginUidContainer.setVisibility(View.GONE);
binding.loginPasswdContainer.setVisibility(View.GONE);
binding.loginInstanceContainer.setVisibility(View.GONE);
binding.createAnAccountPeertube.setVisibility(View.GONE);
} else {
binding.loginUidContainer.setVisibility(View.VISIBLE);
binding.loginPasswdContainer.setVisibility(View.VISIBLE);
binding.loginInstanceContainer.setVisibility(View.GONE);
binding.createAnAccountPeertube.setVisibility(View.VISIBLE);
}
} }
@Override @Override
@ -169,6 +171,7 @@ public class LoginActivity extends AppCompatActivity {
} }
}); });
binding.instancePicker.setSelection(position, true);
} }
if (BuildConfig.allow_remote_connections) { if (BuildConfig.allow_remote_connections) {
binding.loginInstance.setOnFocusChangeListener((v, hasFocus) -> { binding.loginInstance.setOnFocusChangeListener((v, hasFocus) -> {
@ -196,7 +199,7 @@ public class LoginActivity extends AppCompatActivity {
} }
binding.loginButton.setOnClickListener(v -> { binding.loginButton.setOnClickListener(v -> {
if (!BuildConfig.full_instances) { if (!BuildConfig.full_instances && AcadInstances.isOpenId(acadInstance)) {
new Thread(() -> { new Thread(() -> {
try { try {
Oauth oauth = new RetrofitPeertubeAPI(LoginActivity.this, acadInstance, null).oauthClient(null, null, null, null); Oauth oauth = new RetrofitPeertubeAPI(LoginActivity.this, acadInstance, null).oauthClient(null, null, null, null);
@ -275,7 +278,6 @@ public class LoginActivity extends AppCompatActivity {
return; return;
} }
String finalInstance = instance; String finalInstance = instance;
if (BuildConfig.full_instances) {
new Thread(() -> { new Thread(() -> {
WellKnownNodeinfo.NodeInfo instanceNodeInfo = null; WellKnownNodeinfo.NodeInfo instanceNodeInfo = null;
if (BuildConfig.allow_remote_connections) { if (BuildConfig.allow_remote_connections) {
@ -284,7 +286,6 @@ public class LoginActivity extends AppCompatActivity {
connectToFediverse(finalInstance, instanceNodeInfo); connectToFediverse(finalInstance, instanceNodeInfo);
}).start(); }).start();
} }
}
}); });
} }

View File

@ -49,11 +49,8 @@ import com.kobakei.ratethisapp.RateThisApp;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.net.URL; import java.net.URL;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -62,6 +59,7 @@ import java.util.regex.Pattern;
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI; import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
import app.fedilab.fedilabtube.client.data.AccountData.Account; import app.fedilab.fedilabtube.client.data.AccountData.Account;
import app.fedilab.fedilabtube.client.data.InstanceData; import app.fedilab.fedilabtube.client.data.InstanceData;
import app.fedilab.fedilabtube.client.entities.AcadInstances;
import app.fedilab.fedilabtube.client.entities.Error; import app.fedilab.fedilabtube.client.entities.Error;
import app.fedilab.fedilabtube.client.entities.OauthParams; import app.fedilab.fedilabtube.client.entities.OauthParams;
import app.fedilab.fedilabtube.client.entities.PeertubeInformation; import app.fedilab.fedilabtube.client.entities.PeertubeInformation;
@ -496,9 +494,9 @@ public class MainActivity extends BaseMainActivity {
MenuItem settingsItem = menu.findItem(R.id.action_settings); MenuItem settingsItem = menu.findItem(R.id.action_settings);
MenuItem sepiaSearchItem = menu.findItem(R.id.action_sepia_search); MenuItem sepiaSearchItem = menu.findItem(R.id.action_sepia_search);
MenuItem incognitoItem = menu.findItem(R.id.action_incognito); MenuItem incognitoItem = menu.findItem(R.id.action_incognito);
MenuItem instanceItem = menu.findItem(R.id.action_change_instance);
MenuItem accountItem = menu.findItem(R.id.action_account); MenuItem accountItem = menu.findItem(R.id.action_account);
MenuItem donateItem = menu.findItem(R.id.action_donate); MenuItem donateItem = menu.findItem(R.id.action_donate);
MenuItem changeInstanceItem = menu.findItem(R.id.action_change_instance);
FrameLayout rootView = (FrameLayout) accountItem.getActionView(); FrameLayout rootView = (FrameLayout) accountItem.getActionView();
@ -512,24 +510,15 @@ public class MainActivity extends BaseMainActivity {
redCircle.setVisibility(View.GONE); redCircle.setVisibility(View.GONE);
} }
TooltipCompat.setTooltipText(accountItem.getActionView(), getText(R.string.account)); TooltipCompat.setTooltipText(accountItem.getActionView(), getText(R.string.account));
if (BuildConfig.full_instances && BuildConfig.google_restriction) { if (BuildConfig.FLAVOR.compareTo("google_full") == 0) {
donateItem.setVisible(true); donateItem.setVisible(true);
} }
if (BuildConfig.surfing_mode && ((Helper.isLoggedIn(MainActivity.this) && typeOfConnection == NORMAL) || typeOfConnection == SURFING)) { if (!BuildConfig.instance_switcher) {
binding.instances.setVisibility(View.VISIBLE); changeInstanceItem.setVisible(false);
binding.instances.setOnClickListener(null);
binding.instances.setOnClickListener(v -> {
Intent intent = new Intent(MainActivity.this, ManageInstancesActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up);
});
} else {
binding.instances.setVisibility(View.GONE);
} }
switch (typeOfConnection) { switch (typeOfConnection) {
case UNKNOWN: case UNKNOWN:
instanceItem.setVisible(false);
accountItem.setVisible(false); accountItem.setVisible(false);
uploadItem.setVisible(false); uploadItem.setVisible(false);
myVideosItem.setVisible(false); myVideosItem.setVisible(false);
@ -543,7 +532,9 @@ public class MainActivity extends BaseMainActivity {
case NORMAL: case NORMAL:
accountItem.setVisible(true); accountItem.setVisible(true);
if (Helper.isLoggedIn(MainActivity.this)) { if (Helper.isLoggedIn(MainActivity.this)) {
instanceItem.setVisible(false); if (!BuildConfig.full_instances) {
changeInstanceItem.setVisible(false);
}
uploadItem.setVisible(true); uploadItem.setVisible(true);
myVideosItem.setVisible(true); myVideosItem.setVisible(true);
playslistItem.setVisible(true); playslistItem.setVisible(true);
@ -555,7 +546,6 @@ public class MainActivity extends BaseMainActivity {
boolean checked = sharedpreferences.getBoolean(getString(R.string.set_store_in_history), true); boolean checked = sharedpreferences.getBoolean(getString(R.string.set_store_in_history), true);
incognitoItem.setChecked(checked); incognitoItem.setChecked(checked);
} else { } else {
instanceItem.setVisible(true);
uploadItem.setVisible(false); uploadItem.setVisible(false);
myVideosItem.setVisible(false); myVideosItem.setVisible(false);
playslistItem.setVisible(!BuildConfig.full_instances); playslistItem.setVisible(!BuildConfig.full_instances);
@ -566,7 +556,6 @@ public class MainActivity extends BaseMainActivity {
} }
break; break;
case SURFING: case SURFING:
instanceItem.setVisible(false);
accountItem.setVisible(true); accountItem.setVisible(true);
uploadItem.setVisible(false); uploadItem.setVisible(false);
myVideosItem.setVisible(false); myVideosItem.setVisible(false);
@ -578,9 +567,6 @@ public class MainActivity extends BaseMainActivity {
break; break;
} }
if (!BuildConfig.instance_switcher) {
instanceItem.setVisible(false);
}
if (!BuildConfig.sepia_search) { if (!BuildConfig.sepia_search) {
sepiaSearchItem.setVisible(false); sepiaSearchItem.setVisible(false);
@ -624,7 +610,9 @@ public class MainActivity extends BaseMainActivity {
String action = "TIMELINE"; String action = "TIMELINE";
if (item.getItemId() == R.id.action_change_instance) { if (item.getItemId() == R.id.action_change_instance) {
if (BuildConfig.full_instances) { if (BuildConfig.full_instances) {
showRadioButtonDialogFullInstances(MainActivity.this, false); Intent intent = new Intent(MainActivity.this, ManageInstancesActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up);
} else { } else {
showRadioButtonDialog(); showRadioButtonDialog();
} }
@ -738,21 +726,19 @@ public class MainActivity extends BaseMainActivity {
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String acad = HelperInstance.getLiveInstance(MainActivity.this); String acad = HelperInstance.getLiveInstance(MainActivity.this);
int i = 0; int i = 0;
HashMap<String, String> instancesMap = new HashMap<>(HelperAcadInstance.instances_themes); List<AcadInstances> acadInstances = AcadInstances.getInstances();
Iterator<Map.Entry<String, String>> it = instancesMap.entrySet().iterator(); String[] academiesKey = new String[acadInstances.size()];
String[] academiesKey = new String[HelperAcadInstance.instances_themes.size()]; String[] academiesValue = new String[acadInstances.size()];
String[] academiesValue = new String[HelperAcadInstance.instances_themes.size()];
int position = 0; int position = 0;
while (it.hasNext()) { for (AcadInstances ac : acadInstances) {
Map.Entry<String, String> pair = it.next(); academiesKey[i] = ac.getName();
academiesKey[i] = pair.getKey(); academiesValue[i] = ac.getUrl();
academiesValue[i] = pair.getValue(); if (ac.getUrl().compareTo(acad) == 0) {
if (pair.getValue().compareTo(acad) == 0) {
position = i; position = i;
} }
it.remove();
i++; i++;
} }
alt_bld.setSingleChoiceItems(academiesKey, position, (dialog, item) -> { alt_bld.setSingleChoiceItems(academiesKey, position, (dialog, item) -> {
String newInstance = academiesValue[item]; String newInstance = academiesValue[item];
SharedPreferences.Editor editor = sharedpreferences.edit(); SharedPreferences.Editor editor = sharedpreferences.edit();

View File

@ -0,0 +1,109 @@
package app.fedilab.fedilabtube.client.entities;
/* Copyright 2021 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 java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import app.fedilab.fedilabtube.helper.HelperAcadInstance;
public class AcadInstances {
private String name;
private String url;
private boolean openId;
public static boolean isOpenId(String domain) {
List<AcadInstances> instances = getInstances();
for (AcadInstances acadInstance : instances) {
if (acadInstance.getUrl().compareTo(domain) == 0) {
return acadInstance.isOpenId();
}
}
return false;
}
public static List<AcadInstances> getInstances() {
List<AcadInstances> acadInstances = new ArrayList<>();
for (String academie : HelperAcadInstance.academies) {
AcadInstances acadInstance = new AcadInstances();
acadInstance.name = academie;
acadInstance.openId = !Arrays.asList(HelperAcadInstance.notOpenId).contains(academie);
acadInstance.url = getPeertubeUrl(academie);
acadInstances.add(acadInstance);
}
HashMap<String, String> instancesMap = new HashMap<>(HelperAcadInstance.instances_themes);
Iterator<Map.Entry<String, String>> it = instancesMap.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> pair = it.next();
AcadInstances acadInstance = new AcadInstances();
acadInstance.name = pair.getKey();
acadInstance.openId = true;
acadInstance.url = pair.getValue();
acadInstances.add(acadInstance);
it.remove();
}
return acadInstances;
}
/**
* Returns the peertube URL depending of the academic domain name
*
* @param acad String academic domain name
* @return String the peertube URL
*/
private static String getPeertubeUrl(String acad) {
if (acad.compareTo("education.gouv.fr") == 0 || acad.compareTo("igesr.gouv.fr") == 0) {
acad = "education.fr";
} else if (acad.compareTo("ac-nancy-metz.fr") == 0) {
acad = "ac-nancy.fr";
} else if (acad.compareTo("clermont.fr") == 0) {
acad = "clermont-ferrand.fr";
} else if (acad.compareTo("ac-wf.wf") == 0 || acad.compareTo("ac-mayotte.fr") == 0 || acad.compareTo("ac-noumea.nc") == 0
|| acad.compareTo("ac-guadeloupe.fr") == 0 || acad.compareTo("monvr.pf") == 0 || acad.compareTo("ac-reunion.fr") == 0 ||
acad.compareTo("ac-martinique.fr") == 0 || acad.compareTo("ac-guyane.fr") == 0
) {
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";
}
}
public String getName() {
return name;
}
public String getUrl() {
return url;
}
public boolean isOpenId() {
return openId;
}
}

View File

@ -32,6 +32,64 @@ public class HelperAcadInstance {
public static String SUBSCRIPTIONS = "ABONNEMENTS"; public static String SUBSCRIPTIONS = "ABONNEMENTS";
public static String MYVIDEOS = "VIDEOS"; public static String MYVIDEOS = "VIDEOS";
public static String[] notOpenId = {
"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",
"ac-lille.fr",
"ac-limoges.fr",
"ac-lyon.fr",
"ac-mayotte.fr",
"ac-montpellier.fr",
"ac-nancy.fr",
"ac-nantes.fr",
"ac-orleans-tours.fr",
"ac-paris.fr",
"ac-poitiers.fr",
"outremer.fr",
"ac-rennes.fr",
"ac-strasbourg.fr",
"ac-toulouse.fr",
"ac-versailles.fr"
};
public static String[] academies = {
"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-lille.fr",
"ac-limoges.fr",
"ac-lyon.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",
"outremer.fr",
"ac-rennes.fr",
"ac-strasbourg.fr",
"ac-toulouse.fr",
"ac-versailles.fr"
};
//List of available emails //List of available emails
public static String[] valideEmails = { public static String[] valideEmails = {
"ac-aix-marseille.fr", "ac-aix-marseille.fr",
@ -71,10 +129,11 @@ public class HelperAcadInstance {
"igesr.gouv.fr" "igesr.gouv.fr"
}; };
static { static {
Map<String, String> is = new LinkedHashMap<>(); Map<String, String> is = new LinkedHashMap<>();
is.put("Normandie", "tube-normandie.beta.education.fr"); //TODO: remove comments when instances will be available
is.put("Enseignement professionnel", "tube-enseignement-professionnel.apps.education.fr"); /* is.put("Enseignement professionnel", "tube-enseignement-professionnel.apps.education.fr");
is.put("Action éducative", "tube-action-educative.apps.education.fr"); is.put("Action éducative", "tube-action-educative.apps.education.fr");
is.put("Numérique éducatif", "tube-numerique-educatif.apps.education.fr"); is.put("Numérique éducatif", "tube-numerique-educatif.apps.education.fr");
is.put("Institutionnel", "tube-institutionnelle.apps.education.fr"); is.put("Institutionnel", "tube-institutionnelle.apps.education.fr");
@ -83,7 +142,7 @@ public class HelperAcadInstance {
is.put("2d - arts, lettres et sciences humaines", "tube-2d-arts-lettres-sciences-humaines.apps.education.fr"); is.put("2d - arts, lettres et sciences humaines", "tube-2d-arts-lettres-sciences-humaines.apps.education.fr");
is.put("Maternelle", "tube-maternelle.apps.education.fr"); is.put("Maternelle", "tube-maternelle.apps.education.fr");
is.put("Cycle 2", "tube-cycle-2.apps.education.fr"); is.put("Cycle 2", "tube-cycle-2.apps.education.fr");
is.put("Cycle 3", "tube-cycle-3.apps.education.fr"); is.put("Cycle 3", "tube-cycle-3.apps.education.fr");*/
instances_themes = Collections.unmodifiableMap(is); instances_themes = Collections.unmodifiableMap(is);
} }

View File

@ -30,10 +30,8 @@ public class HelperInstance {
* @param context Context * @param context Context
* @return String domain instance * @return String domain instance
*/ */
@SuppressWarnings("ConstantConditions")
public static String getLiveInstance(Context context) { public static String getLiveInstance(Context context) {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String acad;
if (BuildConfig.FLAVOR.compareTo("fdroid_full") == 0 || BuildConfig.FLAVOR.compareTo("google_full") == 0) { if (BuildConfig.FLAVOR.compareTo("fdroid_full") == 0 || BuildConfig.FLAVOR.compareTo("google_full") == 0) {
return sharedpreferences.getString(Helper.PREF_INSTANCE, getDefaultInstance()); return sharedpreferences.getString(Helper.PREF_INSTANCE, getDefaultInstance());
} else if (BuildConfig.FLAVOR.compareTo("bittube") == 0) { } else if (BuildConfig.FLAVOR.compareTo("bittube") == 0) {
@ -41,13 +39,15 @@ public class HelperInstance {
} else if (BuildConfig.FLAVOR.compareTo("queermotion") == 0) { } else if (BuildConfig.FLAVOR.compareTo("queermotion") == 0) {
return sharedpreferences.getString(Helper.PREF_INSTANCE, "queermotion.org"); return sharedpreferences.getString(Helper.PREF_INSTANCE, "queermotion.org");
} else { } else {
acad = sharedpreferences.getString(Helper.PREF_INSTANCE, "tube-institutionnelle.apps.education.fr"); String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, "tube.ac-lyon.fr");
if (acad == null) { if (!instance.startsWith("tube")) {
acad = "tube-institutionnelle.apps.education.fr"; return "tube.ac-lyon.fr";
} } else {
return acad; return instance;
} }
} }
}
/** /**
* Get a default instance host name depending of the device locale * Get a default instance host name depending of the device locale

View File

@ -81,6 +81,34 @@
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="@+id/instance_picker_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/instances_picker"
android:visibility="gone"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Spinner
android:id="@+id/instance_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="20dp"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/instance_picker_title" />
<androidx.constraintlayout.widget.Barrier
android:id="@+id/barrierTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="instance_picker, login_instance_container" />
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
android:id="@+id/login_uid_container" android:id="@+id/login_uid_container"
android:layout_width="0dp" android:layout_width="0dp"
@ -88,7 +116,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/login_instance_container"> app:layout_constraintTop_toBottomOf="@id/barrierTop">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
android:id="@+id/login_uid" android:id="@+id/login_uid"
@ -121,27 +149,7 @@
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="@+id/instance_picker_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/instances_picker"
android:visibility="gone"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Spinner
android:id="@+id/instance_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="20dp"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@+id/login_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/instance_picker_title" />
<androidx.constraintlayout.widget.Barrier <androidx.constraintlayout.widget.Barrier
android:id="@+id/barrier" android:id="@+id/barrier"

View File

@ -44,16 +44,6 @@
app:layout_scrollFlags="scroll|enterAlways" app:layout_scrollFlags="scroll|enterAlways"
android:fitsSystemWindows="true" android:fitsSystemWindows="true"
> >
<ImageView
android:id="@+id/instances"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_baseline_public_24"
android:layout_gravity="start"
android:contentDescription="@string/instance_choice"
android:layout_marginEnd="5dp"
app:tint="?attr/colorAccent" />
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@ -9,17 +9,16 @@
android:title="@string/search" android:title="@string/search"
app:actionViewClass="androidx.appcompat.widget.SearchView" app:actionViewClass="androidx.appcompat.widget.SearchView"
app:showAsAction="always|collapseActionView" /> app:showAsAction="always|collapseActionView" />
<item
android:id="@+id/action_change_instance"
android:icon="@drawable/ic_baseline_track_changes_24"
android:title="@string/change_instance"
android:visible="false"
app:showAsAction="ifRoom" />
<item <item
android:id="@+id/action_account" android:id="@+id/action_account"
app:actionLayout="@layout/counter_account_icon" app:actionLayout="@layout/counter_account_icon"
android:title="@string/account" android:title="@string/account"
app:showAsAction="ifRoom" /> app:showAsAction="ifRoom" />
<item
android:id="@+id/action_change_instance"
android:icon="@drawable/ic_baseline_track_changes_24"
android:title="@string/change_instance"
app:showAsAction="ifRoom" />
<item <item
android:id="@+id/action_playlist" android:id="@+id/action_playlist"
android:icon="@drawable/ic_baseline_playlist_play_24" android:icon="@drawable/ic_baseline_playlist_play_24"