1
0
mirror of https://framagit.org/tom79/fedilab-tube synced 2025-04-24 23:18:43 +02:00

Split code

This commit is contained in:
Thomas 2020-12-01 18:35:54 +01:00
parent 6911fbd124
commit 680bdf7bd2
20 changed files with 281 additions and 212 deletions

View File

@ -80,6 +80,7 @@ android {
buildConfigField "boolean", "google_restriction", "true"
buildConfigField "boolean", "surfing_mode", "false"
buildConfigField "boolean", "sepia_search", "false"
}
}

View File

@ -43,6 +43,8 @@ import app.fedilab.fedilabtube.client.entities.OauthParams;
import app.fedilab.fedilabtube.client.entities.Token;
import app.fedilab.fedilabtube.databinding.ActivityLoginBinding;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.helper.HelperAcadInstance;
import app.fedilab.fedilabtube.helper.HelperInstance;
import es.dmoral.toasty.Toasty;
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.updateCredential;
@ -106,7 +108,7 @@ public class LoginActivity extends AppCompatActivity {
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 && Arrays.asList(Helper.openid).contains(emailArray[1])) {
if (emailArray.length > 1 && Arrays.asList(HelperAcadInstance.openid).contains(emailArray[1])) {
binding.loginButton.callOnClick();
}
}
@ -125,13 +127,13 @@ public class LoginActivity extends AppCompatActivity {
String instance, host;
if (!BuildConfig.full_instances) {
String[] emailArray = binding.loginUid.getText().toString().split("@");
if (emailArray.length > 1 && !Arrays.asList(Helper.valideEmails).contains(emailArray[1])) {
if (emailArray.length > 1 && !Arrays.asList(HelperAcadInstance.valideEmails).contains(emailArray[1])) {
Toasty.error(LoginActivity.this, getString(R.string.email_error_domain, emailArray[1])).show();
binding.loginButton.setEnabled(true);
return;
}
host = emailArray[1];
instance = Helper.getPeertubeUrl(host);
instance = HelperInstance.getPeertubeUrl(host);
} else {
if (binding.loginInstance.getText() == null || binding.loginInstance.getText().toString().trim().length() == 0) {
Toasty.error(LoginActivity.this, getString(R.string.not_valide_instance)).show();
@ -165,7 +167,7 @@ public class LoginActivity extends AppCompatActivity {
}
String finalInstance = instance;
String finalHost = host;
if (Arrays.asList(Helper.openid).contains(host) && !BuildConfig.full_instances) {
if (Arrays.asList(HelperAcadInstance.openid).contains(host) && !BuildConfig.full_instances) {
new Thread(() -> {
try {
Oauth oauth = new RetrofitPeertubeAPI(LoginActivity.this, finalInstance, null).oauthClient(null, null, null, null);
@ -185,7 +187,7 @@ public class LoginActivity extends AppCompatActivity {
editor.apply();
Intent intent = new Intent(LoginActivity.this, WebviewConnectActivity.class);
Bundle b = new Bundle();
b.putString("url", "https://" + Helper.getPeertubeUrl(finalHost) + "/plugins/auth-openid-connect/0.0.1/auth/openid-connect");
b.putString("url", "https://" + HelperInstance.getPeertubeUrl(finalHost) + "/plugins/auth-openid-connect/0.0.1/auth/openid-connect");
intent.putExtras(b);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

View File

@ -68,6 +68,7 @@ import app.fedilab.fedilabtube.databinding.ActivityMainBinding;
import app.fedilab.fedilabtube.fragment.DisplayOverviewFragment;
import app.fedilab.fedilabtube.fragment.DisplayVideosFragment;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.helper.HelperInstance;
import app.fedilab.fedilabtube.helper.PlaylistExportHelper;
import app.fedilab.fedilabtube.helper.SwitchAccountHelper;
import app.fedilab.fedilabtube.services.RetrieveInfoService;
@ -79,8 +80,8 @@ import es.dmoral.toasty.Toasty;
import static app.fedilab.fedilabtube.MainActivity.TypeOfConnection.NORMAL;
import static app.fedilab.fedilabtube.MainActivity.TypeOfConnection.SURFING;
import static app.fedilab.fedilabtube.helper.Helper.academies;
import static app.fedilab.fedilabtube.helper.Helper.peertubeInformation;
import static app.fedilab.fedilabtube.helper.HelperAcadInstance.academies;
public class MainActivity extends AppCompatActivity {
@ -99,7 +100,7 @@ public class MainActivity extends AppCompatActivity {
final SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
AlertDialog.Builder alt_bld = new AlertDialog.Builder(activity);
alt_bld.setTitle(R.string.instance_choice);
String instance = Helper.getLiveInstance(activity);
String instance = HelperInstance.getLiveInstance(activity);
final EditText input = new EditText(activity);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
@ -319,7 +320,7 @@ public class MainActivity extends AppCompatActivity {
new Thread(() -> {
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String tokenStr = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
String instance = Helper.getLiveInstance(MainActivity.this);
String instance = HelperInstance.getLiveInstance(MainActivity.this);
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);
@ -649,10 +650,10 @@ 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 = Helper.getLiveInstance(MainActivity.this);
String acad = HelperInstance.getLiveInstance(MainActivity.this);
int i = 0;
for (String item : academies) {
if (Helper.getPeertubeUrl(item).compareTo(acad) == 0) {
if (HelperInstance.getPeertubeUrl(item).compareTo(acad) == 0) {
break;
}
i++;

View File

@ -134,6 +134,7 @@ import app.fedilab.fedilabtube.drawer.MenuAdapter;
import app.fedilab.fedilabtube.drawer.MenuItemAdapter;
import app.fedilab.fedilabtube.helper.CacheDataSourceFactory;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.helper.HelperInstance;
import app.fedilab.fedilabtube.sqlite.AccountDAO;
import app.fedilab.fedilabtube.sqlite.Sqlite;
import app.fedilab.fedilabtube.viewmodel.CaptionsVM;
@ -153,7 +154,6 @@ import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.REPL
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.REPORT_ACCOUNT;
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.REPORT_VIDEO;
import static app.fedilab.fedilabtube.helper.Helper.getAttColor;
import static app.fedilab.fedilabtube.helper.Helper.getLiveInstance;
import static app.fedilab.fedilabtube.helper.Helper.isLoggedIn;
import static app.fedilab.fedilabtube.helper.Helper.loadGiF;
import static app.fedilab.fedilabtube.helper.Helper.peertubeInformation;
@ -295,7 +295,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
Bundle b = intent.getExtras();
if (b != null) {
peertubeInstance = b.getString("peertube_instance", Helper.getLiveInstance(PeertubeActivity.this));
peertubeInstance = b.getString("peertube_instance", HelperInstance.getLiveInstance(PeertubeActivity.this));
videoUuid = b.getString("video_uuid", null);
isMyVideo = b.getBoolean("isMyVideo", false);
sepiaSearch = b.getBoolean("sepia_search", false);
@ -521,7 +521,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
Bundle b = intent.getExtras();
if (b != null) {
isRemote = false;
peertubeInstance = b.getString("peertube_instance", Helper.getLiveInstance(PeertubeActivity.this));
peertubeInstance = b.getString("peertube_instance", HelperInstance.getLiveInstance(PeertubeActivity.this));
videoUuid = b.getString("video_uuid", null);
setRequestedOrientationCustom(initialOrientation);
if (comments != null && comments.size() > 0) {
@ -1606,7 +1606,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
if (captionToUse != null) {
if (!sepiaSearch) {
uri = Uri.parse("https://" + getLiveInstance(PeertubeActivity.this) + captionToUse.getCaptionPath());
uri = Uri.parse("https://" + HelperInstance.getLiveInstance(PeertubeActivity.this) + captionToUse.getCaptionPath());
} else {
uri = Uri.parse("https://" + peertubeInstance + captionToUse.getCaptionPath());
}

View File

@ -39,6 +39,8 @@ import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
import app.fedilab.fedilabtube.client.entities.AccountCreation;
import app.fedilab.fedilabtube.databinding.ActivityRegisterPeertubeBinding;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.helper.HelperAcadInstance;
import app.fedilab.fedilabtube.helper.HelperInstance;
import es.dmoral.toasty.Toasty;
import static app.fedilab.fedilabtube.MainActivity.PICK_INSTANCE;
@ -129,7 +131,7 @@ public class PeertubeRegisterActivity extends AppCompatActivity {
}
String[] emailArray = binding.email.getText().toString().split("@");
if (!BuildConfig.full_instances) {
if (emailArray.length > 1 && !Arrays.asList(Helper.valideEmails).contains(emailArray[1])) {
if (emailArray.length > 1 && !Arrays.asList(HelperAcadInstance.valideEmails).contains(emailArray[1])) {
Toasty.error(PeertubeRegisterActivity.this, getString(R.string.email_error_domain, emailArray[1])).show();
return;
}
@ -158,7 +160,7 @@ public class PeertubeRegisterActivity extends AppCompatActivity {
});
} else {
String host = emailArray[1];
instance = Helper.getPeertubeUrl(host);
instance = HelperInstance.getPeertubeUrl(host);
}
if (instance != null) {
instance = instance.toLowerCase().trim();

View File

@ -59,6 +59,7 @@ import app.fedilab.fedilabtube.client.data.ChannelData;
import app.fedilab.fedilabtube.client.entities.UserMe;
import app.fedilab.fedilabtube.databinding.ActivityPeertubeUploadBinding;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.helper.HelperInstance;
import app.fedilab.fedilabtube.viewmodel.ChannelsVM;
import es.dmoral.toasty.Toasty;
@ -323,7 +324,7 @@ public class PeertubeUploadActivity extends AppCompatActivity {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
new MultipartUploadRequest(PeertubeUploadActivity.this, "https://" + Helper.getLiveInstance(PeertubeUploadActivity.this) + "/api/v1/videos/upload")
new MultipartUploadRequest(PeertubeUploadActivity.this, "https://" + HelperInstance.getLiveInstance(PeertubeUploadActivity.this) + "/api/v1/videos/upload")
.setMethod("POST")
.setBearerAuth(token)
.addHeader("User-Agent", getString(R.string.app_name) + "/" + BuildConfig.VERSION_NAME)

View File

@ -60,7 +60,11 @@ import retrofit2.http.QueryMap;
public interface PeertubeService {
@GET("instances")
Call<InstanceData> getInstances(@QueryMap Map<String, String> params, @Query("nsfwPolicy[]") String nsfwPolicy, @Query("categoriesOr[]") List<Integer> categories, @Query("languagesOr[]") List<String> languages);
Call<InstanceData> getInstances(
@QueryMap Map<String, String> params,
@Query("nsfwPolicy[]") String nsfwPolicy,
@Query("categoriesOr[]") List<Integer> categories,
@Query("languagesOr[]") List<String> languages);
//Server settings
@GET(".well-known/nodeinfo")

View File

@ -74,6 +74,7 @@ import app.fedilab.fedilabtube.client.entities.UserSettings;
import app.fedilab.fedilabtube.client.entities.VideoParams;
import app.fedilab.fedilabtube.client.entities.WellKnownNodeinfo;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.helper.HelperInstance;
import app.fedilab.fedilabtube.sqlite.AccountDAO;
import app.fedilab.fedilabtube.sqlite.Sqlite;
import app.fedilab.fedilabtube.viewmodel.ChannelsVM;
@ -101,8 +102,8 @@ public class RetrofitPeertubeAPI {
public RetrofitPeertubeAPI(Context context) {
_context = context;
instance = Helper.getLiveInstance(context);
finalUrl = "https://" + Helper.getLiveInstance(context) + "/api/v1/";
instance = HelperInstance.getLiveInstance(context);
finalUrl = "https://" + HelperInstance.getLiveInstance(context) + "/api/v1/";
SharedPreferences sharedpreferences = _context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
count = String.valueOf(sharedpreferences.getInt(Helper.SET_VIDEOS_PER_PAGE, Helper.VIDEOS_PER_PAGE));
}
@ -124,7 +125,7 @@ public class RetrofitPeertubeAPI {
if (host.startsWith("tube") || BuildConfig.full_instances) {
instance = host;
} else {
instance = Helper.getPeertubeUrl(host);
instance = HelperInstance.getPeertubeUrl(host);
}
try {
UserMe userMe = new RetrofitPeertubeAPI(activity, instance, token).verifyCredentials();
@ -870,7 +871,7 @@ public class RetrofitPeertubeAPI {
params.put("count", "250");
params.put("healthy", "true");
params.put("signup", "true");
params.put("minUserQuota", instanceParams.getMinUserQuota());
params.put("sort", "-totalUsers");
Call<InstanceData> instancesCall = peertubeService.getInstances(params, instanceParams.getNsfwPolicy(), instanceParams.getCategoriesOr(), instanceParams.getLanguagesOr());
APIResponse apiResponse = new APIResponse();
try {

View File

@ -61,6 +61,7 @@ import app.fedilab.fedilabtube.client.entities.PlaylistExist;
import app.fedilab.fedilabtube.client.entities.Report;
import app.fedilab.fedilabtube.databinding.DrawerPeertubeBinding;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.helper.HelperInstance;
import app.fedilab.fedilabtube.viewmodel.PlaylistsVM;
import app.fedilab.fedilabtube.viewmodel.PostActionsVM;
import app.fedilab.fedilabtube.viewmodel.TimelineVM;
@ -405,8 +406,8 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
urlPreview = "https://" + instance + urlPreview;
thumbnail = "https://" + instance + thumbnail;
} else {
urlPreview = "https://" + Helper.getLiveInstance(context) + urlPreview;
thumbnail = "https://" + Helper.getLiveInstance(context) + thumbnail;
urlPreview = "https://" + HelperInstance.getLiveInstance(context) + urlPreview;
thumbnail = "https://" + HelperInstance.getLiveInstance(context) + thumbnail;
}
RequestBuilder<Drawable> requestBuilder = Glide.with(context)
.asDrawable();

View File

@ -41,6 +41,7 @@ import app.fedilab.fedilabtube.client.data.NotificationData.Notification;
import app.fedilab.fedilabtube.client.entities.Actor;
import app.fedilab.fedilabtube.fragment.DisplayNotificationsFragment;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.helper.HelperInstance;
public class PeertubeNotificationsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@ -148,7 +149,7 @@ public class PeertubeNotificationsListAdapter extends RecyclerView.Adapter<Recyc
Intent intent = new Intent(context, PeertubeActivity.class);
Bundle b = new Bundle();
b.putParcelable("video", notification.getVideo());
b.putString("peertube_instance", Helper.getLiveInstance(context));
b.putString("peertube_instance", HelperInstance.getLiveInstance(context));
b.putBoolean("isMyVideo", finalMyVideo);
b.putString("video_id", notification.getVideo().getId());
b.putString("video_uuid", notification.getVideo().getUuid());

View File

@ -65,6 +65,7 @@ import app.fedilab.fedilabtube.client.data.PlaylistData.Playlist;
import app.fedilab.fedilabtube.client.data.VideoPlaylistData;
import app.fedilab.fedilabtube.databinding.DrawerPlaylistBinding;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.helper.HelperInstance;
import app.fedilab.fedilabtube.helper.NotificationHelper;
import app.fedilab.fedilabtube.helper.PlaylistExportHelper;
import app.fedilab.fedilabtube.sqlite.ManagePlaylistsDAO;
@ -241,7 +242,7 @@ public class PlaylistAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
}
String urlAvatar = playlist.getThumbnailPath() != null ? Helper.getLiveInstance(context) + playlist.getThumbnailPath() : null;
String urlAvatar = playlist.getThumbnailPath() != null ? HelperInstance.getLiveInstance(context) + playlist.getThumbnailPath() : null;
FutureTarget<Bitmap> futureBitmapChannel = Glide.with(context.getApplicationContext())
.asBitmap()
.load(urlAvatar != null ? urlAvatar : R.drawable.missing_peertube).submit();

View File

@ -58,6 +58,7 @@ import app.fedilab.fedilabtube.databinding.AddChannelBinding;
import app.fedilab.fedilabtube.databinding.FragmentRecyclerviewBinding;
import app.fedilab.fedilabtube.drawer.ChannelListAdapter;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.helper.HelperInstance;
import app.fedilab.fedilabtube.viewmodel.ChannelsVM;
import app.fedilab.fedilabtube.viewmodel.SearchVM;
import es.dmoral.toasty.Toasty;
@ -303,7 +304,7 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap
if (oldChannelValues == null) {
apiResponse = new RetrofitPeertubeAPI(context).createOrUpdateChannel(ChannelsVM.action.CREATE_CHANNEL, null, channelCreation, inputData);
} else {
apiResponse = new RetrofitPeertubeAPI(context).createOrUpdateChannel(ChannelsVM.action.UPDATE_CHANNEL, channelCreation.getName() + "@" + Helper.getLiveInstance(context), channelCreation, inputData);
apiResponse = new RetrofitPeertubeAPI(context).createOrUpdateChannel(ChannelsVM.action.UPDATE_CHANNEL, channelCreation.getName() + "@" + HelperInstance.getLiveInstance(context), channelCreation, inputData);
}
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {

View File

@ -39,6 +39,7 @@ import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
import app.fedilab.fedilabtube.client.entities.Error;
import app.fedilab.fedilabtube.client.entities.UserSettings;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.helper.HelperInstance;
import app.fedilab.fedilabtube.helper.ThemeHelper;
import es.dmoral.toasty.Toasty;
@ -275,7 +276,7 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
my_account.setIcon(defaultAvatar);
String avatarUrl = null;
if (userMe.getAccount().getAvatar() != null) {
avatarUrl = "https://" + Helper.getLiveInstance(context) + userMe.getAccount().getAvatar().getPath();
avatarUrl = "https://" + HelperInstance.getLiveInstance(context) + userMe.getAccount().getAvatar().getPath();
}
Glide.with(getActivity())
.asDrawable()

View File

@ -61,7 +61,6 @@ import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;
import app.fedilab.fedilabtube.BuildConfig;
import app.fedilab.fedilabtube.MainActivity;
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.WebviewActivity;
@ -132,186 +131,8 @@ public class Helper {
public static final int VIDEOS_PER_PAGE = 10;
public static final String RECEIVE_ACTION = "receive_action";
public static final String SET_UNFOLLOW_VALIDATION = "set_unfollow_validation";
//List of available academies
public static String[] openid = {
"ac-normandie.fr",
"education.fr",
"education.gouv.fr"
//TODO: remove this one used for tests
// "ac-orleans-tours.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"
};
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
*
* @param acad String academic domain name
* @return String the peertube URL
*/
public static String getPeertubeUrl(String acad) {
if (BuildConfig.full_instances) {
return 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";
}
}
/**
* Returns the instance of the authenticated user
*
* @param context Context
* @return String domain instance
*/
public static String getLiveInstance(Context context) {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String acad;
if (BuildConfig.full_instances) {
return sharedpreferences.getString(Helper.PREF_INSTANCE, getDefaultInstance());
} else {
acad = sharedpreferences.getString(Helper.PREF_INSTANCE, "tube.ac-lyon.fr");
if (acad == null) {
acad = "tube.ac-lyon.fr";
}
if (acad.startsWith("tube-")) {
return acad;
} else {
return getPeertubeUrl(acad);
}
}
}
/**
* Get a default instance host name depending of the device locale
*
* @return peertube host String
*/
private static String getDefaultInstance() {
String lang = Locale.getDefault().getLanguage();
if (lang.contains("-")) {
if (!lang.split("-")[0].trim().toLowerCase().startsWith("zh")) {
lang = lang.split("-")[0];
if (lang.split("-")[1].toLowerCase().contains("be")) {
lang = "be";
} else if (lang.split("-")[1].toLowerCase().contains("gb")) {
lang = "gb";
}
} else {
lang = lang.split("-")[0] + "-" + lang.split("-")[1].toUpperCase();
}
}
switch (lang) {
case "it":
return "peertube.uno";
case "be":
return "peertube.be";
case "fr":
return "video.liberta.vip";
case "de":
return "peertube.at";
case "ru":
return "peertube.su";
case "gb":
return "peertube.co.uk";
case "da":
case "sv":
case "nb":
case "fi":
case "is":
return "peertube.dk";
default:
return "peertube.social";
}
}
/**
* Convert a date in String -> format yyyy-MM-dd HH:mm:ss
@ -471,7 +292,7 @@ public class Helper {
return;
}
if (url.startsWith("/")) {
url = instance != null ? instance + url : Helper.getLiveInstance(context) + url;
url = instance != null ? instance + url : HelperInstance.getLiveInstance(context) + url;
}
if (!url.startsWith("http")) {
url = "https://" + url;

View File

@ -0,0 +1,98 @@
package app.fedilab.fedilabtube.helper;
/* 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>. */
public class HelperAcadInstance {
//List of available academies
public static String[] openid = {
"ac-normandie.fr",
"education.fr",
"education.gouv.fr"
//TODO: remove this one used for tests
// "ac-orleans-tours.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"
};
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"
};
}

View File

@ -0,0 +1,130 @@
package app.fedilab.fedilabtube.helper;
import android.content.Context;
import android.content.SharedPreferences;
import java.util.Locale;
import app.fedilab.fedilabtube.BuildConfig;
/* 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>. */
public class HelperInstance {
/**
* Returns the peertube URL depending of the academic domain name
*
* @param acad String academic domain name
* @return String the peertube URL
*/
public static String getPeertubeUrl(String acad) {
if (BuildConfig.full_instances) {
return 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";
}
}
/**
* Returns the instance of the authenticated user
*
* @param context Context
* @return String domain instance
*/
@SuppressWarnings("ConstantConditions")
public static String getLiveInstance(Context context) {
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) {
return sharedpreferences.getString(Helper.PREF_INSTANCE, getDefaultInstance());
} else if (BuildConfig.FLAVOR.compareTo("bittube") == 0) {
return sharedpreferences.getString(Helper.PREF_INSTANCE, "bittube.video");
} else {
acad = sharedpreferences.getString(Helper.PREF_INSTANCE, "tube.ac-lyon.fr");
if (acad == null) {
acad = "tube.ac-lyon.fr";
}
if (acad.startsWith("tube-")) {
return acad;
} else {
return getPeertubeUrl(acad);
}
}
}
/**
* Get a default instance host name depending of the device locale
*
* @return peertube host String
*/
private static String getDefaultInstance() {
String lang = Locale.getDefault().getLanguage();
if (lang.contains("-")) {
if (!lang.split("-")[0].trim().toLowerCase().startsWith("zh")) {
lang = lang.split("-")[0];
if (lang.split("-")[1].toLowerCase().contains("be")) {
lang = "be";
} else if (lang.split("-")[1].toLowerCase().contains("gb")) {
lang = "gb";
}
} else {
lang = lang.split("-")[0] + "-" + lang.split("-")[1].toUpperCase();
}
}
switch (lang) {
case "it":
return "peertube.uno";
case "be":
return "peertube.be";
case "fr":
return "video.liberta.vip";
case "de":
return "peertube.at";
case "ru":
return "peertube.su";
case "gb":
return "peertube.co.uk";
case "da":
case "sv":
case "nb":
case "fi":
case "is":
return "peertube.dk";
default:
return "peertube.social";
}
}
}

View File

@ -17,7 +17,7 @@ public class RoundedBackgroundSpan extends ReplacementSpan {
public RoundedBackgroundSpan(Context context) {
super();
backgroundColor = context.getResources().getColor(R.color.tag_color);
backgroundColor = context.getResources().getColor(R.color.colorAccent);
textColor = context.getResources().getColor(R.color.tag_color_text);
}

View File

@ -28,6 +28,7 @@ import app.fedilab.fedilabtube.client.data.AccountData.Account;
import app.fedilab.fedilabtube.client.entities.Avatar;
import app.fedilab.fedilabtube.client.entities.Token;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.helper.HelperInstance;
@SuppressWarnings("UnusedReturnValue")
@ -144,7 +145,7 @@ public class AccountDAO {
values.put(Sqlite.COL_OAUTHTOKEN, token.getAccess_token());
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = Helper.getLiveInstance(context);
String instance = HelperInstance.getLiveInstance(context);
try {
return db.update(Sqlite.TABLE_USER_ACCOUNT,
values, Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =?",

View File

@ -27,6 +27,7 @@ import java.util.List;
import app.fedilab.fedilabtube.client.data.InstanceData;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.helper.HelperInstance;
@SuppressWarnings("UnusedReturnValue")
@ -87,7 +88,7 @@ public class StoredInstanceDAO {
ContentValues values = new ContentValues();
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = Helper.getLiveInstance(context);
String instance = HelperInstance.getLiveInstance(context);
values.put(Sqlite.COL_USER_ID, userId != null ? userId : "_ALL_");
values.put(Sqlite.COL_USER_INSTANCE, instance != null ? instance : "_ALL_");

View File

@ -34,6 +34,7 @@ import app.fedilab.fedilabtube.client.data.AccountData;
import app.fedilab.fedilabtube.client.data.ChannelData;
import app.fedilab.fedilabtube.client.data.VideoData;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.helper.HelperInstance;
import app.fedilab.fedilabtube.sqlite.ManagePlaylistsDAO;
import app.fedilab.fedilabtube.sqlite.Sqlite;
@ -125,7 +126,7 @@ public class TimelineVM extends AndroidViewModel {
private void getSingle(String instance, String videoId, boolean myVideo) {
Context _mContext = getApplication().getApplicationContext();
boolean canUseToken = false;
if (instance == null || instance.compareTo(Helper.getLiveInstance(_mContext)) == 0) {
if (instance == null || instance.compareTo(HelperInstance.getLiveInstance(_mContext)) == 0) {
canUseToken = true;
}
boolean finalCanUseToken = canUseToken;