mirror of
https://github.com/2009scape/2009Scape-mobile.git
synced 2025-12-18 20:40:11 -07:00
Move dir
This commit is contained in:
parent
273fa6f952
commit
cadb0ab12f
313 changed files with 206 additions and 14 deletions
|
|
@ -0,0 +1,59 @@
|
|||
package net.kdt.pojavlaunch;
|
||||
import java.io.*;
|
||||
import android.content.*;
|
||||
import net.kdt.pojavlaunch.value.*;
|
||||
import com.google.gson.*;
|
||||
|
||||
public class PojavProfile
|
||||
{
|
||||
private static String PROFILE_PREF = "pojav_profile";
|
||||
private static String PROFILE_PREF_FILE = "file";
|
||||
private static String PROFILE_PREF_TEMP_CONTENT = "tempContent";
|
||||
|
||||
private static SharedPreferences getPrefs(Context ctx) {
|
||||
return ctx.getSharedPreferences(PROFILE_PREF, Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
public static MinecraftAccount getCurrentProfileContent(Context ctx) throws IOException, JsonSyntaxException {
|
||||
MinecraftAccount build = MinecraftAccount.load(getPrefs(ctx).getString(PROFILE_PREF_FILE, ""));
|
||||
if (build == null) {
|
||||
getTempProfileContent(ctx);
|
||||
}
|
||||
return build;
|
||||
}
|
||||
|
||||
public static MinecraftAccount getTempProfileContent(Context ctx) {
|
||||
return MinecraftAccount.parse(getPrefs(ctx).getString(PROFILE_PREF_TEMP_CONTENT, ""));
|
||||
}
|
||||
|
||||
public static String getCurrentProfilePath(Context ctx) {
|
||||
return getPrefs(ctx).getString(PROFILE_PREF_FILE, "");
|
||||
}
|
||||
|
||||
public static boolean setCurrentProfile(Context ctx, Object obj) {
|
||||
SharedPreferences.Editor pref = getPrefs(ctx).edit();
|
||||
|
||||
try {
|
||||
if (obj instanceof MinecraftAccount) {
|
||||
try {
|
||||
MinecraftAccount.saveTempAccount((MinecraftAccount) obj);
|
||||
} catch (IOException e) {
|
||||
Tools.showError(ctx, e);
|
||||
}
|
||||
} else if (obj instanceof String) {
|
||||
pref.putString(PROFILE_PREF_FILE, (String) obj);
|
||||
MinecraftAccount.clearTempAccount();
|
||||
} else if (obj == null) {
|
||||
pref.putString(PROFILE_PREF_FILE, "");
|
||||
} else {
|
||||
throw new IllegalArgumentException("Profile must be MinecraftAccount.class, String.class or null");
|
||||
}
|
||||
} finally {
|
||||
return pref.commit();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isFileType(Context ctx) {
|
||||
return new File(PojavProfile.getCurrentProfilePath(ctx)).exists();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue