Some improvements

This commit is contained in:
Thomas 2020-06-27 12:23:03 +02:00
parent b0d34f0e31
commit 4275183b79
5 changed files with 85 additions and 2 deletions

View File

@ -1,8 +1,14 @@
package app.fedilab.fedilabtube;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
@ -11,7 +17,13 @@ import androidx.navigation.ui.NavigationUI;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import org.jetbrains.annotations.NotNull;
import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeInformationAsyncTask;
import app.fedilab.fedilabtube.helper.Helper;
import static app.fedilab.fedilabtube.helper.Helper.academies;
import static app.fedilab.fedilabtube.helper.Helper.getLiveInstance;
public class MainActivity extends AppCompatActivity {
@ -36,4 +48,46 @@ public class MainActivity extends AppCompatActivity {
NavigationUI.setupWithNavController(navView, navController);
}
@Override
public boolean onCreateOptionsMenu(@NotNull Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_change_instance) {
showRadioButtonDialog();
return true;
}
return super.onOptionsItemSelected(item);
}
private void showRadioButtonDialog() {
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, "ac-lyon.fr");
int i = 0;
for(String item: academies){
if( item.compareTo(acad) == 0) {
break;
}
i++;
}
alt_bld.setSingleChoiceItems(academies, i, (dialog, item) -> {
String newInstance = academies[item];
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_INSTANCE, newInstance);
editor.commit();
dialog.dismiss();
recreate();
});
AlertDialog alert = alt_bld.create();
alert.show();
}
}

View File

@ -119,7 +119,8 @@ public class Helper {
public static final String SET_DISPLAY_CONFIRM = "set_display_confirm";
public static final String INTENT_ADD_UPLOADED_MEDIA = "intent_add_uploaded_media";
//List of available academies
public static List<String> academies = new ArrayList<>(Arrays.asList(
public static String[] academies = {
"ac-aix-marseille.fr",
"ac-amiens.fr",
"ac-besancon.fr",
@ -150,7 +151,7 @@ public class Helper {
"ac-strasbourg.fr",
"ac-toulouse.fr",
"ac-versailles.fr"
));
};
/**
* Returns the peertube URL depending of the academic domain name

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M19.07,4.93l-1.41,1.41C19.1,7.79 20,9.79 20,12c0,4.42 -3.58,8 -8,8s-8,-3.58 -8,-8c0,-4.08 3.05,-7.44 7,-7.93v2.02C8.16,6.57 6,9.03 6,12c0,3.31 2.69,6 6,6s6,-2.69 6,-6c0,-1.66 -0.67,-3.16 -1.76,-4.24l-1.41,1.41C15.55,9.9 16,10.9 16,12c0,2.21 -1.79,4 -4,4s-4,-1.79 -4,-4c0,-1.86 1.28,-3.41 3,-3.86v2.14c-0.6,0.35 -1,0.98 -1,1.72 0,1.1 0.9,2 2,2s2,-0.9 2,-2c0,-0.74 -0.4,-1.38 -1,-1.72V2h-1C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10c0,-2.76 -1.12,-5.26 -2.93,-7.07z"/>
</vector>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_change_instance"
android:icon="@drawable/ic_baseline_track_changes_24"
android:title="@string/change_instance"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_account"
android:icon="@drawable/ic_outline_account_circle_24"
android:title="@string/account"
app:showAsAction="ifRoom" />
</menu>

View File

@ -94,4 +94,7 @@
<string name="display_nsfw_videos">Afficher les vidéos sensibles</string>
<string name="action_playlist_add">Vous n\'avez aucune liste de lecture. Cliquez sur l\'icône « + » pour en ajouter une</string>
<string name="not_logged_in">Vous devez être connecté.e pour effectuer cette action !</string>
<string name="change_instance">Changer d\'instance</string>
<string name="account">Compte</string>
<string name="instance_choice">Choisissez une instance</string>
</resources>