diff --git a/AndroidCompat/getAndroid.sh b/AndroidCompat/getAndroid.sh index f1136ef9..97de7772 100755 --- a/AndroidCompat/getAndroid.sh +++ b/AndroidCompat/getAndroid.sh @@ -13,7 +13,7 @@ do which $dep >/dev/null 2>&1 || { echo >&2 "Error: This script needs $dep installed."; abort=yes; } done -if [ $abort = yes ]; then +if [ "$abort" = yes ]; then echo "Some of the dependencies didn't exist. Aborting." exit 1 fi diff --git a/AndroidCompat/src/main/java/android/widget/Toast.java b/AndroidCompat/src/main/java/android/widget/Toast.java new file mode 100644 index 00000000..603efb9b --- /dev/null +++ b/AndroidCompat/src/main/java/android/widget/Toast.java @@ -0,0 +1,91 @@ +package android.widget; + +/* + * Copyright (C) Contributors to the Suwayomi project + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +public class Toast { + public static final int LENGTH_LONG = 1; + public static final int LENGTH_SHORT = 0; + + private CharSequence text; + + private Toast(CharSequence text) { + this.text = text; + } + + public Toast(android.content.Context context) { + throw new RuntimeException("Stub!"); + } + + public void show() { + System.out.printf("made a Toast: \"%s\"\n", text.toString()); + } + + public void cancel() { + throw new RuntimeException("Stub!"); + } + + public void setView(android.view.View view) { + throw new RuntimeException("Stub!"); + } + + public android.view.View getView() { + throw new RuntimeException("Stub!"); + } + + public void setDuration(int duration) { + throw new RuntimeException("Stub!"); + } + + public int getDuration() { + throw new RuntimeException("Stub!"); + } + + public void setMargin(float horizontalMargin, float verticalMargin) { + throw new RuntimeException("Stub!"); + } + + public float getHorizontalMargin() { + throw new RuntimeException("Stub!"); + } + + public float getVerticalMargin() { + throw new RuntimeException("Stub!"); + } + + public void setGravity(int gravity, int xOffset, int yOffset) { + throw new RuntimeException("Stub!"); + } + + public int getGravity() { + throw new RuntimeException("Stub!"); + } + + public int getXOffset() { + throw new RuntimeException("Stub!"); + } + + public int getYOffset() { + throw new RuntimeException("Stub!"); + } + + public static Toast makeText(android.content.Context context, java.lang.CharSequence text, int duration) { + return new Toast(text); + } + + public static android.widget.Toast makeText(android.content.Context context, int resId, int duration) throws android.content.res.Resources.NotFoundException { + throw new RuntimeException("Stub!"); + } + + public void setText(int resId) { + throw new RuntimeException("Stub!"); + } + + public void setText(java.lang.CharSequence s) { + throw new RuntimeException("Stub!"); + } +} \ No newline at end of file diff --git a/AndroidCompat/src/main/java/xyz/nulldev/androidcompat/androidimpl/CustomContext.java b/AndroidCompat/src/main/java/xyz/nulldev/androidcompat/androidimpl/CustomContext.java index 3e51b134..4050320f 100644 --- a/AndroidCompat/src/main/java/xyz/nulldev/androidcompat/androidimpl/CustomContext.java +++ b/AndroidCompat/src/main/java/xyz/nulldev/androidcompat/androidimpl/CustomContext.java @@ -38,7 +38,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import xyz.nulldev.androidcompat.info.ApplicationInfoImpl; import xyz.nulldev.androidcompat.io.AndroidFiles; -import xyz.nulldev.androidcompat.io.sharedprefs.JavaSharedPreferences; +import xyz.nulldev.androidcompat.io.sharedprefs.JsonSharedPreferences; import xyz.nulldev.androidcompat.service.ServiceSupport; import xyz.nulldev.androidcompat.util.KodeinGlobalHelper; @@ -50,9 +50,10 @@ import java.util.Map; /** * Custom context implementation. * + * TODO Deal with packagemanager for extension sources */ public class CustomContext extends Context implements DIAware { - private final DI kodein; + private DI kodein; public CustomContext() { this(KodeinGlobalHelper.kodein()); } @@ -164,22 +165,23 @@ public class CustomContext extends Context implements DIAware { /** Fake shared prefs! **/ private Map prefs = new HashMap<>(); //Cache + private File sharedPrefsFileFromString(String s) { + return new File(androidFiles.getPrefsDir(), s + ".json"); + } + @Override public synchronized SharedPreferences getSharedPreferences(String s, int i) { SharedPreferences preferences = prefs.get(s); //Create new shared preferences if one does not exist if(preferences == null) { - preferences = new JavaSharedPreferences(s); + preferences = getSharedPreferences(sharedPrefsFileFromString(s), i); prefs.put(s, preferences); } return preferences; } - @Override - public SharedPreferences getSharedPreferences(@NotNull File file, int mode) { - String path = file.getAbsolutePath().replace('\\', '/'); - int firstSlash = path.indexOf("/"); - return new JavaSharedPreferences(path.substring(firstSlash)); + public SharedPreferences getSharedPreferences(File file, int mode) { + return new JsonSharedPreferences(file); } @Override @@ -189,8 +191,8 @@ public class CustomContext extends Context implements DIAware { @Override public boolean deleteSharedPreferences(String name) { - JavaSharedPreferences item = (JavaSharedPreferences) prefs.remove(name); - return item.deleteAll(); + prefs.remove(name); + return sharedPrefsFileFromString(name).delete(); } @Override @@ -733,4 +735,3 @@ public class CustomContext extends Context implements DIAware { } } - diff --git a/AndroidCompat/src/main/java/xyz/nulldev/androidcompat/io/AndroidFiles.kt b/AndroidCompat/src/main/java/xyz/nulldev/androidcompat/io/AndroidFiles.kt index dafa70ea..ea55b497 100644 --- a/AndroidCompat/src/main/java/xyz/nulldev/androidcompat/io/AndroidFiles.kt +++ b/AndroidCompat/src/main/java/xyz/nulldev/androidcompat/io/AndroidFiles.kt @@ -26,6 +26,8 @@ class AndroidFiles(val configManager: ConfigManager = GlobalConfigManager) { val downloadCacheDir: File get() = registerFile(filesConfig.downloadCacheDir) val databasesDir: File get() = registerFile(filesConfig.databasesDir) + val prefsDir: File get() = registerFile(filesConfig.prefsDir) + val packagesDir: File get() = registerFile(filesConfig.packageDir) fun registerFile(file: String): File { diff --git a/AndroidCompat/src/main/java/xyz/nulldev/androidcompat/io/sharedprefs/JavaSharedPreferences.kt b/AndroidCompat/src/main/java/xyz/nulldev/androidcompat/io/sharedprefs/JavaSharedPreferences.kt index 1c7f3ea8..a0c132f0 100644 --- a/AndroidCompat/src/main/java/xyz/nulldev/androidcompat/io/sharedprefs/JavaSharedPreferences.kt +++ b/AndroidCompat/src/main/java/xyz/nulldev/androidcompat/io/sharedprefs/JavaSharedPreferences.kt @@ -1,5 +1,12 @@ package xyz.nulldev.androidcompat.io.sharedprefs +/* + * Copyright (C) Contributors to the Suwayomi project + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + import android.content.SharedPreferences import com.russhwolf.settings.ExperimentalSettingsApi import com.russhwolf.settings.ExperimentalSettingsImplementation diff --git a/AndroidCompat/src/main/java/xyz/nulldev/androidcompat/io/sharedprefs/JsonSharedPreferences.java b/AndroidCompat/src/main/java/xyz/nulldev/androidcompat/io/sharedprefs/JsonSharedPreferences.java index 9b04c7b0..90703bb0 100644 --- a/AndroidCompat/src/main/java/xyz/nulldev/androidcompat/io/sharedprefs/JsonSharedPreferences.java +++ b/AndroidCompat/src/main/java/xyz/nulldev/androidcompat/io/sharedprefs/JsonSharedPreferences.java @@ -233,7 +233,7 @@ public class JsonSharedPreferences implements SharedPreferences { private JsonSharedPreferencesEditor() { } - private void recordChange(String key) { + private void recordChange(String key) { if (!affectedKeys.contains(key)) { affectedKeys.add(key); }