mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2026-04-19 09:07:06 -04:00
[V2 UI] Implements account switcher
This commit is contained in:
@@ -11,13 +11,6 @@ public class AndroidLWJGLKeycode {
|
||||
private static final ArrayMap<Integer, Integer> androidToLwjglMap;
|
||||
private static String[] androidKeyNameArray;
|
||||
static {
|
||||
/*
|
||||
* There are already have mapped in
|
||||
* org.lwjgl.opengl.AndroidKeyCodes
|
||||
* but this key map is more than.
|
||||
*/
|
||||
|
||||
|
||||
// Mapping Android Keycodes to LWJGL Keycodes
|
||||
androidToLwjglMap = new ArrayMap<Integer, Integer>();
|
||||
|
||||
|
||||
@@ -52,6 +52,10 @@ public class MCProfile
|
||||
}
|
||||
|
||||
public static MCProfile.Builder parse(String content) {
|
||||
if (content == null || content.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MCProfile.Builder builder = new MCProfile.Builder();
|
||||
|
||||
String[] profileInfos = content.split(":");
|
||||
|
||||
@@ -121,17 +121,38 @@ public class PojavLauncherActivity extends BaseLauncherActivity
|
||||
|
||||
//showProfileInfo();
|
||||
|
||||
final String[] accountList = new File(Tools.mpProfiles).list();
|
||||
final List<String> accountList = new ArrayList<String>();
|
||||
final MCProfile.Builder tempProfile = PojavProfile.getTempProfileContent(this);
|
||||
if (tempProfile != null) {
|
||||
accountList.add(tempProfile.getUsername());
|
||||
}
|
||||
accountList.addAll(Arrays.asList(new File(Tools.mpProfiles).list()));
|
||||
|
||||
ArrayAdapter<String> adapterAcc = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, accountList);
|
||||
adapterAcc.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
|
||||
accountSelector = (Spinner) findViewById(R.id.launchermain_spinner_account);
|
||||
accountSelector.setAdapter(adapterAcc);
|
||||
if (tempProfile != null) {
|
||||
accountSelector.setSelection(0);
|
||||
} else {
|
||||
for (int i = 0; i < accountList.size(); i++) {
|
||||
String account = accountList.get(i);
|
||||
if (account.equals(mProfile.getUsername())) {
|
||||
accountSelector.setSelection(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
accountSelector.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> p1, View p2, int position, long p4) {
|
||||
PojavProfile.setCurrentProfile(PojavLauncherActivity.this, accountList[position]);
|
||||
if (tempProfile != null && position == 0) {
|
||||
PojavProfile.setCurrentProfile(PojavLauncherActivity.this, tempProfile);
|
||||
} else {
|
||||
PojavProfile.setCurrentProfile(PojavLauncherActivity.this, accountList.get(position + (tempProfile != null ? 1 : 0)));
|
||||
}
|
||||
finish();
|
||||
startActivity(getIntent());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,14 +7,23 @@ public class PojavProfile
|
||||
private static String PROFILE_PREF = "pojav_profile";
|
||||
private static String PROFILE_PREF_FILE = "file";
|
||||
private static String PROFILE_PREF_CONTENT = "content";
|
||||
private static String PROFILE_PREF_TEMP_CONTENT = "tempContent";
|
||||
|
||||
private static SharedPreferences getPrefs(Context ctx) {
|
||||
return ctx.getSharedPreferences(PROFILE_PREF, Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
public static MCProfile.Builder getCurrentProfileContent(Context ctx) {
|
||||
return MCProfile.parse(getPrefs(ctx).getString(PROFILE_PREF_CONTENT, ""));
|
||||
MCProfile.Builder build = MCProfile.parse(getPrefs(ctx).getString(PROFILE_PREF_CONTENT, ""));
|
||||
if (build == null) {
|
||||
getTempProfileContent(ctx);
|
||||
}
|
||||
return build;
|
||||
}
|
||||
|
||||
public static MCProfile.Builder getTempProfileContent(Context ctx) {
|
||||
return MCProfile.parse(getPrefs(ctx).getString(PROFILE_PREF_TEMP_CONTENT, ""));
|
||||
}
|
||||
|
||||
public static String getCurrentProfilePath(Context ctx) {
|
||||
return getPrefs(ctx).getString(PROFILE_PREF_FILE, "");
|
||||
@@ -25,7 +34,9 @@ public class PojavProfile
|
||||
|
||||
try {
|
||||
if (obj instanceof MCProfile.Builder) {
|
||||
pref.putString(PROFILE_PREF_CONTENT, MCProfile.toString((MCProfile.Builder) obj));
|
||||
String str = MCProfile.toString((MCProfile.Builder) obj);
|
||||
pref.putString(PROFILE_PREF_CONTENT, str);
|
||||
pref.putString(PROFILE_PREF_TEMP_CONTENT, str);
|
||||
} else if (obj instanceof String) {
|
||||
pref.putString(PROFILE_PREF_FILE, (String) obj);
|
||||
pref.putString(PROFILE_PREF_CONTENT, MCProfile.toString((String) obj));
|
||||
|
||||
@@ -3,6 +3,8 @@ package net.kdt.pojavlaunch.value.launcherprofiles;
|
||||
public class MinecraftAuthenticationDatabase
|
||||
{
|
||||
public String accessToken;
|
||||
public String displayName;
|
||||
public String username;
|
||||
public MinecraftProfile[] profiles;
|
||||
public String uuid;
|
||||
// public MinecraftProfile[] profiles;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package net.kdt.pojavlaunch.value.launcherprofiles;
|
||||
import com.google.gson.*;
|
||||
import java.util.*;
|
||||
import net.kdt.pojavlaunch.*;
|
||||
|
||||
public class MinecraftLauncherProfiles
|
||||
{
|
||||
public MinecraftProfile[] profiles;
|
||||
public Map<String, MinecraftProfile> profiles;
|
||||
public String clientToken;
|
||||
public MinecraftAuthenticationDatabase[] authenticationDatabase;
|
||||
public Map<String, MinecraftAuthenticationDatabase> authenticationDatabase;
|
||||
// public Map launcherVersion;
|
||||
public MinecraftLauncherSettings settings;
|
||||
// public Map analyticsToken;
|
||||
|
||||
@@ -21,7 +21,8 @@
|
||||
<net.kdt.pojavlaunch.MinecraftGLView
|
||||
android:id="@+id/main_game_render_view"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"/>
|
||||
android:layout_height="fill_parent"
|
||||
android:background="#00000000"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_height="match_parent"
|
||||
|
||||
Reference in New Issue
Block a user