? = null) {
+ if (BuildConfig.DEBUG) {
+ return
+ }
+ val eventProperties = JSONObject()
+ try {
+ eventProperties.put("eventAction", eventAction)
+ eventProperties.put("eventCategory", eventCategory)
+ eventProperties.put("hitType", hitType)
+ eventProperties.put("status", "displayed")
+ if (additionalData != null) {
+ for ((key, value) in additionalData) {
+ eventProperties.put(key, value)
+ }
+ }
+ } catch (exception: JSONException) {
+ }
+ Amplitude.getInstance().logEvent(eventAction, eventProperties)
+ }
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/AppConfigManager.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/AppConfigManager.kt
index 6a18d7bb3..1b9518301 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/AppConfigManager.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/AppConfigManager.kt
@@ -6,6 +6,8 @@ import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.habitrpg.android.habitica.BuildConfig
+import com.habitrpg.android.habitica.models.promotions.HabiticaPromotion
+import com.habitrpg.android.habitica.models.promotions.getHabiticaPromotionFromKey
import java.util.*
class AppConfigManager {
@@ -98,11 +100,20 @@ class AppConfigManager {
}
}
- fun reorderMenu(): Boolean {
- return remoteConfig.getBoolean("reorderMenu")
- }
-
fun enableAdventureGuide(): Boolean {
return remoteConfig.getBoolean("enableAdventureGuide")
}
+
+ fun activePromo(context: Context): HabiticaPromotion? {
+ val preferences = PreferenceManager.getDefaultSharedPreferences(context)
+ val key = preferences.getString("currentEvent", null)
+ if (key?.isNotBlank() == true) {
+ val startDateLong = preferences.getLong("currentEventStartDate", 0)
+ val startDate = if (startDateLong > 0) Date(startDateLong) else null
+ val endDateLong = preferences.getLong("currentEventEndDate", 0)
+ val endDate = if (endDateLong > 0) Date(endDateLong) else null
+ return getHabiticaPromotionFromKey(key, startDate, endDate)
+ }
+ return null
+ }
}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/DeviceName.java b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/DeviceName.java
deleted file mode 100644
index 1cd8c302a..000000000
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/DeviceName.java
+++ /dev/null
@@ -1,1060 +0,0 @@
-package com.habitrpg.android.habitica.helpers;
-
-/*
- * Copyright (C) 2017 Jared Rummler
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import android.Manifest;
-import android.annotation.SuppressLint;
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.content.pm.PackageManager;
-import android.net.ConnectivityManager;
-import android.net.NetworkInfo;
-import android.os.Build;
-import android.os.Handler;
-import android.os.Looper;
-import android.text.TextUtils;
-
-import androidx.annotation.WorkerThread;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.util.Locale;
-
-// @formatter:off
-/**
- * Get the consumer friendly name of an Android device.
- *
- * On many popular devices the market name of the device is not available. For example, on the
- * Samsung Galaxy S6 the value of {@link Build#MODEL} could be "SM-G920F", "SM-G920I", "SM-G920W8",
- * etc.
- *
- * See the usages below to get the consumer friends name of a device:
- *
- * Get the name of the current device:
- *
- *
- * String deviceName = DeviceName.getDeviceName();
- *
- *
- * The above code will get the correct device name for the top 600 Android devices. If the
- * device is unrecognized, then Build.MODEL is returned.
- *
- * Get the name of a device using the device's codename:
- *
- *
- * // Retruns "Moto X Style"
- * DeviceName.getDeviceName("clark", "Unknown device");
- *
- *
- * Get information about the device:
- *
- *
- * DeviceName.with(context).request(new DeviceName.Callback() {
- *
- * @Override public void onFinished(DeviceName.DeviceInfo info, Exception error) {
- * String manufacturer = info.manufacturer; // "Samsung"
- * String name = info.marketName; // "Galaxy S6 Edge"
- * String model = info.model; // "SM-G925I"
- * String codename = info.codename; // "zerolte"
- * String deviceName = info.getName(); // "Galaxy S6 Edge"
- * // FYI: We are on the UI thread.
- * }
- * });
- *
- *
- * The above code loads JSON from a generated list of device names based on Google's maintained
- * list. It will be up-to-date with Google's supported device list so that you will get the correct
- * name for new or unknown devices. This supports over 10,000 devices.
- *
- * This will only make a network call once. The value is saved to SharedPreferences for future
- * calls.
- */
-public class DeviceName {
- // @formatter:on
-
- // JSON which is derived from Google's PDF document which contains all devices on Google Play.
- // To get the URL to the JSON file which contains information about the device name:
- // String url = String.format(DEVICE_JSON_URL, Build.DEVICE);
- private static final String DEVICE_JSON_URL =
- "https://raw.githubusercontent.com/jaredrummler/AndroidDeviceNames/master/json/devices/%s.json";
-
- // Preference filename for storing device info so we don't need to download it again.
- private static final String SHARED_PREF_NAME = "device_names";
-
- /**
- * Create a new request to get information about a device.
- *
- * @param context the application context
- * @return a new Request instance.
- */
- public static Request with(Context context) {
- return new Request(context.getApplicationContext());
- }
-
- /**
- * Get the consumer friendly name of the device.
- *
- * @return the market name of the current device.
- * @see #getDeviceName(String, String)
- */
- public static String getDeviceName() {
- return getDeviceName(Build.DEVICE, Build.MODEL, capitalize(Build.MODEL));
- }
-
- /**
- * Get the consumer friendly name of a device.
- *
- * @param codename the value of the system property "ro.product.device" ({@link Build#DEVICE})
- * or
- * the value of the system property "ro.product.model" ({@link Build#MODEL})
- * @param fallback the fallback name if the device is unknown. Usually the value of the system property
- * "ro.product.model" ({@link Build#MODEL})
- * @return the market name of a device or {@code fallback} if the device is unknown.
- */
- public static String getDeviceName(String codename, String fallback) {
- return getDeviceName(codename, codename, fallback);
- }
-
- /**
- * Get the consumer friendly name of a device.
- *
- * @param codename the value of the system property "ro.product.device" ({@link Build#DEVICE}).
- * @param model the value of the system property "ro.product.model" ({@link Build#MODEL}).
- * @param fallback the fallback name if the device is unknown. Usually the value of the system property
- * "ro.product.model" ({@link Build#MODEL})
- * @return the market name of a device or {@code fallback} if the device is unknown.
- */
- public static String getDeviceName(String codename, String model, String fallback) {
- // ----------------------------------------------------------------------------
- // Google
- if ((codename != null && codename.equals("walleye"))) {
- return "Pixel 2";
- }
- if ((codename != null && codename.equals("taimen"))) {
- return "Pixel 2 XL";
- }
- if ((codename != null && codename.equals("blueline"))) {
- return "Pixel 3";
- }
- if ((codename != null && codename.equals("crosshatch"))) {
- return "Pixel 3 XL";
- }
- if ((codename != null && codename.equals("sargo"))) {
- return "Pixel 3a";
- }
- if ((codename != null && codename.equals("bonito"))) {
- return "Pixel 3a XL";
- }
- // ----------------------------------------------------------------------------
- // Huawei
- if ((codename != null && (codename.equals("HWBND-H"))) || (model != null && (model.equals("BND-L21")
- || model.equals("BND-L24")
- || model.equals("BND-L31")))) {
- return "Honor 7X";
- }
- if ((codename != null && (codename.equals("HWBKL"))) || (model != null && (model.equals("BKL-L04") || model.equals(
- "BKL-L09")))) {
- return "Honor View 10";
- }
- if ((codename != null && (codename.equals("HWALP"))) || (model != null && (model.equals("ALP-AL00") || model.equals(
- "ALP-L09") || model.equals("ALP-L29") || model.equals("ALP-TL00")))) {
- return "Mate 10";
- }
- if ((codename != null && (codename.equals("HWMHA"))) || (model != null && (model.equals("MHA-AL00") || model.equals(
- "MHA-L09") || model.equals("MHA-L29") || model.equals("MHA-TL00")))) {
- return "Mate 9";
- }
- if ((codename != null && codename.equals("angler"))) {
- return "Nexus 6P";
- }
- // ----------------------------------------------------------------------------
- // LGE
- if ((codename != null && (codename.equals("h1"))) || (model != null && (model.equals("LG-F700K") || model.equals(
- "LG-F700L") || model.equals("LG-F700S") || model.equals("LG-H820") || model.equals("LG-H820PR") || model.equals(
- "LG-H830") || model.equals("LG-H831") || model.equals("LG-H850") || model.equals("LG-H858") || model.equals(
- "LG-H860") || model.equals("LG-H868") || model.equals("LGAS992") || model.equals("LGLS992") || model.equals(
- "LGUS992") || model.equals("RS988") || model.equals("VS987")))) {
- return "LG G5";
- }
- if ((codename != null && (codename.equals("lucye"))) || (model != null && (model.equals("LG-AS993")
- || model.equals("LG-H870")
- || model.equals("LG-H870AR")
- || model.equals("LG-H870DS")
- || model.equals("LG-H870I")
- || model.equals("LG-H870S")
- || model.equals("LG-H871")
- || model.equals("LG-H871S")
- || model.equals("LG-H872")
- || model.equals("LG-H872PR")
- || model.equals("LG-H873")
- || model.equals("LG-LS993")
- || model.equals("LGM-G600K")
- || model.equals("LGM-G600L")
- || model.equals("LGM-G600S")
- || model.equals("LGUS997")
- || model.equals("VS988")))) {
- return "LG G6";
- }
- if ((codename != null && (codename.equals("flashlmdd"))) || (model != null && (model.equals("LM-V500")
- || model.equals("LM-V500N")))) {
- return "LG V50 ThinQ";
- }
- if ((codename != null && codename.equals("mako"))) {
- return "Nexus 4";
- }
- if ((codename != null && codename.equals("hammerhead"))) {
- return "Nexus 5";
- }
- if ((codename != null && codename.equals("bullhead"))) {
- return "Nexus 5X";
- }
- // ----------------------------------------------------------------------------
- // Motorola
- if ((codename != null && (codename.equals("griffin"))) || (model != null && (model.equals("XT1650") || model.equals(
- "XT1650-05")))) {
- return "Moto Z";
- }
- if ((codename != null && codename.equals("shamu"))) {
- return "Nexus 6";
- }
- // ----------------------------------------------------------------------------
- // Nokia
- if ((codename != null && (codename.equals("RHD")
- || codename.equals("ROO")
- || codename.equals("ROON_sprout")
- || codename.equals("ROO_sprout")))) {
- return "Nokia 3.1 Plus";
- }
- if ((codename != null && codename.equals("CTL_sprout"))) {
- return "Nokia 7.1";
- }
- // ----------------------------------------------------------------------------
- // OnePlus
- if ((codename != null && codename.equals("OnePlus6")) || (model != null && model.equals("ONEPLUS A6003"))) {
- return "OnePlus 6";
- }
- if ((codename != null && (codename.equals("OnePlus6T") || codename.equals("OnePlus6TSingle"))) || (model != null
- && (model.equals("ONEPLUS A6013")))) {
- return "OnePlus 6T";
- }
- if ((codename != null && codename.equals("OnePlus7")) || (model != null && model.equals("GM1905"))) {
- return "OnePlus 7";
- }
- if ((codename != null && (codename.equals("OnePlus7Pro") || codename.equals("OnePlus7ProTMO"))) || (model != null
- && (model.equals("GM1915") || model.equals("GM1917")))) {
- return "OnePlus 7 Pro";
- }
- // ----------------------------------------------------------------------------
- // Samsung
- if ((codename != null && (codename.equals("a50"))) || (model != null && (model.equals("SM-A505F")
- || model.equals("SM-A505FM")
- || model.equals("SM-A505FN")
- || model.equals("SM-A505G")
- || model.equals("SM-A505GN")
- || model.equals("SM-A505GT")
- || model.equals("SM-A505N")
- || model.equals("SM-A505U")
- || model.equals("SM-A505W")
- || model.equals("SM-A505YN")))) {
- return "Galaxy A50";
- }
- if ((codename != null && (codename.equals("a6elteaio")
- || codename.equals("a6elteatt")
- || codename.equals("a6eltemtr")
- || codename.equals("a6eltespr")
- || codename.equals("a6eltetmo")
- || codename.equals("a6elteue")
- || codename.equals("a6lte")
- || codename.equals("a6lteks"))) || (model != null && (model.equals("SM-A600A")
- || model.equals("SM-A600AZ")
- || model.equals("SM-A600F")
- || model.equals("SM-A600FN")
- || model.equals("SM-A600G")
- || model.equals("SM-A600GN")
- || model.equals("SM-A600N")
- || model.equals("SM-A600P")
- || model.equals("SM-A600T")
- || model.equals("SM-A600T1")
- || model.equals("SM-A600U")))) {
- return "Galaxy A6";
- }
- if ((codename != null && (codename.equals("SC-01J")
- || codename.equals("SCV34")
- || codename.equals("gracelte")
- || codename.equals("graceltektt")
- || codename.equals("graceltelgt")
- || codename.equals("gracelteskt")
- || codename.equals("graceqlteacg")
- || codename.equals("graceqlteatt")
- || codename.equals("graceqltebmc")
- || codename.equals("graceqltechn")
- || codename.equals("graceqltedcm")
- || codename.equals("graceqltelra")
- || codename.equals("graceqltespr")
- || codename.equals("graceqltetfnvzw")
- || codename.equals("graceqltetmo")
- || codename.equals("graceqlteue")
- || codename.equals("graceqlteusc")
- || codename.equals("graceqltevzw"))) || (model != null && (model.equals("SAMSUNG-SM-N930A")
- || model.equals("SC-01J")
- || model.equals("SCV34")
- || model.equals("SGH-N037")
- || model.equals("SM-N9300")
- || model.equals("SM-N930F")
- || model.equals("SM-N930K")
- || model.equals("SM-N930L")
- || model.equals("SM-N930P")
- || model.equals("SM-N930R4")
- || model.equals("SM-N930R6")
- || model.equals("SM-N930R7")
- || model.equals("SM-N930S")
- || model.equals("SM-N930T")
- || model.equals("SM-N930U")
- || model.equals("SM-N930V")
- || model.equals("SM-N930VL")
- || model.equals("SM-N930W8")
- || model.equals("SM-N930X")))) {
- return "Galaxy Note7";
- }
- if ((codename != null && (codename.equals("SC-01K")
- || codename.equals("SCV37")
- || codename.equals("greatlte")
- || codename.equals("greatlteks")
- || codename.equals("greatqlte")
- || codename.equals("greatqltechn")
- || codename.equals("greatqltecmcc")
- || codename.equals("greatqltecs")
- || codename.equals("greatqlteue"))) || (model != null && (model.equals("SC-01K")
- || model.equals("SCV37")
- || model.equals("SM-N9500")
- || model.equals("SM-N9508")
- || model.equals("SM-N950F")
- || model.equals("SM-N950N")
- || model.equals("SM-N950U")
- || model.equals("SM-N950U1")
- || model.equals("SM-N950W")
- || model.equals("SM-N950XN")))) {
- return "Galaxy Note8";
- }
- if ((codename != null && (codename.equals("SC-01L")
- || codename.equals("SCV40")
- || codename.equals("crownlte")
- || codename.equals("crownlteks")
- || codename.equals("crownqltechn")
- || codename.equals("crownqltecs")
- || codename.equals("crownqltesq")
- || codename.equals("crownqlteue"))) || (model != null && (model.equals("SC-01L")
- || model.equals("SCV40")
- || model.equals("SM-N9600")
- || model.equals("SM-N960F")
- || model.equals("SM-N960N")
- || model.equals("SM-N960U")
- || model.equals("SM-N960U1")
- || model.equals("SM-N960W")))) {
- return "Galaxy Note9";
- }
- if ((codename != null && (codename.equals("SC-03L")
- || codename.equals("SCV41")
- || codename.equals("beyond1")
- || codename.equals("beyond1q"))) || (model != null && (model.equals("SC-03L")
- || model.equals("SCV41")
- || model.equals("SM-G9730")
- || model.equals("SM-G9738")
- || model.equals("SM-G973F")
- || model.equals("SM-G973N")
- || model.equals("SM-G973U")
- || model.equals("SM-G973U1")
- || model.equals("SM-G973W")))) {
- return "Galaxy S10";
- }
- if ((codename != null && (codename.equals("SC-04L")
- || codename.equals("SCV42")
- || codename.equals("beyond2")
- || codename.equals("beyond2q"))) || (model != null && (model.equals("SC-04L")
- || model.equals("SCV42")
- || model.equals("SM-G9750")
- || model.equals("SM-G9758")
- || model.equals("SM-G975F")
- || model.equals("SM-G975N")
- || model.equals("SM-G975U")
- || model.equals("SM-G975U1")
- || model.equals("SM-G975W")))) {
- return "Galaxy S10+";
- }
- if ((codename != null && (codename.equals("beyond0") || codename.equals("beyond0q"))) || (model != null
- && (model.equals("SM-G9700")
- || model.equals("SM-G9708")
- || model.equals("SM-G970F")
- || model.equals("SM-G970N")
- || model.equals("SM-G970U")
- || model.equals("SM-G970U1")
- || model.equals("SM-G970W")))) {
- return "Galaxy S10e";
- }
- if ((codename != null && (codename.equals("SC-04F")
- || codename.equals("SCL23")
- || codename.equals("k3g")
- || codename.equals("klte")
- || codename.equals("klteMetroPCS")
- || codename.equals("klteacg")
- || codename.equals("klteaio")
- || codename.equals("klteatt")
- || codename.equals("kltecan")
- || codename.equals("klteduoszn")
- || codename.equals("kltektt")
- || codename.equals("kltelgt")
- || codename.equals("kltelra")
- || codename.equals("klteskt")
- || codename.equals("kltespr")
- || codename.equals("kltetfnvzw")
- || codename.equals("kltetmo")
- || codename.equals("klteusc")
- || codename.equals("kltevzw")
- || codename.equals("kwifi")
- || codename.equals("lentisltektt")
- || codename.equals("lentisltelgt")
- || codename.equals("lentislteskt"))) || (model != null && (model.equals("SAMSUNG-SM-G900A")
- || model.equals("SAMSUNG-SM-G900AZ")
- || model.equals("SC-04F")
- || model.equals("SCL23")
- || model.equals("SM-G9006W")
- || model.equals("SM-G9008W")
- || model.equals("SM-G9009W")
- || model.equals("SM-G900F")
- || model.equals("SM-G900FQ")
- || model.equals("SM-G900H")
- || model.equals("SM-G900I")
- || model.equals("SM-G900K")
- || model.equals("SM-G900L")
- || model.equals("SM-G900M")
- || model.equals("SM-G900MD")
- || model.equals("SM-G900P")
- || model.equals("SM-G900R4")
- || model.equals("SM-G900R6")
- || model.equals("SM-G900R7")
- || model.equals("SM-G900S")
- || model.equals("SM-G900T")
- || model.equals("SM-G900T1")
- || model.equals("SM-G900T3")
- || model.equals("SM-G900T4")
- || model.equals("SM-G900V")
- || model.equals("SM-G900W8")
- || model.equals("SM-G900X")
- || model.equals("SM-G906K")
- || model.equals("SM-G906L")
- || model.equals("SM-G906S")
- || model.equals("SM-S903VL")))) {
- return "Galaxy S5";
- }
- if ((codename != null && (codename.equals("s5neolte") || codename.equals("s5neoltecan"))) || (model != null && (
- model.equals("SM-G903F")
- || model.equals("SM-G903M")
- || model.equals("SM-G903W")))) {
- return "Galaxy S5 Neo";
- }
- if ((codename != null && (codename.equals("SC-05G")
- || codename.equals("zeroflte")
- || codename.equals("zeroflteacg")
- || codename.equals("zeroflteaio")
- || codename.equals("zeroflteatt")
- || codename.equals("zerofltebmc")
- || codename.equals("zerofltechn")
- || codename.equals("zerofltectc")
- || codename.equals("zerofltektt")
- || codename.equals("zerofltelgt")
- || codename.equals("zerofltelra")
- || codename.equals("zerofltemtr")
- || codename.equals("zeroflteskt")
- || codename.equals("zerofltespr")
- || codename.equals("zerofltetfnvzw")
- || codename.equals("zerofltetmo")
- || codename.equals("zeroflteusc")
- || codename.equals("zerofltevzw"))) || (model != null && (model.equals("SAMSUNG-SM-G920A")
- || model.equals("SAMSUNG-SM-G920AZ")
- || model.equals("SC-05G")
- || model.equals("SM-G9200")
- || model.equals("SM-G9208")
- || model.equals("SM-G9209")
- || model.equals("SM-G920F")
- || model.equals("SM-G920I")
- || model.equals("SM-G920K")
- || model.equals("SM-G920L")
- || model.equals("SM-G920P")
- || model.equals("SM-G920R4")
- || model.equals("SM-G920R6")
- || model.equals("SM-G920R7")
- || model.equals("SM-G920S")
- || model.equals("SM-G920T")
- || model.equals("SM-G920T1")
- || model.equals("SM-G920V")
- || model.equals("SM-G920W8")
- || model.equals("SM-G920X")
- || model.equals("SM-S906L")
- || model.equals("SM-S907VL")))) {
- return "Galaxy S6";
- }
- if ((codename != null && (codename.equals("404SC")
- || codename.equals("SC-04G")
- || codename.equals("SCV31")
- || codename.equals("zerolte")
- || codename.equals("zerolteacg")
- || codename.equals("zerolteatt")
- || codename.equals("zeroltebmc")
- || codename.equals("zeroltechn")
- || codename.equals("zeroltektt")
- || codename.equals("zeroltelra")
- || codename.equals("zerolteskt")
- || codename.equals("zeroltespr")
- || codename.equals("zeroltetmo")
- || codename.equals("zerolteusc")
- || codename.equals("zeroltevzw"))) || (model != null && (model.equals("404SC")
- || model.equals("SAMSUNG-SM-G925A")
- || model.equals("SC-04G")
- || model.equals("SCV31")
- || model.equals("SM-G9250")
- || model.equals("SM-G925I")
- || model.equals("SM-G925K")
- || model.equals("SM-G925P")
- || model.equals("SM-G925R4")
- || model.equals("SM-G925R6")
- || model.equals("SM-G925R7")
- || model.equals("SM-G925S")
- || model.equals("SM-G925T")
- || model.equals("SM-G925V")
- || model.equals("SM-G925W8")
- || model.equals("SM-G925X")))) {
- return "Galaxy S6 Edge";
- }
- if ((codename != null && (codename.equals("zenlte")
- || codename.equals("zenlteatt")
- || codename.equals("zenltebmc")
- || codename.equals("zenltechn")
- || codename.equals("zenltektt")
- || codename.equals("zenltekx")
- || codename.equals("zenltelgt")
- || codename.equals("zenlteskt")
- || codename.equals("zenltespr")
- || codename.equals("zenltetmo")
- || codename.equals("zenlteusc")
- || codename.equals("zenltevzw"))) || (model != null && (model.equals("SAMSUNG-SM-G928A")
- || model.equals("SM-G9280")
- || model.equals("SM-G9287C")
- || model.equals("SM-G928C")
- || model.equals("SM-G928G")
- || model.equals("SM-G928I")
- || model.equals("SM-G928K")
- || model.equals("SM-G928L")
- || model.equals("SM-G928N0")
- || model.equals("SM-G928P")
- || model.equals("SM-G928R4")
- || model.equals("SM-G928S")
- || model.equals("SM-G928T")
- || model.equals("SM-G928V")
- || model.equals("SM-G928W8")
- || model.equals("SM-G928X")))) {
- return "Galaxy S6 Edge+";
- }
- if ((codename != null && (codename.equals("herolte") || codename.equals("heroltebmc") || codename.equals(
- "heroltektt") || codename.equals("heroltelgt") || codename.equals("herolteskt") || codename.equals(
- "heroqlteacg") || codename.equals("heroqlteaio") || codename.equals("heroqlteatt") || codename.equals(
- "heroqltecctvzw") || codename.equals("heroqltechn") || codename.equals("heroqltelra") || codename.equals(
- "heroqltemtr") || codename.equals("heroqltespr") || codename.equals("heroqltetfnvzw") || codename.equals(
- "heroqltetmo") || codename.equals("heroqlteue") || codename.equals("heroqlteusc") || codename.equals(
- "heroqltevzw"))) || (model != null && (model.equals("SAMSUNG-SM-G930A")
- || model.equals("SAMSUNG-SM-G930AZ")
- || model.equals("SM-G9300")
- || model.equals("SM-G9308")
- || model.equals("SM-G930F")
- || model.equals("SM-G930K")
- || model.equals("SM-G930L")
- || model.equals("SM-G930P")
- || model.equals("SM-G930R4")
- || model.equals("SM-G930R6")
- || model.equals("SM-G930R7")
- || model.equals("SM-G930S")
- || model.equals("SM-G930T")
- || model.equals("SM-G930T1")
- || model.equals("SM-G930U")
- || model.equals("SM-G930V")
- || model.equals("SM-G930VC")
- || model.equals("SM-G930VL")
- || model.equals("SM-G930W8")
- || model.equals("SM-G930X")))) {
- return "Galaxy S7";
- }
- if ((codename != null && (codename.equals("SC-02H")
- || codename.equals("SCV33")
- || codename.equals("hero2lte")
- || codename.equals("hero2ltebmc")
- || codename.equals("hero2ltektt")
- || codename.equals("hero2lteskt")
- || codename.equals("hero2qlteatt")
- || codename.equals("hero2qltecctvzw")
- || codename.equals("hero2qltespr")
- || codename.equals("hero2qltetmo")
- || codename.equals("hero2qlteusc")
- || codename.equals("hero2qltevzw"))) || (model != null && (model.equals("SAMSUNG-SM-G935A")
- || model.equals("SC-02H")
- || model.equals("SCV33")
- || model.equals("SM-G935K")
- || model.equals("SM-G935P")
- || model.equals("SM-G935R4")
- || model.equals("SM-G935S")
- || model.equals("SM-G935T")
- || model.equals("SM-G935V")
- || model.equals("SM-G935VC")
- || model.equals("SM-G935W8")
- || model.equals("SM-G935X")))) {
- return "Galaxy S7 Edge";
- }
- if ((codename != null && (codename.equals("SC-02J")
- || codename.equals("SCV36")
- || codename.equals("dreamlte")
- || codename.equals("dreamlteks")
- || codename.equals("dreamqltecan")
- || codename.equals("dreamqltechn")
- || codename.equals("dreamqltecmcc")
- || codename.equals("dreamqltesq")
- || codename.equals("dreamqlteue"))) || (model != null && (model.equals("SC-02J")
- || model.equals("SCV36")
- || model.equals("SM-G9500")
- || model.equals("SM-G9508")
- || model.equals("SM-G950F")
- || model.equals("SM-G950N")
- || model.equals("SM-G950U")
- || model.equals("SM-G950U1")
- || model.equals("SM-G950W")))) {
- return "Galaxy S8";
- }
- if ((codename != null && (codename.equals("SC-03J")
- || codename.equals("SCV35")
- || codename.equals("dream2lte")
- || codename.equals("dream2lteks")
- || codename.equals("dream2qltecan")
- || codename.equals("dream2qltechn")
- || codename.equals("dream2qltesq")
- || codename.equals("dream2qlteue"))) || (model != null && (model.equals("SC-03J")
- || model.equals("SCV35")
- || model.equals("SM-G9550")
- || model.equals("SM-G955F")
- || model.equals("SM-G955N")
- || model.equals("SM-G955U")
- || model.equals("SM-G955U1")
- || model.equals("SM-G955W")))) {
- return "Galaxy S8+";
- }
- if ((codename != null && (codename.equals("SC-02K")
- || codename.equals("SCV38")
- || codename.equals("starlte")
- || codename.equals("starlteks")
- || codename.equals("starqltechn")
- || codename.equals("starqltecmcc")
- || codename.equals("starqltecs")
- || codename.equals("starqltesq")
- || codename.equals("starqlteue"))) || (model != null && (model.equals("SC-02K")
- || model.equals("SCV38")
- || model.equals("SM-G9600")
- || model.equals("SM-G9608")
- || model.equals("SM-G960F")
- || model.equals("SM-G960N")
- || model.equals("SM-G960U")
- || model.equals("SM-G960U1")
- || model.equals("SM-G960W")))) {
- return "Galaxy S9";
- }
- if ((codename != null && (codename.equals("SC-03K")
- || codename.equals("SCV39")
- || codename.equals("star2lte")
- || codename.equals("star2lteks")
- || codename.equals("star2qltechn")
- || codename.equals("star2qltecs")
- || codename.equals("star2qltesq")
- || codename.equals("star2qlteue"))) || (model != null && (model.equals("SC-03K")
- || model.equals("SCV39")
- || model.equals("SM-G9650")
- || model.equals("SM-G965F")
- || model.equals("SM-G965N")
- || model.equals("SM-G965U")
- || model.equals("SM-G965U1")
- || model.equals("SM-G965W")))) {
- return "Galaxy S9+";
- }
- // ----------------------------------------------------------------------------
- // Sony
- if ((codename != null && (codename.equals("802SO")
- || codename.equals("J8110")
- || codename.equals("J8170")
- || codename.equals("J9110")
- || codename.equals("SO-03L")
- || codename.equals("SOV40"))) || (model != null && (model.equals("802SO")
- || model.equals("J8110")
- || model.equals("J8170")
- || model.equals("J9110")
- || model.equals("SO-03L")
- || model.equals("SOV40")))) {
- return "Xperia 1";
- }
- if ((codename != null && (codename.equals("I3113")
- || codename.equals("I3123")
- || codename.equals("I4113")
- || codename.equals("I4193"))) || (model != null && (model.equals("I3113")
- || model.equals("I3123")
- || model.equals("I4113")
- || model.equals("I4193")))) {
- return "Xperia 10";
- }
- if ((codename != null && (codename.equals("I3213")
- || codename.equals("I3223")
- || codename.equals("I4213")
- || codename.equals("I4293"))) || (model != null && (model.equals("I3213")
- || model.equals("I3223")
- || model.equals("I4213")
- || model.equals("I4293")))) {
- return "Xperia 10 Plus";
- }
- if ((codename != null && (codename.equals("702SO")
- || codename.equals("H8216")
- || codename.equals("H8266")
- || codename.equals("H8276")
- || codename.equals("H8296")
- || codename.equals("SO-03K")
- || codename.equals("SOV37"))) || (model != null && (model.equals("702SO")
- || model.equals("H8216")
- || model.equals("H8266")
- || model.equals("H8276")
- || model.equals("H8296")
- || model.equals("SO-03K")
- || model.equals("SOV37")))) {
- return "Xperia XZ2";
- }
- if ((codename != null && (codename.equals("H8116")
- || codename.equals("H8166")
- || codename.equals("SO-04K")
- || codename.equals("SOV38"))) || (model != null && (model.equals("H8116")
- || model.equals("H8166")
- || model.equals("SO-04K")
- || model.equals("SOV38")))) {
- return "Xperia XZ2 Premium";
- }
- if ((codename != null && (codename.equals("801SO")
- || codename.equals("H8416")
- || codename.equals("H9436")
- || codename.equals("H9493")
- || codename.equals("SO-01L")
- || codename.equals("SOV39"))) || (model != null && (model.equals("801SO")
- || model.equals("H8416")
- || model.equals("H9436")
- || model.equals("H9493")
- || model.equals("SO-01L")
- || model.equals("SOV39")))) {
- return "Xperia XZ3";
- }
- return fallback;
- }
-
- /**
- * Get the {@link DeviceInfo} for the current device. Do not run on the UI thread, as this may
- * download JSON to retrieve the {@link DeviceInfo}. JSON is only downloaded once and then
- * stored to {@link SharedPreferences}.
- *
- * @param context the application context.
- * @return {@link DeviceInfo} for the current device.
- */
- @WorkerThread public static DeviceInfo getDeviceInfo(Context context) {
- return getDeviceInfo(context.getApplicationContext(), Build.DEVICE, Build.MODEL);
- }
-
- /**
- * Get the {@link DeviceInfo} for the current device. Do not run on the UI thread, as this may
- * download JSON to retrieve the {@link DeviceInfo}. JSON is only downloaded once and then
- * stored to {@link SharedPreferences}.
- *
- * @param context the application context.
- * @param codename the codename of the device
- * @return {@link DeviceInfo} for the current device.
- */
- @WorkerThread public static DeviceInfo getDeviceInfo(Context context, String codename) {
- return getDeviceInfo(context, codename, null);
- }
-
- /**
- * Get the {@link DeviceInfo} for the current device. Do not run on the UI thread, as this may
- * download JSON to retrieve the {@link DeviceInfo}. JSON is only downloaded once and then
- * stored to {@link SharedPreferences}.
- *
- * @param context the application context.
- * @param codename the codename of the device
- * @param model the model of the device
- * @return {@link DeviceInfo} for the current device.
- */
- @WorkerThread public static DeviceInfo getDeviceInfo(Context context, String codename, String model) {
- SharedPreferences prefs = context.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
- String key = String.format("%s:%s", codename, model);
- String savedJson = prefs.getString(key, null);
- if (savedJson != null) {
- try {
- return new DeviceInfo(new JSONObject(savedJson));
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
-
- // check if we have an internet connection
- int ret = context.checkCallingOrSelfPermission(Manifest.permission.ACCESS_NETWORK_STATE);
- boolean isConnectedToNetwork = false;
- if (ret == PackageManager.PERMISSION_GRANTED) {
- ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
- @SuppressLint("MissingPermission") NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
- if (networkInfo != null && networkInfo.isConnected()) {
- isConnectedToNetwork = true;
- }
- } else {
- // assume we are connected.
- isConnectedToNetwork = true;
- }
-
- if (isConnectedToNetwork) {
- try {
- // Get the device name from the generated JSON files created from Google's device list.
- String url = String.format(DEVICE_JSON_URL, codename.toLowerCase(Locale.ENGLISH));
- String jsonString = downloadJson(url);
- JSONArray jsonArray = new JSONArray(jsonString);
- for (int i = 0, len = jsonArray.length(); i < len; i++) {
- JSONObject json = jsonArray.getJSONObject(i);
- DeviceInfo info = new DeviceInfo(json);
- if ((codename.equalsIgnoreCase(info.codename) && model == null)
- || codename.equalsIgnoreCase(info.codename) && model.equalsIgnoreCase(info.model)) {
- // Save to SharedPreferences so we don't need to make another request.
- SharedPreferences.Editor editor = prefs.edit();
- editor.putString(key, json.toString());
- editor.apply();
- return info;
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- if (codename.equals(Build.DEVICE) && Build.MODEL.equals(model)) {
- return new DeviceInfo(Build.MANUFACTURER, getDeviceName(), codename, model); // current device
- }
-
- return new DeviceInfo(null, null, codename, model); // unknown device
- }
-
- /**
- * Capitalizes getAllProcesses the whitespace separated words in a String. Only the first
- * letter of each word is changed.
- *
- * Whitespace is defined by {@link Character#isWhitespace(char)}.
- *
- * @param str the String to capitalize
- * @return capitalized The capitalized String
- */
- private static String capitalize(String str) {
- if (TextUtils.isEmpty(str)) {
- return str;
- }
- char[] arr = str.toCharArray();
- boolean capitalizeNext = true;
- String phrase = "";
- for (char c : arr) {
- if (capitalizeNext && Character.isLetter(c)) {
- phrase += Character.toUpperCase(c);
- capitalizeNext = false;
- continue;
- } else if (Character.isWhitespace(c)) {
- capitalizeNext = true;
- }
- phrase += c;
- }
- return phrase;
- }
-
- /** Download URL to String */
- @WorkerThread private static String downloadJson(String myurl) throws IOException {
- StringBuilder sb = new StringBuilder();
- BufferedReader reader = null;
- try {
- URL url = new URL(myurl);
- HttpURLConnection conn = (HttpURLConnection) url.openConnection();
- conn.setReadTimeout(10000);
- conn.setConnectTimeout(15000);
- conn.setRequestMethod("GET");
- conn.setDoInput(true);
- conn.connect();
- if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
- reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
- String line;
- while ((line = reader.readLine()) != null) {
- sb.append(line).append('\n');
- }
- }
- return sb.toString();
- } finally {
- if (reader != null) {
- reader.close();
- }
- }
- }
-
- public static final class Request {
-
- final Context context;
- final Handler handler;
- String codename;
- String model;
-
- private Request(Context ctx) {
- context = ctx;
- handler = new Handler(ctx.getMainLooper());
- }
-
- /**
- * Set the device codename to query. You should also set the model.
- *
- * @param codename the value of the system property "ro.product.device"
- * @return This Request object to allow for chaining of calls to set methods.
- * @see Build#DEVICE
- */
- public Request setCodename(String codename) {
- this.codename = codename;
- return this;
- }
-
- /**
- * Set the device model to query. You should also set the codename.
- *
- * @param model the value of the system property "ro.product.model"
- * @return This Request object to allow for chaining of calls to set methods.
- * @see Build#MODEL
- */
- public Request setModel(String model) {
- this.model = model;
- return this;
- }
-
- /**
- * Download information about the device. This saves the results in shared-preferences so
- * future requests will not need a network connection.
- *
- * @param callback the callback to retrieve the {@link DeviceName.DeviceInfo}
- */
- public void request(Callback callback) {
- if (codename == null && model == null) {
- codename = Build.DEVICE;
- model = Build.MODEL;
- }
- GetDeviceRunnable runnable = new GetDeviceRunnable(callback);
- if (Looper.myLooper() == Looper.getMainLooper()) {
- new Thread(runnable).start();
- } else {
- runnable.run(); // already running in background thread.
- }
- }
-
- private final class GetDeviceRunnable implements Runnable {
-
- final Callback callback;
- DeviceInfo deviceInfo;
- Exception error;
-
- public GetDeviceRunnable(Callback callback) {
- this.callback = callback;
- }
-
- @Override public void run() {
- try {
- deviceInfo = getDeviceInfo(context, codename, model);
- } catch (Exception e) {
- error = e;
- }
- handler.post(new Runnable() {
-
- @Override public void run() {
- callback.onFinished(deviceInfo, error);
- }
- });
- }
- }
- }
-
- /**
- * Callback which is invoked when the {@link DeviceName.DeviceInfo} is finished loading.
- */
- public interface Callback {
-
- /**
- * Callback to get the device info. This is run on the UI thread.
- *
- * @param info the requested {@link DeviceName.DeviceInfo}
- * @param error {@code null} if nothing went wrong.
- */
- void onFinished(DeviceInfo info, Exception error);
- }
-
- /**
- * Device information based on
- * Google's maintained list.
- */
- public static final class DeviceInfo {
-
- /** Retail branding */
- public final String manufacturer;
-
- /** Marketing name */
- public final String marketName;
-
- /** the value of the system property "ro.product.device" */
- public final String codename;
-
- /** the value of the system property "ro.product.model" */
- public final String model;
-
- public DeviceInfo(String manufacturer, String marketName, String codename, String model) {
- this.manufacturer = manufacturer;
- this.marketName = marketName;
- this.codename = codename;
- this.model = model;
- }
-
- private DeviceInfo(JSONObject jsonObject) throws JSONException {
- manufacturer = jsonObject.getString("manufacturer");
- marketName = jsonObject.getString("market_name");
- codename = jsonObject.getString("codename");
- model = jsonObject.getString("model");
- }
-
- /**
- * @return the consumer friendly name of the device.
- */
- public String getName() {
- if (!TextUtils.isEmpty(marketName)) {
- return marketName;
- }
- return capitalize(model);
- }
- }
-}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/DeviceName.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/DeviceName.kt
new file mode 100644
index 000000000..ee634fb33
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/DeviceName.kt
@@ -0,0 +1,573 @@
+package com.habitrpg.android.habitica.helpers
+
+import android.Manifest
+import android.annotation.SuppressLint
+import android.content.Context
+import android.content.SharedPreferences
+import android.content.pm.PackageManager
+import android.net.ConnectivityManager
+import android.os.Build
+import android.os.Handler
+import android.os.Looper
+import android.text.TextUtils
+import androidx.annotation.WorkerThread
+import org.json.JSONArray
+import org.json.JSONException
+import org.json.JSONObject
+import java.io.BufferedReader
+import java.io.IOException
+import java.io.InputStreamReader
+import java.net.HttpURLConnection
+import java.net.URL
+import java.util.*
+
+/*
+* Copyright (C) 2017 Jared Rummler
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/ // @formatter:off
+/**
+ *
+ * Get the consumer friendly name of an Android device.
+ *
+ *
+ * On many popular devices the market name of the device is not available. For example, on the
+ * Samsung Galaxy S6 the value of [Build.MODEL] could be "SM-G920F", "SM-G920I", "SM-G920W8",
+ * etc.
+ *
+ *
+ * See the usages below to get the consumer friends name of a device:
+ *
+ *
+ * **Get the name of the current device:**
+ *
+ *
+ * String deviceName = DeviceName.getDeviceName();
+
*
+ *
+ *
+ * The above code will get the correct device name for the top 600 Android devices. If the
+ * device is unrecognized, then Build.MODEL is returned.
+ *
+ *
+ * **Get the name of a device using the device's codename:**
+ *
+ *
+ * // Retruns "Moto X Style"
+ * DeviceName.getDeviceName("clark", "Unknown device");
+ *
+ *
+ *
+ * **Get information about the device:**
+ *
+ *
+ * DeviceName.with(context).request(new DeviceName.Callback() {
+ *
+ * @Override public void onFinished(DeviceName.DeviceInfo info, Exception error) {
+ * String manufacturer = info.manufacturer; // "Samsung"
+ * String name = info.marketName; // "Galaxy S6 Edge"
+ * String model = info.model; // "SM-G925I"
+ * String codename = info.codename; // "zerolte"
+ * String deviceName = info.getName(); // "Galaxy S6 Edge"
+ * // FYI: We are on the UI thread.
+ * }
+ * });
+ *
+ *
+ *
+ * The above code loads JSON from a generated list of device names based on Google's maintained
+ * list. It will be up-to-date with Google's supported device list so that you will get the correct
+ * name for new or unknown devices. This supports over 10,000 devices.
+ *
+ *
+ * This will only make a network call once. The value is saved to SharedPreferences for future
+ * calls.
+ */
+object DeviceName {
+ // @formatter:on
+ // JSON which is derived from Google's PDF document which contains all devices on Google Play.
+ // To get the URL to the JSON file which contains information about the device name:
+ // String url = String.format(DEVICE_JSON_URL, Build.DEVICE);
+ private const val DEVICE_JSON_URL = "https://raw.githubusercontent.com/jaredrummler/AndroidDeviceNames/master/json/devices/%s.json"
+
+ // Preference filename for storing device info so we don't need to download it again.
+ private const val SHARED_PREF_NAME = "device_names"
+
+ /**
+ * Create a new request to get information about a device.
+ *
+ * @param context the application context
+ * @return a new Request instance.
+ */
+ fun with(context: Context): Request {
+ return Request(context.applicationContext)
+ }
+
+ /**
+ * Get the consumer friendly name of the device.
+ *
+ * @return the market name of the current device.
+ * @see .getDeviceName
+ */
+ val deviceName: String?
+ get() = getDeviceName(Build.DEVICE, Build.MODEL, Build.MODEL.capitalize(Locale.getDefault()))
+
+ /**
+ * Get the consumer friendly name of a device.
+ *
+ * @param codename the value of the system property "ro.product.device" ([Build.DEVICE])
+ * *or*
+ * the value of the system property "ro.product.model" ([Build.MODEL])
+ * @param fallback the fallback name if the device is unknown. Usually the value of the system property
+ * "ro.product.model" ([Build.MODEL])
+ * @return the market name of a device or `fallback` if the device is unknown.
+ */
+ fun getDeviceName(codename: String?, fallback: String?): String? {
+ return getDeviceName(codename, codename, fallback)
+ }
+
+ /**
+ * Get the consumer friendly name of a device.
+ *
+ * @param codename the value of the system property "ro.product.device" ([Build.DEVICE]).
+ * @param model the value of the system property "ro.product.model" ([Build.MODEL]).
+ * @param fallback the fallback name if the device is unknown. Usually the value of the system property
+ * "ro.product.model" ([Build.MODEL])
+ * @return the market name of a device or `fallback` if the device is unknown.
+ */
+ fun getDeviceName(codename: String?, model: String?, fallback: String?): String? {
+ // ----------------------------------------------------------------------------
+ // Google
+ if (codename != null && codename == "walleye") {
+ return "Pixel 2"
+ }
+ if (codename != null && codename == "taimen") {
+ return "Pixel 2 XL"
+ }
+ if (codename != null && codename == "blueline") {
+ return "Pixel 3"
+ }
+ if (codename != null && codename == "crosshatch") {
+ return "Pixel 3 XL"
+ }
+ if (codename != null && codename == "sargo") {
+ return "Pixel 3a"
+ }
+ if (codename != null && codename == "bonito") {
+ return "Pixel 3a XL"
+ }
+ // ----------------------------------------------------------------------------
+ // Huawei
+ if (codename != null && codename == "HWBND-H" || model != null && (model == "BND-L21" || model == "BND-L24" || model == "BND-L31")) {
+ return "Honor 7X"
+ }
+ if (codename != null && codename == "HWBKL" || model != null && (model == "BKL-L04" || model ==
+ "BKL-L09")) {
+ return "Honor View 10"
+ }
+ if (codename != null && codename == "HWALP" || model != null && (model == "ALP-AL00" || model ==
+ "ALP-L09" || model == "ALP-L29" || model == "ALP-TL00")) {
+ return "Mate 10"
+ }
+ if (codename != null && codename == "HWMHA" || model != null && (model == "MHA-AL00" || model ==
+ "MHA-L09" || model == "MHA-L29" || model == "MHA-TL00")) {
+ return "Mate 9"
+ }
+ if (codename != null && codename == "angler") {
+ return "Nexus 6P"
+ }
+ // ----------------------------------------------------------------------------
+ // LGE
+ if (codename != null && codename == "h1" || model != null && (model == "LG-F700K" || model ==
+ "LG-F700L" || model == "LG-F700S" || model == "LG-H820" || model == "LG-H820PR" || model ==
+ "LG-H830" || model == "LG-H831" || model == "LG-H850" || model == "LG-H858" || model ==
+ "LG-H860" || model == "LG-H868" || model == "LGAS992" || model == "LGLS992" || model ==
+ "LGUS992" || model == "RS988" || model == "VS987")) {
+ return "LG G5"
+ }
+ if (codename != null && codename == "lucye" || model != null && (model == "LG-AS993" || model == "LG-H870" || model == "LG-H870AR" || model == "LG-H870DS" || model == "LG-H870I" || model == "LG-H870S" || model == "LG-H871" || model == "LG-H871S" || model == "LG-H872" || model == "LG-H872PR" || model == "LG-H873" || model == "LG-LS993" || model == "LGM-G600K" || model == "LGM-G600L" || model == "LGM-G600S" || model == "LGUS997" || model == "VS988")) {
+ return "LG G6"
+ }
+ if (codename != null && codename == "flashlmdd" || model != null && (model == "LM-V500" || model == "LM-V500N")) {
+ return "LG V50 ThinQ"
+ }
+ if (codename != null && codename == "mako") {
+ return "Nexus 4"
+ }
+ if (codename != null && codename == "hammerhead") {
+ return "Nexus 5"
+ }
+ if (codename != null && codename == "bullhead") {
+ return "Nexus 5X"
+ }
+ // ----------------------------------------------------------------------------
+ // Motorola
+ if (codename != null && codename == "griffin" || model != null && (model == "XT1650" || model ==
+ "XT1650-05")) {
+ return "Moto Z"
+ }
+ if (codename != null && codename == "shamu") {
+ return "Nexus 6"
+ }
+ // ----------------------------------------------------------------------------
+ // Nokia
+ if (codename != null && (codename == "RHD" || codename == "ROO" || codename == "ROON_sprout" || codename == "ROO_sprout")) {
+ return "Nokia 3.1 Plus"
+ }
+ if (codename != null && codename == "CTL_sprout") {
+ return "Nokia 7.1"
+ }
+ // ----------------------------------------------------------------------------
+ // OnePlus
+ if (codename != null && codename == "OnePlus6" || model != null && model == "ONEPLUS A6003") {
+ return "OnePlus 6"
+ }
+ if (codename != null && (codename == "OnePlus6T" || codename == "OnePlus6TSingle") || (model != null
+ && model == "ONEPLUS A6013")) {
+ return "OnePlus 6T"
+ }
+ if (codename != null && codename == "OnePlus7" || model != null && model == "GM1905") {
+ return "OnePlus 7"
+ }
+ if (codename != null && (codename == "OnePlus7Pro" || codename == "OnePlus7ProTMO") || (model != null
+ && (model == "GM1915" || model == "GM1917"))) {
+ return "OnePlus 7 Pro"
+ }
+ // ----------------------------------------------------------------------------
+ // Samsung
+ if (codename != null && codename == "a50" || model != null && (model == "SM-A505F" || model == "SM-A505FM" || model == "SM-A505FN" || model == "SM-A505G" || model == "SM-A505GN" || model == "SM-A505GT" || model == "SM-A505N" || model == "SM-A505U" || model == "SM-A505W" || model == "SM-A505YN")) {
+ return "Galaxy A50"
+ }
+ if (codename != null && (codename == "a6elteaio" || codename == "a6elteatt" || codename == "a6eltemtr" || codename == "a6eltespr" || codename == "a6eltetmo" || codename == "a6elteue" || codename == "a6lte" || codename == "a6lteks") || model != null && (model == "SM-A600A" || model == "SM-A600AZ" || model == "SM-A600F" || model == "SM-A600FN" || model == "SM-A600G" || model == "SM-A600GN" || model == "SM-A600N" || model == "SM-A600P" || model == "SM-A600T" || model == "SM-A600T1" || model == "SM-A600U")) {
+ return "Galaxy A6"
+ }
+ if (codename != null && (codename == "SC-01J" || codename == "SCV34" || codename == "gracelte" || codename == "graceltektt" || codename == "graceltelgt" || codename == "gracelteskt" || codename == "graceqlteacg" || codename == "graceqlteatt" || codename == "graceqltebmc" || codename == "graceqltechn" || codename == "graceqltedcm" || codename == "graceqltelra" || codename == "graceqltespr" || codename == "graceqltetfnvzw" || codename == "graceqltetmo" || codename == "graceqlteue" || codename == "graceqlteusc" || codename == "graceqltevzw") || model != null && (model == "SAMSUNG-SM-N930A" || model == "SC-01J" || model == "SCV34" || model == "SGH-N037" || model == "SM-N9300" || model == "SM-N930F" || model == "SM-N930K" || model == "SM-N930L" || model == "SM-N930P" || model == "SM-N930R4" || model == "SM-N930R6" || model == "SM-N930R7" || model == "SM-N930S" || model == "SM-N930T" || model == "SM-N930U" || model == "SM-N930V" || model == "SM-N930VL" || model == "SM-N930W8" || model == "SM-N930X")) {
+ return "Galaxy Note7"
+ }
+ if (codename != null && (codename == "SC-01K" || codename == "SCV37" || codename == "greatlte" || codename == "greatlteks" || codename == "greatqlte" || codename == "greatqltechn" || codename == "greatqltecmcc" || codename == "greatqltecs" || codename == "greatqlteue") || model != null && (model == "SC-01K" || model == "SCV37" || model == "SM-N9500" || model == "SM-N9508" || model == "SM-N950F" || model == "SM-N950N" || model == "SM-N950U" || model == "SM-N950U1" || model == "SM-N950W" || model == "SM-N950XN")) {
+ return "Galaxy Note8"
+ }
+ if (codename != null && (codename == "SC-01L" || codename == "SCV40" || codename == "crownlte" || codename == "crownlteks" || codename == "crownqltechn" || codename == "crownqltecs" || codename == "crownqltesq" || codename == "crownqlteue") || model != null && (model == "SC-01L" || model == "SCV40" || model == "SM-N9600" || model == "SM-N960F" || model == "SM-N960N" || model == "SM-N960U" || model == "SM-N960U1" || model == "SM-N960W")) {
+ return "Galaxy Note9"
+ }
+ if (codename != null && (codename == "SC-03L" || codename == "SCV41" || codename == "beyond1" || codename == "beyond1q") || model != null && (model == "SC-03L" || model == "SCV41" || model == "SM-G9730" || model == "SM-G9738" || model == "SM-G973F" || model == "SM-G973N" || model == "SM-G973U" || model == "SM-G973U1" || model == "SM-G973W")) {
+ return "Galaxy S10"
+ }
+ if (codename != null && (codename == "SC-04L" || codename == "SCV42" || codename == "beyond2" || codename == "beyond2q") || model != null && (model == "SC-04L" || model == "SCV42" || model == "SM-G9750" || model == "SM-G9758" || model == "SM-G975F" || model == "SM-G975N" || model == "SM-G975U" || model == "SM-G975U1" || model == "SM-G975W")) {
+ return "Galaxy S10+"
+ }
+ if (codename != null && (codename == "beyond0" || codename == "beyond0q") || (model != null
+ && (model == "SM-G9700" || model == "SM-G9708" || model == "SM-G970F" || model == "SM-G970N" || model == "SM-G970U" || model == "SM-G970U1" || model == "SM-G970W"))) {
+ return "Galaxy S10e"
+ }
+ if (codename != null && (codename == "SC-04F" || codename == "SCL23" || codename == "k3g" || codename == "klte" || codename == "klteMetroPCS" || codename == "klteacg" || codename == "klteaio" || codename == "klteatt" || codename == "kltecan" || codename == "klteduoszn" || codename == "kltektt" || codename == "kltelgt" || codename == "kltelra" || codename == "klteskt" || codename == "kltespr" || codename == "kltetfnvzw" || codename == "kltetmo" || codename == "klteusc" || codename == "kltevzw" || codename == "kwifi" || codename == "lentisltektt" || codename == "lentisltelgt" || codename == "lentislteskt") || model != null && (model == "SAMSUNG-SM-G900A" || model == "SAMSUNG-SM-G900AZ" || model == "SC-04F" || model == "SCL23" || model == "SM-G9006W" || model == "SM-G9008W" || model == "SM-G9009W" || model == "SM-G900F" || model == "SM-G900FQ" || model == "SM-G900H" || model == "SM-G900I" || model == "SM-G900K" || model == "SM-G900L" || model == "SM-G900M" || model == "SM-G900MD" || model == "SM-G900P" || model == "SM-G900R4" || model == "SM-G900R6" || model == "SM-G900R7" || model == "SM-G900S" || model == "SM-G900T" || model == "SM-G900T1" || model == "SM-G900T3" || model == "SM-G900T4" || model == "SM-G900V" || model == "SM-G900W8" || model == "SM-G900X" || model == "SM-G906K" || model == "SM-G906L" || model == "SM-G906S" || model == "SM-S903VL")) {
+ return "Galaxy S5"
+ }
+ if (codename != null && (codename == "s5neolte" || codename == "s5neoltecan") || model != null && (model == "SM-G903F" || model == "SM-G903M" || model == "SM-G903W")) {
+ return "Galaxy S5 Neo"
+ }
+ if (codename != null && (codename == "SC-05G" || codename == "zeroflte" || codename == "zeroflteacg" || codename == "zeroflteaio" || codename == "zeroflteatt" || codename == "zerofltebmc" || codename == "zerofltechn" || codename == "zerofltectc" || codename == "zerofltektt" || codename == "zerofltelgt" || codename == "zerofltelra" || codename == "zerofltemtr" || codename == "zeroflteskt" || codename == "zerofltespr" || codename == "zerofltetfnvzw" || codename == "zerofltetmo" || codename == "zeroflteusc" || codename == "zerofltevzw") || model != null && (model == "SAMSUNG-SM-G920A" || model == "SAMSUNG-SM-G920AZ" || model == "SC-05G" || model == "SM-G9200" || model == "SM-G9208" || model == "SM-G9209" || model == "SM-G920F" || model == "SM-G920I" || model == "SM-G920K" || model == "SM-G920L" || model == "SM-G920P" || model == "SM-G920R4" || model == "SM-G920R6" || model == "SM-G920R7" || model == "SM-G920S" || model == "SM-G920T" || model == "SM-G920T1" || model == "SM-G920V" || model == "SM-G920W8" || model == "SM-G920X" || model == "SM-S906L" || model == "SM-S907VL")) {
+ return "Galaxy S6"
+ }
+ if (codename != null && (codename == "404SC" || codename == "SC-04G" || codename == "SCV31" || codename == "zerolte" || codename == "zerolteacg" || codename == "zerolteatt" || codename == "zeroltebmc" || codename == "zeroltechn" || codename == "zeroltektt" || codename == "zeroltelra" || codename == "zerolteskt" || codename == "zeroltespr" || codename == "zeroltetmo" || codename == "zerolteusc" || codename == "zeroltevzw") || model != null && (model == "404SC" || model == "SAMSUNG-SM-G925A" || model == "SC-04G" || model == "SCV31" || model == "SM-G9250" || model == "SM-G925I" || model == "SM-G925K" || model == "SM-G925P" || model == "SM-G925R4" || model == "SM-G925R6" || model == "SM-G925R7" || model == "SM-G925S" || model == "SM-G925T" || model == "SM-G925V" || model == "SM-G925W8" || model == "SM-G925X")) {
+ return "Galaxy S6 Edge"
+ }
+ if (codename != null && (codename == "zenlte" || codename == "zenlteatt" || codename == "zenltebmc" || codename == "zenltechn" || codename == "zenltektt" || codename == "zenltekx" || codename == "zenltelgt" || codename == "zenlteskt" || codename == "zenltespr" || codename == "zenltetmo" || codename == "zenlteusc" || codename == "zenltevzw") || model != null && (model == "SAMSUNG-SM-G928A" || model == "SM-G9280" || model == "SM-G9287C" || model == "SM-G928C" || model == "SM-G928G" || model == "SM-G928I" || model == "SM-G928K" || model == "SM-G928L" || model == "SM-G928N0" || model == "SM-G928P" || model == "SM-G928R4" || model == "SM-G928S" || model == "SM-G928T" || model == "SM-G928V" || model == "SM-G928W8" || model == "SM-G928X")) {
+ return "Galaxy S6 Edge+"
+ }
+ if (codename != null && (codename == "herolte" || codename == "heroltebmc" || codename ==
+ "heroltektt" || codename == "heroltelgt" || codename == "herolteskt" || codename ==
+ "heroqlteacg" || codename == "heroqlteaio" || codename == "heroqlteatt" || codename ==
+ "heroqltecctvzw" || codename == "heroqltechn" || codename == "heroqltelra" || codename ==
+ "heroqltemtr" || codename == "heroqltespr" || codename == "heroqltetfnvzw" || codename ==
+ "heroqltetmo" || codename == "heroqlteue" || codename == "heroqlteusc" || codename ==
+ "heroqltevzw") || model != null && (model == "SAMSUNG-SM-G930A" || model == "SAMSUNG-SM-G930AZ" || model == "SM-G9300" || model == "SM-G9308" || model == "SM-G930F" || model == "SM-G930K" || model == "SM-G930L" || model == "SM-G930P" || model == "SM-G930R4" || model == "SM-G930R6" || model == "SM-G930R7" || model == "SM-G930S" || model == "SM-G930T" || model == "SM-G930T1" || model == "SM-G930U" || model == "SM-G930V" || model == "SM-G930VC" || model == "SM-G930VL" || model == "SM-G930W8" || model == "SM-G930X")) {
+ return "Galaxy S7"
+ }
+ if (codename != null && (codename == "SC-02H" || codename == "SCV33" || codename == "hero2lte" || codename == "hero2ltebmc" || codename == "hero2ltektt" || codename == "hero2lteskt" || codename == "hero2qlteatt" || codename == "hero2qltecctvzw" || codename == "hero2qltespr" || codename == "hero2qltetmo" || codename == "hero2qlteusc" || codename == "hero2qltevzw") || model != null && (model == "SAMSUNG-SM-G935A" || model == "SC-02H" || model == "SCV33" || model == "SM-G935K" || model == "SM-G935P" || model == "SM-G935R4" || model == "SM-G935S" || model == "SM-G935T" || model == "SM-G935V" || model == "SM-G935VC" || model == "SM-G935W8" || model == "SM-G935X")) {
+ return "Galaxy S7 Edge"
+ }
+ if (codename != null && (codename == "SC-02J" || codename == "SCV36" || codename == "dreamlte" || codename == "dreamlteks" || codename == "dreamqltecan" || codename == "dreamqltechn" || codename == "dreamqltecmcc" || codename == "dreamqltesq" || codename == "dreamqlteue") || model != null && (model == "SC-02J" || model == "SCV36" || model == "SM-G9500" || model == "SM-G9508" || model == "SM-G950F" || model == "SM-G950N" || model == "SM-G950U" || model == "SM-G950U1" || model == "SM-G950W")) {
+ return "Galaxy S8"
+ }
+ if (codename != null && (codename == "SC-03J" || codename == "SCV35" || codename == "dream2lte" || codename == "dream2lteks" || codename == "dream2qltecan" || codename == "dream2qltechn" || codename == "dream2qltesq" || codename == "dream2qlteue") || model != null && (model == "SC-03J" || model == "SCV35" || model == "SM-G9550" || model == "SM-G955F" || model == "SM-G955N" || model == "SM-G955U" || model == "SM-G955U1" || model == "SM-G955W")) {
+ return "Galaxy S8+"
+ }
+ if (codename != null && (codename == "SC-02K" || codename == "SCV38" || codename == "starlte" || codename == "starlteks" || codename == "starqltechn" || codename == "starqltecmcc" || codename == "starqltecs" || codename == "starqltesq" || codename == "starqlteue") || model != null && (model == "SC-02K" || model == "SCV38" || model == "SM-G9600" || model == "SM-G9608" || model == "SM-G960F" || model == "SM-G960N" || model == "SM-G960U" || model == "SM-G960U1" || model == "SM-G960W")) {
+ return "Galaxy S9"
+ }
+ if (codename != null && (codename == "SC-03K" || codename == "SCV39" || codename == "star2lte" || codename == "star2lteks" || codename == "star2qltechn" || codename == "star2qltecs" || codename == "star2qltesq" || codename == "star2qlteue") || model != null && (model == "SC-03K" || model == "SCV39" || model == "SM-G9650" || model == "SM-G965F" || model == "SM-G965N" || model == "SM-G965U" || model == "SM-G965U1" || model == "SM-G965W")) {
+ return "Galaxy S9+"
+ }
+ // ----------------------------------------------------------------------------
+ // Sony
+ if (codename != null && (codename == "802SO" || codename == "J8110" || codename == "J8170" || codename == "J9110" || codename == "SO-03L" || codename == "SOV40") || model != null && (model == "802SO" || model == "J8110" || model == "J8170" || model == "J9110" || model == "SO-03L" || model == "SOV40")) {
+ return "Xperia 1"
+ }
+ if (codename != null && (codename == "I3113" || codename == "I3123" || codename == "I4113" || codename == "I4193") || model != null && (model == "I3113" || model == "I3123" || model == "I4113" || model == "I4193")) {
+ return "Xperia 10"
+ }
+ if (codename != null && (codename == "I3213" || codename == "I3223" || codename == "I4213" || codename == "I4293") || model != null && (model == "I3213" || model == "I3223" || model == "I4213" || model == "I4293")) {
+ return "Xperia 10 Plus"
+ }
+ if (codename != null && (codename == "702SO" || codename == "H8216" || codename == "H8266" || codename == "H8276" || codename == "H8296" || codename == "SO-03K" || codename == "SOV37") || model != null && (model == "702SO" || model == "H8216" || model == "H8266" || model == "H8276" || model == "H8296" || model == "SO-03K" || model == "SOV37")) {
+ return "Xperia XZ2"
+ }
+ if (codename != null && (codename == "H8116" || codename == "H8166" || codename == "SO-04K" || codename == "SOV38") || model != null && (model == "H8116" || model == "H8166" || model == "SO-04K" || model == "SOV38")) {
+ return "Xperia XZ2 Premium"
+ }
+ return if (codename != null && (codename == "801SO" || codename == "H8416" || codename == "H9436" || codename == "H9493" || codename == "SO-01L" || codename == "SOV39") || model != null && (model == "801SO" || model == "H8416" || model == "H9436" || model == "H9493" || model == "SO-01L" || model == "SOV39")) {
+ "Xperia XZ3"
+ } else fallback
+ }
+
+ /**
+ * Get the [DeviceInfo] for the current device. Do not run on the UI thread, as this may
+ * download JSON to retrieve the [DeviceInfo]. JSON is only downloaded once and then
+ * stored to [SharedPreferences].
+ *
+ * @param context the application context.
+ * @return [DeviceInfo] for the current device.
+ */
+ @WorkerThread
+ fun getDeviceInfo(context: Context): DeviceInfo {
+ return getDeviceInfo(context.applicationContext, Build.DEVICE, Build.MODEL)
+ }
+
+ /**
+ * Get the [DeviceInfo] for the current device. Do not run on the UI thread, as this may
+ * download JSON to retrieve the [DeviceInfo]. JSON is only downloaded once and then
+ * stored to [SharedPreferences].
+ *
+ * @param context the application context.
+ * @param codename the codename of the device
+ * @return [DeviceInfo] for the current device.
+ */
+ @WorkerThread
+ fun getDeviceInfo(context: Context, codename: String?): DeviceInfo {
+ return getDeviceInfo(context, codename, null)
+ }
+
+ /**
+ * Get the [DeviceInfo] for the current device. Do not run on the UI thread, as this may
+ * download JSON to retrieve the [DeviceInfo]. JSON is only downloaded once and then
+ * stored to [SharedPreferences].
+ *
+ * @param context the application context.
+ * @param codename the codename of the device
+ * @param model the model of the device
+ * @return [DeviceInfo] for the current device.
+ */
+ @WorkerThread
+ fun getDeviceInfo(context: Context, codename: String?, model: String?): DeviceInfo {
+ val prefs = context.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE)
+ val key = String.format("%s:%s", codename, model)
+ val savedJson = prefs.getString(key, null)
+ if (savedJson != null) {
+ try {
+ return DeviceInfo(JSONObject(savedJson))
+ } catch (e: JSONException) {
+ e.printStackTrace()
+ }
+ }
+
+ // check if we have an internet connection
+ val ret = context.checkCallingOrSelfPermission(Manifest.permission.ACCESS_NETWORK_STATE)
+ var isConnectedToNetwork = false
+ if (ret == PackageManager.PERMISSION_GRANTED) {
+ val connMgr = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
+ @SuppressLint("MissingPermission") val networkInfo = connMgr.activeNetworkInfo
+ if (networkInfo != null && networkInfo.isConnected) {
+ isConnectedToNetwork = true
+ }
+ } else {
+ // assume we are connected.
+ isConnectedToNetwork = true
+ }
+ if (isConnectedToNetwork) {
+ try {
+ // Get the device name from the generated JSON files created from Google's device list.
+ val url = String.format(DEVICE_JSON_URL, codename!!.toLowerCase(Locale.ENGLISH))
+ val jsonString = downloadJson(url)
+ val jsonArray = JSONArray(jsonString)
+ var i = 0
+ val len = jsonArray.length()
+ while (i < len) {
+ val json = jsonArray.getJSONObject(i)
+ val info = DeviceInfo(json)
+ if (codename.equals(info.codename, ignoreCase = true) && model == null
+ || codename.equals(info.codename, ignoreCase = true) && model.equals(info.model, ignoreCase = true)) {
+ // Save to SharedPreferences so we don't need to make another request.
+ val editor = prefs.edit()
+ editor.putString(key, json.toString())
+ editor.apply()
+ return info
+ }
+ i++
+ }
+ } catch (e: Exception) {
+ e.printStackTrace()
+ }
+ }
+ return if (codename == Build.DEVICE && Build.MODEL == model) {
+ DeviceInfo(Build.MANUFACTURER, deviceName, codename, model) // current device
+ } else DeviceInfo(null, null, codename, model)
+ // unknown device
+ }
+
+ /** Download URL to String */
+ @WorkerThread
+ @Throws(IOException::class)
+ private fun downloadJson(myurl: String): String {
+ val sb = StringBuilder()
+ var reader: BufferedReader? = null
+ return try {
+ val url = URL(myurl)
+ val conn = url.openConnection() as HttpURLConnection
+ conn.readTimeout = 10000
+ conn.connectTimeout = 15000
+ conn.requestMethod = "GET"
+ conn.doInput = true
+ conn.connect()
+ if (conn.responseCode == HttpURLConnection.HTTP_OK) {
+ reader = BufferedReader(InputStreamReader(conn.inputStream))
+ var line: String?
+ while (reader.readLine().also { line = it } != null) {
+ sb.append(line).append('\n')
+ }
+ }
+ sb.toString()
+ } finally {
+ reader?.close()
+ }
+ }
+
+ class Request internal constructor(val context: Context) {
+ val handler: Handler
+ var codename: String? = null
+ var model: String? = null
+
+ /**
+ * Set the device codename to query. You should also set the model.
+ *
+ * @param codename the value of the system property "ro.product.device"
+ * @return This Request object to allow for chaining of calls to set methods.
+ * @see Build.DEVICE
+ */
+ fun setCodename(codename: String?): Request {
+ this.codename = codename
+ return this
+ }
+
+ /**
+ * Set the device model to query. You should also set the codename.
+ *
+ * @param model the value of the system property "ro.product.model"
+ * @return This Request object to allow for chaining of calls to set methods.
+ * @see Build.MODEL
+ */
+ fun setModel(model: String?): Request {
+ this.model = model
+ return this
+ }
+
+ /**
+ * Download information about the device. This saves the results in shared-preferences so
+ * future requests will not need a network connection.
+ *
+ * @param callback the callback to retrieve the [DeviceName.DeviceInfo]
+ */
+ fun request(callback: Callback) {
+ if (codename == null && model == null) {
+ codename = Build.DEVICE
+ model = Build.MODEL
+ }
+ val runnable = GetDeviceRunnable(callback)
+ if (Looper.myLooper() == Looper.getMainLooper()) {
+ Thread(runnable).start()
+ } else {
+ runnable.run() // already running in background thread.
+ }
+ }
+
+ private inner class GetDeviceRunnable(val callback: Callback) : Runnable {
+ var deviceInfo: DeviceInfo? = null
+ var error: Exception? = null
+ override fun run() {
+ try {
+ deviceInfo = getDeviceInfo(context, codename, model)
+ } catch (e: Exception) {
+ error = e
+ }
+ handler.post { callback.onFinished(deviceInfo, error) }
+ }
+ }
+
+ init {
+ handler = Handler(context.mainLooper)
+ }
+ }
+
+ /**
+ * Callback which is invoked when the [DeviceName.DeviceInfo] is finished loading.
+ */
+ interface Callback {
+ /**
+ * Callback to get the device info. This is run on the UI thread.
+ *
+ * @param info the requested [DeviceName.DeviceInfo]
+ * @param error `null` if nothing went wrong.
+ */
+ fun onFinished(info: DeviceInfo?, error: Exception?)
+ }
+
+ /**
+ * Device information based on
+ * [Google's maintained list](https://support.google.com/googleplay/answer/1727131).
+ */
+ class DeviceInfo {
+ /** Retail branding */
+ val manufacturer: String?
+
+ /** Marketing name */
+ val marketName: String?
+
+ /** the value of the system property "ro.product.device" */
+ val codename: String?
+
+ /** the value of the system property "ro.product.model" */
+ val model: String?
+
+ constructor(manufacturer: String?, marketName: String?, codename: String?, model: String?) {
+ this.manufacturer = manufacturer
+ this.marketName = marketName
+ this.codename = codename
+ this.model = model
+ }
+
+ constructor(jsonObject: JSONObject) {
+ manufacturer = jsonObject.getString("manufacturer")
+ marketName = jsonObject.getString("market_name")
+ codename = jsonObject.getString("codename")
+ model = jsonObject.getString("model")
+ }
+
+ /**
+ * @return the consumer friendly name of the device.
+ */
+ val name: String?
+ get() = if (!TextUtils.isEmpty(marketName)) {
+ marketName
+ } else model?.capitalize(Locale.getDefault())
+ }
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/Keyhelper.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/Keyhelper.kt
index 52fec9c52..3de8006b0 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/Keyhelper.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/Keyhelper.kt
@@ -12,6 +12,7 @@ import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.IOException
import java.io.UnsupportedEncodingException
+import java.lang.IllegalStateException
import java.math.BigInteger
import java.security.*
import java.util.*
@@ -188,6 +189,8 @@ constructor(ctx: Context, var sharedPreferences: SharedPreferences, var keyStore
null
} catch (e: GeneralSecurityException) {
null
+ } catch (e: IllegalStateException) {
+ null
}
}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/LanguageHelper.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/LanguageHelper.kt
index eb734a4c6..31c9e4f78 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/LanguageHelper.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/LanguageHelper.kt
@@ -4,13 +4,13 @@ import java.util.*
class LanguageHelper(languageSharedPref: String?) {
- var locale: Locale? = null
+ var locale: Locale
private set
var languageCode: String? = null
private set
init {
- when (languageSharedPref) {
+ when (val pref = languageSharedPref ?: "en") {
"iw" -> {
locale = Locale("iw")
languageCode = "he"
@@ -28,13 +28,11 @@ class LanguageHelper(languageSharedPref: String?) {
languageCode = "pt"
}
else -> {
- languageSharedPref?.let { pref ->
- locale = if (pref.contains("_")) {
- val languageCodeParts = pref.split("_".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
- Locale(languageCodeParts[0], languageCodeParts[1])
- } else {
- Locale(languageSharedPref)
- }
+ locale = if (pref.contains("_")) {
+ val languageCodeParts = pref.split("_".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
+ Locale(languageCodeParts[0], languageCodeParts[1])
+ } else {
+ Locale(pref)
}
languageCode = languageSharedPref
}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/MainNavigationController.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/MainNavigationController.kt
index f90bb8e51..dcbf71eca 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/MainNavigationController.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/MainNavigationController.kt
@@ -1,6 +1,7 @@
package com.habitrpg.android.habitica.helpers
import android.os.Bundle
+import android.util.Log
import androidx.navigation.NavController
import androidx.navigation.NavDirections
import java.lang.ref.WeakReference
@@ -21,7 +22,11 @@ object MainNavigationController {
lastNavigation = Date()
try {
navController?.get()?.navigate(transactionId, args)
- } catch (_: IllegalArgumentException) {}
+ } catch (e: IllegalArgumentException) {
+ Log.e("Main Navigation", e.localizedMessage)
+ } catch (error: Exception) {
+ Log.e("Main Navigation", error.localizedMessage)
+ }
}
}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/NotificationsManager.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/NotificationsManager.kt
index fb06fd50f..1475dd55c 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/NotificationsManager.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/NotificationsManager.kt
@@ -1,7 +1,6 @@
package com.habitrpg.android.habitica.helpers
import android.content.Context
-import androidx.core.os.bundleOf
import com.google.firebase.analytics.FirebaseAnalytics
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.data.ApiClient
@@ -15,13 +14,9 @@ import com.habitrpg.android.habitica.models.notifications.FirstDropData
import com.habitrpg.android.habitica.models.notifications.LoginIncentiveData
import com.habitrpg.android.habitica.models.user.User
import com.habitrpg.android.habitica.ui.views.HabiticaSnackbar
-import com.habitrpg.android.habitica.ui.views.dialogs.AchievementDialog
import io.reactivex.BackpressureStrategy
import io.reactivex.Completable
import io.reactivex.Flowable
-import io.reactivex.android.schedulers.AndroidSchedulers
-import io.reactivex.functions.Action
-import io.reactivex.functions.Consumer
import io.reactivex.subjects.BehaviorSubject
import org.greenrobot.eventbus.EventBus
import java.util.*
@@ -116,7 +111,7 @@ class NotificationsManager (private val context: Context) {
EventBus.getDefault().post(event)
if (apiClient != null) {
apiClient?.readNotification(notification.id)
- ?.subscribe(Consumer {}, RxErrorHandler.handleEmptyError())
+ ?.subscribe({}, RxErrorHandler.handleEmptyError())
}
}
return true
@@ -131,7 +126,7 @@ class NotificationsManager (private val context: Context) {
}
val sub = Completable.complete()
.delay(delay, TimeUnit.MILLISECONDS)
- .subscribe(Action {
+ .subscribe({
EventBus.getDefault().post(ShowAchievementDialog(achievement, notification.id, isLastOnboardingAchievement))
}, RxErrorHandler.handleEmptyError())
logOnboardingEvents(achievement)
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/PurchaseHandler.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/PurchaseHandler.kt
index 296dc705e..e2270b20e 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/PurchaseHandler.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/PurchaseHandler.kt
@@ -6,7 +6,6 @@ import com.habitrpg.android.habitica.HabiticaBaseApplication
import com.habitrpg.android.habitica.proxy.CrashlyticsProxy
import org.solovyev.android.checkout.*
import java.util.*
-import javax.annotation.Nonnull
class PurchaseHandler(activity: Activity, val crashlyticsProxy: CrashlyticsProxy) {
private val billing = HabiticaBaseApplication.getInstance(activity.applicationContext)?.billing
@@ -92,7 +91,11 @@ class PurchaseHandler(activity: Activity, val crashlyticsProxy: CrashlyticsProxy
private fun loadInventory(type: String, skus: List, callback: Inventory.Callback) {
val request = Inventory.Request.create().loadAllPurchases().loadSkus(type, skus)
if (request != null) {
- inventory?.load(request, callback)
+ try {
+ inventory?.load(request, callback)
+ } catch (e: NullPointerException) {
+ return
+ }
}
}
@@ -116,7 +119,7 @@ class PurchaseHandler(activity: Activity, val crashlyticsProxy: CrashlyticsProxy
}
}
- override fun onError(i: Int, e: Exception) { crashlyticsProxy.fabricLogE("Purchase", "Consume", e) }
+ override fun onError(i: Int, e: Exception) { crashlyticsProxy.logException(e) }
})
}
}
@@ -153,7 +156,7 @@ class PurchaseHandler(activity: Activity, val crashlyticsProxy: CrashlyticsProxy
}
override fun onError(i: Int, e: Exception) {
- crashlyticsProxy.fabricLogE("Purchase", "Consume", e)
+ crashlyticsProxy.logException(e)
}
})
}
@@ -161,7 +164,7 @@ class PurchaseHandler(activity: Activity, val crashlyticsProxy: CrashlyticsProxy
}
override fun onError(i: Int, e: Exception) {
- crashlyticsProxy.fabricLogE("Purchase", "getAllPurchases", e)
+ crashlyticsProxy.logException(e)
}
})
}
@@ -175,7 +178,7 @@ class PurchaseHandler(activity: Activity, val crashlyticsProxy: CrashlyticsProxy
override fun onSuccess(o: Any) { /* no-op */ }
override fun onError(i: Int, e: Exception) {
- crashlyticsProxy.fabricLogE("PurchaseConsumeException", "Consume", e)
+ crashlyticsProxy.logException(e)
}
})
}
@@ -195,7 +198,7 @@ class PurchaseHandler(activity: Activity, val crashlyticsProxy: CrashlyticsProxy
override fun onSuccess(o: Any) { /* no-op */ }
override fun onError(i: Int, e: Exception) {
- crashlyticsProxy.fabricLogE("PurchaseConsumeException", "Consume", e)
+ crashlyticsProxy.logException(e)
}
})
}
@@ -211,7 +214,7 @@ class PurchaseHandler(activity: Activity, val crashlyticsProxy: CrashlyticsProxy
override fun onSuccess(result: Any) { /* no-op */ }
override fun onError(response: Int, e: Exception) {
- crashlyticsProxy.fabricLogE("PurchaseConsumeException", "Consume", e)
+ crashlyticsProxy.logException(e)
}
})
}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/SoundManager.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/SoundManager.kt
index 25834344d..85c5c2e8a 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/SoundManager.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/SoundManager.kt
@@ -2,7 +2,6 @@ package com.habitrpg.android.habitica.helpers
import com.habitrpg.android.habitica.HabiticaBaseApplication
import io.reactivex.Maybe
-import io.reactivex.functions.Consumer
import io.reactivex.schedulers.Schedulers
import javax.inject.Inject
@@ -48,7 +47,7 @@ class SoundManager {
val soundFiles = ArrayList()
soundFiles.add(SoundFile(soundTheme, type))
- soundFileLoader.download(soundFiles).observeOn(Schedulers.newThread()).subscribe(Consumer {
+ soundFileLoader.download(soundFiles).observeOn(Schedulers.newThread()).subscribe({
val file = soundFiles[0]
loadedSoundFiles[type] = file
file.play()
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/TaskAlarmManager.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/TaskAlarmManager.kt
index 4f4094b80..002227421 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/TaskAlarmManager.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/TaskAlarmManager.kt
@@ -15,7 +15,6 @@ import com.habitrpg.android.habitica.receivers.TaskReceiver
import com.habitrpg.shared.habitica.HLogger
import com.habitrpg.shared.habitica.LogLevel
import io.reactivex.Flowable
-import io.reactivex.functions.Consumer
import java.util.*
class TaskAlarmManager(private var context: Context, private var taskRepository: TaskRepository, private var userId: String) {
@@ -49,15 +48,15 @@ class TaskAlarmManager(private var context: Context, private var taskRepository:
taskRepository.getTaskCopy(taskId)
.filter { task -> task.isValid && task.isManaged && Task.TYPE_DAILY == task.type }
.firstElement()
- .subscribe(Consumer { this.setAlarmsForTask(it) }, RxErrorHandler.handleEmptyError())
+ .subscribe({ this.setAlarmsForTask(it) }, RxErrorHandler.handleEmptyError())
}
fun scheduleAllSavedAlarms(preventDailyReminder: Boolean) {
taskRepository.getTaskCopies(userId)
.firstElement()
.toFlowable()
- .flatMap { Flowable.fromIterable(it) }
- .subscribe(Consumer { this.setAlarmsForTask(it) }, RxErrorHandler.handleEmptyError())
+ .flatMap { Flowable.fromIterable(it) }
+ .subscribe({ this.setAlarmsForTask(it) }, RxErrorHandler.handleEmptyError())
if (!preventDailyReminder) {
scheduleDailyReminder(context)
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/TaskFilterHelper.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/TaskFilterHelper.kt
index 7b9c6db69..e4ebe9147 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/TaskFilterHelper.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/TaskFilterHelper.kt
@@ -33,10 +33,6 @@ class TaskFilterHelper {
}
}
- fun isTagChecked(tagID: String): Boolean {
- return this.tagsId.contains(tagID)
- }
-
fun filter(tasks: List): List {
if (tasks.isEmpty()) {
return tasks
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/HabiticaFirebaseMessagingService.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/HabiticaFirebaseMessagingService.kt
index c8cc4127e..d73dc9926 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/HabiticaFirebaseMessagingService.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/HabiticaFirebaseMessagingService.kt
@@ -3,10 +3,8 @@ package com.habitrpg.android.habitica.helpers.notifications
import com.google.firebase.iid.FirebaseInstanceId
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
-import com.habitrpg.android.habitica.HabiticaApplication
import com.habitrpg.android.habitica.HabiticaBaseApplication
import com.habitrpg.android.habitica.components.UserComponent
-import java.util.*
import javax.inject.Inject
class HabiticaFirebaseMessagingService : FirebaseMessagingService() {
@@ -19,14 +17,16 @@ class HabiticaFirebaseMessagingService : FirebaseMessagingService() {
override fun onMessageReceived(remoteMessage: RemoteMessage) {
userComponent?.inject(this)
- pushNotificationManager.displayNotification(remoteMessage)
+ if (this::pushNotificationManager.isInitialized) {
+ pushNotificationManager.displayNotification(remoteMessage)
+ }
}
override fun onNewToken(s: String) {
super.onNewToken(s)
userComponent?.inject(this)
val refreshedToken = FirebaseInstanceId.getInstance().token
- if (refreshedToken != null) {
+ if (refreshedToken != null && this::pushNotificationManager.isInitialized) {
pushNotificationManager.refreshedToken = refreshedToken
}
}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/PushNotificationManager.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/PushNotificationManager.kt
index 7354b0dc2..02272b51b 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/PushNotificationManager.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/helpers/notifications/PushNotificationManager.kt
@@ -9,7 +9,6 @@ import com.habitrpg.android.habitica.data.ApiClient
import com.habitrpg.android.habitica.helpers.AmplitudeManager
import com.habitrpg.android.habitica.helpers.RxErrorHandler
import com.habitrpg.android.habitica.models.user.User
-import io.reactivex.functions.Consumer
import java.util.*
class PushNotificationManager(var apiClient: ApiClient, private val sharedPreferences: SharedPreferences, private val context: Context) {
@@ -43,14 +42,14 @@ class PushNotificationManager(var apiClient: ApiClient, private val sharedPrefer
val pushDeviceData = HashMap()
pushDeviceData["regId"] = this.refreshedToken
pushDeviceData["type"] = "android"
- apiClient.addPushDevice(pushDeviceData).subscribe(Consumer { }, RxErrorHandler.handleEmptyError())
+ apiClient.addPushDevice(pushDeviceData).subscribe({ }, RxErrorHandler.handleEmptyError())
}
fun removePushDeviceUsingStoredToken() {
if (this.refreshedToken.isEmpty()) {
return
}
- apiClient.deletePushDevice(this.refreshedToken).subscribe(Consumer { }, RxErrorHandler.handleEmptyError())
+ apiClient.deletePushDevice(this.refreshedToken).subscribe({ }, RxErrorHandler.handleEmptyError())
}
private fun userHasPushDevice(): Boolean {
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/interactors/CheckClassSelectionUseCase.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/interactors/CheckClassSelectionUseCase.kt
index d7bf998a2..70cea0804 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/interactors/CheckClassSelectionUseCase.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/interactors/CheckClassSelectionUseCase.kt
@@ -32,7 +32,7 @@ constructor(threadExecutor: ThreadExecutor, postExecutionThread: PostExecutionTh
displayClassSelectionActivity(requestValues.isInitialSelection, requestValues.currentClass, requestValues.activity)
}
- Flowable.empty()
+ Flowable.empty()
}
}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/interactors/DisplayItemDropUseCase.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/interactors/DisplayItemDropUseCase.kt
index 5776d9cb9..5369513e8 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/interactors/DisplayItemDropUseCase.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/interactors/DisplayItemDropUseCase.kt
@@ -1,14 +1,18 @@
package com.habitrpg.android.habitica.interactors
+import android.content.Context
import android.os.Handler
+import android.provider.Settings.Global.getString
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
+import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.executors.PostExecutionThread
import com.habitrpg.android.habitica.executors.ThreadExecutor
import com.habitrpg.android.habitica.helpers.SoundManager
import com.habitrpg.android.habitica.models.responses.TaskScoringResult
import com.habitrpg.android.habitica.ui.views.HabiticaSnackbar
import io.reactivex.Flowable
+import java.lang.StringBuilder
import javax.inject.Inject
class DisplayItemDropUseCase @Inject
@@ -17,18 +21,25 @@ constructor(private val soundManager: SoundManager, threadExecutor: ThreadExecut
override fun buildUseCaseObservable(requestValues: RequestValues): Flowable {
return Flowable.defer {
val data = requestValues.data
+ var snackbarText = StringBuilder(data?.drop?.dialog ?: "")
- if (data?.drop != null) {
+ if (data?.questItemsFound ?: 0 > 0 && requestValues.showQuestItems) {
+ if (snackbarText.isNotEmpty())
+ snackbarText.append('\n')
+ snackbarText.append(requestValues.context.getString(R.string.quest_items_found, data!!.questItemsFound))
+ }
+
+ if (snackbarText.isNotEmpty()) {
Handler().postDelayed({
HabiticaSnackbar.showSnackbar(requestValues.snackbarTargetView,
- data.drop?.dialog, HabiticaSnackbar.SnackbarDisplayType.DROP)
+ snackbarText, HabiticaSnackbar.SnackbarDisplayType.DROP)
soundManager.loadAndPlayAudio(SoundManager.SoundItemDrop)
}, 3000L)
}
- Flowable.empty()
+ Flowable.empty()
}
}
- class RequestValues(val data: TaskScoringResult?, val context: AppCompatActivity, val snackbarTargetView: ViewGroup) : UseCase.RequestValues
+ class RequestValues(val data: TaskScoringResult?, val context: AppCompatActivity, val snackbarTargetView: ViewGroup, val showQuestItems: Boolean) : UseCase.RequestValues
}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/interactors/LevelUpUseCase.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/interactors/LevelUpUseCase.kt
index ebe88862a..48bd42369 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/interactors/LevelUpUseCase.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/interactors/LevelUpUseCase.kt
@@ -14,7 +14,6 @@ import com.habitrpg.android.habitica.ui.AvatarView
import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper
import com.habitrpg.android.habitica.ui.views.dialogs.HabiticaAlertDialog
import io.reactivex.Flowable
-import io.reactivex.functions.Consumer
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
@@ -64,7 +63,7 @@ constructor(private val soundManager: SoundManager, threadExecutor: ThreadExecut
event.sharedMessage = requestValues.activity.getString(R.string.share_levelup, requestValues.newLevel)
val avatarView = AvatarView(requestValues.activity, showBackground = true, showMount = true, showPet = true)
avatarView.setAvatar(requestValues.user)
- avatarView.onAvatarImageReady(Consumer { t -> event.shareImage = t })
+ avatarView.onAvatarImageReady({ t -> event.shareImage = t })
val alert = HabiticaAlertDialog(requestValues.activity)
alert.setTitle(requestValues.activity.getString(R.string.levelup_header, requestValues.newLevel))
@@ -87,7 +86,7 @@ constructor(private val soundManager: SoundManager, threadExecutor: ThreadExecut
private fun showClassSelection(requestValues: RequestValues) {
checkClassSelectionUseCase.observable(CheckClassSelectionUseCase.RequestValues(requestValues.user, true, null, requestValues.activity))
- .subscribe(Consumer { }, RxErrorHandler.handleEmptyError())
+ .subscribe({ }, RxErrorHandler.handleEmptyError())
}
class RequestValues(val user: User, val activity: AppCompatActivity) : UseCase.RequestValues {
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/interactors/NotifyUserUseCase.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/interactors/NotifyUserUseCase.kt
index e076e92ed..32a386ba8 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/interactors/NotifyUserUseCase.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/interactors/NotifyUserUseCase.kt
@@ -39,7 +39,7 @@ constructor(threadExecutor: ThreadExecutor, postExecutionThread: PostExecutionTh
if (requestValues.hasLeveledUp == true) {
return@defer levelUpUseCase.observable(LevelUpUseCase.RequestValues(requestValues.user, requestValues.context))
- .flatMap { userRepository.retrieveUser(true) }
+ .flatMap { userRepository.retrieveUser(true) }
.map { it.stats }
} else {
val pair = getNotificationAndAddStatsToUser(requestValues.context, requestValues.xp, requestValues.hp, requestValues.gold, requestValues.mp, requestValues.questDamage, requestValues.user)
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/interactors/ScoreTaskLocallyInteractor.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/interactors/ScoreTaskLocallyInteractor.kt
index ee1853576..71c44d2cf 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/interactors/ScoreTaskLocallyInteractor.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/interactors/ScoreTaskLocallyInteractor.kt
@@ -123,10 +123,10 @@ class ScoreTaskLocallyInteractor {
var totalConstitution = levelStat
var totalPerception = levelStat
- totalStrength += user.stats?.buffs?.getStr()?.toInt() ?: 0
- totalIntelligence += user.stats?.buffs?.get_int()?.toInt() ?: 0
- totalConstitution += user.stats?.buffs?.getCon()?.toInt() ?: 0
- totalPerception += user.stats?.buffs?.getPer()?.toInt() ?: 0
+ totalStrength += user.stats?.buffs?.str?.toInt() ?: 0
+ totalIntelligence += user.stats?.buffs?._int?.toInt() ?: 0
+ totalConstitution += user.stats?.buffs?.con?.toInt() ?: 0
+ totalPerception += user.stats?.buffs?.per?.toInt() ?: 0
totalStrength += user.stats?.strength ?: 0
totalIntelligence += user.stats?.intelligence ?: 0
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/interactors/UseCase.java b/Habitica/src/main/java/com/habitrpg/android/habitica/interactors/UseCase.java
index 900ec24ef..f08fb797c 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/interactors/UseCase.java
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/interactors/UseCase.java
@@ -7,21 +7,15 @@ import io.reactivex.Flowable;
public abstract class UseCase {
- private final ThreadExecutor threadExecutor;
private final PostExecutionThread postExecutionThread;
protected UseCase(ThreadExecutor threadExecutor,
PostExecutionThread postExecutionThread) {
- this.threadExecutor = threadExecutor;
this.postExecutionThread = postExecutionThread;
}
- /**
- * Builds an {@link rx.Flowable} which will be used when executing the current {@link UseCase}.
- */
protected abstract Flowable buildUseCaseObservable(Q requestValues);
- @SuppressWarnings("unchecked")
public Flowable observable(Q requestValues) {
return this.buildUseCaseObservable(requestValues)
.subscribeOn(postExecutionThread.getScheduler())
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/Avatar.java b/Habitica/src/main/java/com/habitrpg/android/habitica/models/Avatar.java
deleted file mode 100644
index 66a77e762..000000000
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/Avatar.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package com.habitrpg.android.habitica.models;
-
-
-import androidx.annotation.Nullable;
-
-import com.habitrpg.android.habitica.models.user.Outfit;
-import com.habitrpg.android.habitica.models.user.Stats;
-
-/**
- * Created by phillip on 29.06.17.
- */
-
-public interface Avatar {
- @Nullable
- String getCurrentMount();
-
- @Nullable
- String getCurrentPet();
-
- boolean getSleep();
-
- @Nullable
- Stats getStats();
-
- @Nullable
- AvatarPreferences getPreferences();
-
- @Nullable
- Integer getGemCount();
-
- @Nullable
- Integer getHourglassCount();
-
- @Nullable
- Outfit getCostume();
- @Nullable
- Outfit getEquipped();
-
- boolean hasClass();
-
- boolean isValid();
-}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/Avatar.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/Avatar.kt
new file mode 100644
index 000000000..24e37bd57
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/Avatar.kt
@@ -0,0 +1,21 @@
+package com.habitrpg.android.habitica.models
+
+import com.habitrpg.android.habitica.models.user.Outfit
+import com.habitrpg.android.habitica.models.user.Stats
+
+/**
+ * Created by phillip on 29.06.17.
+ */
+interface Avatar {
+ val currentMount: String?
+ val currentPet: String?
+ val sleep: Boolean
+ val stats: Stats?
+ val preferences: AvatarPreferences?
+ val gemCount: Int
+ val hourglassCount: Int
+ val costume: Outfit?
+ val equipped: Outfit?
+ fun hasClass(): Boolean
+ fun isValid(): Boolean
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/AvatarPreferences.java b/Habitica/src/main/java/com/habitrpg/android/habitica/models/AvatarPreferences.java
deleted file mode 100644
index 36d4a4e6f..000000000
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/AvatarPreferences.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package com.habitrpg.android.habitica.models;
-
-import com.habitrpg.android.habitica.models.user.Hair;
-
-/**
- * Created by phillip on 15.09.17.
- */
-
-public interface AvatarPreferences {
-
- String getUserId();
-
- Hair getHair();
-
- boolean getCostume();
-
- boolean getSleep();
-
- String getShirt();
-
- String getSkin();
- String getSize();
-
- String getBackground();
-
- String getChair();
-
- boolean getDisableClasses();
-}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/AvatarPreferences.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/AvatarPreferences.kt
new file mode 100644
index 000000000..e271c00e6
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/AvatarPreferences.kt
@@ -0,0 +1,16 @@
+package com.habitrpg.android.habitica.models
+
+import com.habitrpg.android.habitica.models.user.Hair
+
+interface AvatarPreferences {
+ val userId: String?
+ val hair: Hair?
+ val costume: Boolean
+ val sleep: Boolean
+ val shirt: String?
+ val skin: String?
+ val size: String?
+ val background: String?
+ val chair: String?
+ val disableClasses: Boolean
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/HabitRpgClass.java b/Habitica/src/main/java/com/habitrpg/android/habitica/models/HabitRpgClass.java
deleted file mode 100644
index d7004f308..000000000
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/HabitRpgClass.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.habitrpg.android.habitica.models;
-
-/**
- * Created by MagicMicky on 16/03/14.
- */
-public enum HabitRpgClass {
- rogue,
- wizard,
- warrior,
- healer,
- base
-
-}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/PushDevice.java b/Habitica/src/main/java/com/habitrpg/android/habitica/models/PushDevice.java
deleted file mode 100644
index 7b5c1c1a0..000000000
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/PushDevice.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package com.habitrpg.android.habitica.models;
-
-import com.google.gson.annotations.Expose;
-import com.google.gson.annotations.SerializedName;
-
-/**
- * Created by keithholliday on 7/5/16.
- */
-public class PushDevice {
-
- @SerializedName("regId")
- @Expose
- private String regId;
-
- @SerializedName("type")
- @Expose
- private String type;
-
- public String getRegId() {
- return this.regId;
- }
-
- public void setRegId(String regId) {
- this.regId = regId;
- }
-
- public String getType() {
- return this.type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/PushDevice.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/PushDevice.kt
new file mode 100644
index 000000000..33a32afe9
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/PushDevice.kt
@@ -0,0 +1,14 @@
+package com.habitrpg.android.habitica.models
+
+import com.google.gson.annotations.Expose
+import com.google.gson.annotations.SerializedName
+
+class PushDevice {
+ @SerializedName("regId")
+ @Expose
+ var regId: String? = null
+
+ @SerializedName("type")
+ @Expose
+ var type: String? = null
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/Transaction.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/Transaction.kt
index 5829d6e93..da0fa66e0 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/Transaction.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/Transaction.kt
@@ -2,6 +2,5 @@ package com.habitrpg.android.habitica.models
class Transaction {
var receipt: String? = null
-
var signature: String? = null
}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/WorldState.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/WorldState.kt
index cb99a5444..76d268836 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/WorldState.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/WorldState.kt
@@ -1,8 +1,8 @@
package com.habitrpg.android.habitica.models
-import com.facebook.internal.Mutable
import com.habitrpg.android.habitica.models.inventory.QuestProgress
import com.habitrpg.android.habitica.models.inventory.QuestRageStrike
+import java.util.*
class WorldState {
@@ -11,4 +11,7 @@ class WorldState {
var progress: QuestProgress? = null
var rageStrikes: MutableList? = null
+ var currentEventKey: String? = null
+ var currentEventStartDate: Date? = null
+ var currentEventEndDate: Date? = null
}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Animal.java b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Animal.java
deleted file mode 100644
index 96c1b7f90..000000000
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Animal.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.habitrpg.android.habitica.models.inventory;
-
-public interface Animal {
-
- String getKey();
-
- void setKey(String key);
-
- String getText();
-
- void setText(String text);
-
- String getType();
-
- void setType(String type);
-
- String getAnimal();
-
- void setAnimal(String animal);
-
- String getColor();
-
- void setColor(String color);
-
- boolean getPremium();
-
- void setPremium(boolean premium);
-
- Integer getNumberOwned();
-
- void setNumberOwned(Integer numberOwned);
-
- Integer getTotalNumber();
-
- void setTotalNumber(Integer totalNumber);
-}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Animal.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Animal.kt
new file mode 100644
index 000000000..47a7e5255
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Animal.kt
@@ -0,0 +1,12 @@
+package com.habitrpg.android.habitica.models.inventory
+
+interface Animal {
+ var key: String?
+ var text: String?
+ var type: String?
+ var animal: String
+ var color: String
+ var premium: Boolean
+ var numberOwned: Int
+ var totalNumber: Int
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/CustomizationSet.java b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/CustomizationSet.java
deleted file mode 100644
index bcb82d9d5..000000000
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/CustomizationSet.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.habitrpg.android.habitica.models.inventory;
-
-import java.util.List;
-
-/**
- * Created by viirus on 19/01/16.
- */
-public class CustomizationSet {
-
- public String text;
- public String identifier;
- public Integer price;
- public boolean hasPurchasable;
-
- public List customizations;
-}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/CustomizationSet.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/CustomizationSet.kt
new file mode 100644
index 000000000..aa4ca8b4a
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/CustomizationSet.kt
@@ -0,0 +1,9 @@
+package com.habitrpg.android.habitica.models.inventory
+
+class CustomizationSet {
+ var text: String? = null
+ var identifier: String? = null
+ var price: Int = 0
+ var hasPurchasable = false
+ var customizations: MutableList = mutableListOf()
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Egg.java b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Egg.java
deleted file mode 100644
index 2c41352f2..000000000
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Egg.java
+++ /dev/null
@@ -1,88 +0,0 @@
-package com.habitrpg.android.habitica.models.inventory;
-
-import io.realm.RealmObject;
-import io.realm.annotations.PrimaryKey;
-
-public class Egg extends RealmObject implements Item {
-
- @PrimaryKey
- String key;
- String text, notes;
- Integer value;
- String adjective, mountText;
-
- Integer stableOwned, stableTotal;
-
- public String getAdjective() {
- return adjective;
- }
-
- public void setAdjective(String adjective) {
- this.adjective = adjective;
- }
-
- public String getMountText() {
- return mountText;
- }
-
- public void setMountText(String mountText) {
- this.mountText = mountText;
- }
-
- public Integer getStableOwned() {
- if (stableOwned == null) {
- stableOwned = 0;
- }
- return stableOwned;
- }
-
- public void setStableOwned(Integer stableOwned) {
- this.stableOwned = stableOwned;
- }
-
- public Integer getStableTotal() {
- return stableTotal;
- }
-
- public void setStableTotal(Integer stableTotal) {
- this.stableTotal = stableTotal;
- }
-
- public String getType() {
- return "eggs";
- }
-
- @Override
- public String getKey() {
- return key;
- }
-
- public String getText() {
- return text;
- }
-
- @Override
- public Integer getValue() {
- return value;
- }
-
- public void setText(String text) {
- this.text = text;
- }
-
- public void setValue(Integer value) {
- this.value = value;
- }
-
- public String getNotes() {
- return notes;
- }
-
- public void setNotes(String notes) {
- this.notes = notes;
- }
-
- public void setKey(String key) {
- this.key = key;
- }
-}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Egg.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Egg.kt
new file mode 100644
index 000000000..d237dbc69
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Egg.kt
@@ -0,0 +1,17 @@
+package com.habitrpg.android.habitica.models.inventory
+
+import io.realm.RealmObject
+import io.realm.annotations.PrimaryKey
+
+open class Egg : RealmObject(), Item {
+ @PrimaryKey
+ override var key: String = ""
+ override var text: String = ""
+ var notes: String? = null
+ override var value: Int = 0
+ var adjective: String? = null
+ var mountText: String? = null
+
+ override val type: String
+ get() = "eggs"
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Food.java b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Food.java
deleted file mode 100644
index 936adc6b2..000000000
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Food.java
+++ /dev/null
@@ -1,77 +0,0 @@
-package com.habitrpg.android.habitica.models.inventory;
-
-import io.realm.RealmObject;
-import io.realm.annotations.PrimaryKey;
-
-public class Food extends RealmObject implements Item {
-
- @PrimaryKey
- String key;
- String text, notes;
- Integer value;
- String target, article;
- Boolean canDrop;
-
- public String getTarget() {
- return target;
- }
-
- public void setTarget(String target) {
- this.target = target;
- }
-
- public String getArticle() {
- return article;
- }
-
- public void setArticle(String article) {
- this.article = article;
- }
-
- public Boolean getCanDrop() {
- return canDrop;
- }
-
- public void setCanDrop(Boolean canDrop) {
- this.canDrop = canDrop;
- }
-
- public String getType() {
- return "food";
- }
-
- @Override
- public String getKey() {
- return key;
- }
-
- @Override
- public String getText() {
- return text;
- }
-
- @Override
- public Integer getValue() {
- return value;
- }
-
- public void setText(String text) {
- this.text = text;
- }
-
- public String getNotes() {
- return notes;
- }
-
- public void setValue(Integer value) {
- this.value = value;
- }
-
- public void setNotes(String notes) {
- this.notes = notes;
- }
-
- public void setKey(String key) {
- this.key = key;
- }
-}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Food.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Food.kt
new file mode 100644
index 000000000..4f5f04cd6
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Food.kt
@@ -0,0 +1,17 @@
+package com.habitrpg.android.habitica.models.inventory
+
+import io.realm.RealmObject
+import io.realm.annotations.PrimaryKey
+
+open class Food : RealmObject(), Item {
+ @PrimaryKey
+ override var key: String = ""
+ override var text: String = ""
+ var notes: String? = null
+ override var value: Int = 0
+ var target: String? = null
+ var article: String? = null
+ var canDrop: Boolean? = null
+ override val type: String
+ get() = "food"
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/HatchingPotion.java b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/HatchingPotion.java
deleted file mode 100644
index 4d42ca4cd..000000000
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/HatchingPotion.java
+++ /dev/null
@@ -1,68 +0,0 @@
-package com.habitrpg.android.habitica.models.inventory;
-
-import io.realm.RealmObject;
-import io.realm.annotations.PrimaryKey;
-
-public class HatchingPotion extends RealmObject implements Item {
-
- @PrimaryKey
- String key;
- String text, notes;
- Integer value;
- Boolean limited, premium;
-
- public Boolean getLimited() {
- return limited;
- }
-
- public void setLimited(Boolean limited) {
- this.limited = limited;
- }
-
- public Boolean getPremium() {
- return premium;
- }
-
- public void setPremium(Boolean premium) {
- this.premium = premium;
- }
-
- @Override
- public String getType() {
- return "hatchingPotions";
- }
-
- @Override
- public String getKey() {
- return key;
- }
-
- public String getText() {
- return text;
- }
-
- @Override
- public Integer getValue() {
- return value;
- }
-
- public void setText(String text) {
- this.text = text;
- }
-
- public void setValue(Integer value) {
- this.value = value;
- }
-
- public String getNotes() {
- return notes;
- }
-
- public void setNotes(String notes) {
- this.notes = notes;
- }
-
- public void setKey(String key) {
- this.key = key;
- }
-}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/HatchingPotion.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/HatchingPotion.kt
new file mode 100644
index 000000000..5257fd502
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/HatchingPotion.kt
@@ -0,0 +1,16 @@
+package com.habitrpg.android.habitica.models.inventory
+
+import io.realm.RealmObject
+import io.realm.annotations.PrimaryKey
+
+open class HatchingPotion : RealmObject(), Item {
+ @PrimaryKey
+ override var key: String = ""
+ override var text: String = ""
+ var notes: String? = null
+ override var value: Int = 0
+ var limited: Boolean? = null
+ var premium: Boolean? = null
+ override val type: String
+ get() = "hatchingPotions"
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Item.java b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Item.java
deleted file mode 100644
index da0f3e08a..000000000
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Item.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.habitrpg.android.habitica.models.inventory;
-
-import io.realm.RealmModel;
-
-public interface Item extends RealmModel {
-
- String getType();
-
- String getKey();
-
- String getText();
-
- Integer getValue();
-}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Item.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Item.kt
new file mode 100644
index 000000000..0e39a4217
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Item.kt
@@ -0,0 +1,10 @@
+package com.habitrpg.android.habitica.models.inventory
+
+import io.realm.RealmModel
+
+interface Item : RealmModel {
+ val type: String
+ val key: String
+ val text: String
+ val value: Int
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Mount.java b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Mount.java
deleted file mode 100644
index 1fd23de3c..000000000
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Mount.java
+++ /dev/null
@@ -1,99 +0,0 @@
-package com.habitrpg.android.habitica.models.inventory;
-
-import io.realm.RealmObject;
-import io.realm.annotations.Ignore;
-import io.realm.annotations.PrimaryKey;
-
-public class Mount extends RealmObject implements Animal {
-
- @PrimaryKey
- String key;
- String animal, color, text, type;
- boolean premium;
-
- @Ignore
- private Integer numberOwned;
-
- @Ignore
- private Integer totalNumber;
-
- public String getKey() {
- return key;
- }
-
- public void setKey(String key) {
- this.key = key;
- }
-
- @Override
- public String getText() {
- return text;
- }
-
- @Override
- public void setText(String text) {
- this.text = text;
- }
-
- @Override
- public String getType() {
- return type;
- }
-
- @Override
- public void setType(String type) {
- this.type = type;
- }
-
- public String getAnimal() {
- if (animal == null) {
- return key.split("-")[0];
- }
- return animal;
- }
-
- public void setAnimal(String animal) {
- this.animal = animal;
- }
-
- public String getColor() {
- if (color == null) {
- return key.split("-")[1];
- }
- return color;
- }
-
- public void setColor(String color) {
- this.color = color;
- }
-
- public boolean getPremium() {
- return premium;
- }
-
- public void setPremium(boolean premium) {
- this.premium = premium;
- }
-
- public Integer getNumberOwned() {
- if (numberOwned == null) {
- return 0;
- }
- return numberOwned;
- }
-
- public void setNumberOwned(Integer numberOwned) {
- this.numberOwned = numberOwned;
- }
-
- public Integer getTotalNumber() {
- if (totalNumber == null) {
- return 0;
- }
- return totalNumber;
- }
-
- public void setTotalNumber(Integer totalNumber) {
- this.totalNumber = totalNumber;
- }
-}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Mount.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Mount.kt
new file mode 100644
index 000000000..3e4386536
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Mount.kt
@@ -0,0 +1,31 @@
+package com.habitrpg.android.habitica.models.inventory
+
+import io.realm.RealmObject
+import io.realm.annotations.Ignore
+import io.realm.annotations.PrimaryKey
+
+open class Mount : RealmObject(), Animal {
+ @PrimaryKey
+ override var key: String? = null
+ override var animal: String = ""
+ get() {
+ return if (field.isBlank()) {
+ key?.split("-")?.toTypedArray()?.get(0) ?: ""
+ } else field
+ }
+ override var color: String = ""
+ get() {
+ return if (field.isBlank()) {
+ key?.split("-")?.toTypedArray()?.get(1) ?: ""
+ } else field
+ }
+ override var text: String? = null
+ override var type: String? = null
+ override var premium = false
+
+
+ @Ignore
+ override var numberOwned: Int = 0
+ @Ignore
+ override var totalNumber: Int = 0
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Pet.java b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Pet.java
deleted file mode 100644
index 642c2c1fc..000000000
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Pet.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package com.habitrpg.android.habitica.models.inventory;
-
-import io.realm.RealmObject;
-import io.realm.annotations.Ignore;
-import io.realm.annotations.PrimaryKey;
-
-public class Pet extends RealmObject implements Animal{
-
- @PrimaryKey
- String key;
- String animal, color, text, type;
- boolean premium;
-
- @Ignore
- private Integer numberOwned;
-
- @Ignore
- private Integer totalNumber;
-
- public String getKey() {
- return key;
- }
-
- public void setKey(String key) {
- this.key = key;
- }
-
- @Override
- public String getText() {
- return text;
- }
-
-
- @Override
- public void setText(String text) {
- this.text = text;
- }
-
- @Override
- public String getType() {
- return type;
- }
-
- @Override
- public void setType(String type) {
- this.type = type;
- }
-
- public String getAnimal() {
- if (animal == null) {
- return getKey().split("-")[0];
- }
- return animal;
- }
-
- public void setAnimal(String animal) {
- this.animal = animal;
- }
-
- public String getColor() {
- if (color == null) {
- return getKey().split("-")[1];
- }
- return color;
- }
-
- public void setColor(String color) {
- this.color = color;
- }
-
- public boolean getPremium() {
- return premium;
- }
-
- public void setPremium(boolean premium) {
- this.premium = premium;
- }
-
- public Integer getNumberOwned() {
- if (numberOwned == null) {
- return 0;
- }
- return numberOwned;
- }
-
- public void setNumberOwned(Integer numberOwned) {
- this.numberOwned = numberOwned;
- }
-
- public Integer getTotalNumber() {
- if (totalNumber == null) {
- return 0;
- }
-
- return totalNumber;
- }
-
- public void setTotalNumber(Integer totalNumber) {
- this.totalNumber = totalNumber;
- }
-}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Pet.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Pet.kt
new file mode 100644
index 000000000..7d2d69566
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Pet.kt
@@ -0,0 +1,30 @@
+package com.habitrpg.android.habitica.models.inventory
+
+import io.realm.RealmObject
+import io.realm.annotations.Ignore
+import io.realm.annotations.PrimaryKey
+
+open class Pet : RealmObject(), Animal {
+ @PrimaryKey
+ override var key: String? = null
+ override var animal: String = ""
+ get() {
+ return if (field.isBlank()) {
+ key?.split("-")?.toTypedArray()?.get(0) ?: ""
+ } else field
+ }
+ override var color: String = ""
+ get() {
+ return if (field.isBlank()) {
+ key?.split("-")?.toTypedArray()?.get(1) ?: ""
+ } else field
+ }
+ override var text: String? = null
+ override var type: String? = null
+ override var premium = false
+
+ @Ignore
+ override var numberOwned: Int = 0
+ @Ignore
+ override var totalNumber: Int = 0
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestColors.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestColors.kt
index ac7a25e30..12394fa6d 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestColors.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestColors.kt
@@ -17,19 +17,19 @@ open class QuestColors : RealmObject() {
var light: String? = null
var extralight: String? = null
- var darkColor: Int = 0
+ val darkColor: Int
get() {
return Color.parseColor(dark)
}
- var mediumColor: Int = 0
+ val mediumColor: Int
get() {
return Color.parseColor(medium)
}
- var lightColor: Int = 0
+ val lightColor: Int
get() {
return Color.parseColor(light)
}
- var extraLightColor: Int = 0
+ val extraLightColor: Int
get() {
return Color.parseColor(extralight)
}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestContent.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestContent.kt
index a5d84d7a6..b2996fe41 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestContent.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestContent.kt
@@ -7,17 +7,17 @@ import io.realm.annotations.PrimaryKey
open class QuestContent : RealmObject(), Item {
@PrimaryKey
- internal var key: String = ""
+ override var key: String = ""
set(value) {
field = value
drop?.key = value
colors?.key = value
boss?.key = value
}
- internal var text: String = ""
+ override var text: String = ""
var notes: String = ""
var completion: String = ""
- internal var value: Int = 0
+ override var value: Int = 0
var previous: String? = null
var lvl: Int = 0
var isCanBuy: Boolean = false
@@ -49,33 +49,8 @@ open class QuestContent : RealmObject(), Item {
val isBossQuest: Boolean
get() = this.boss != null
- override fun getType(): String {
- return "quests"
- }
-
- override fun getKey(): String {
- return key
- }
-
- override fun getText(): String {
- return text
- }
-
- override fun getValue(): Int? {
- return value
- }
-
- fun setText(text: String) {
- this.text = text
- }
-
- fun setValue(value: Int) {
- this.value = value
- }
-
- fun setKey(key: String) {
- this.key = key
- }
+ override val type: String
+ get() = "quests"
fun getCollectWithKey(key: String): QuestCollect? {
for (collect in this.collect ?: emptyList()) {
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestDropItem.java b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestDropItem.java
deleted file mode 100644
index f50a5155f..000000000
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestDropItem.java
+++ /dev/null
@@ -1,97 +0,0 @@
-package com.habitrpg.android.habitica.models.inventory;
-
-import io.realm.RealmObject;
-import io.realm.annotations.PrimaryKey;
-
-/**
- * Created by phillip on 25.07.17.
- */
-
-public class QuestDropItem extends RealmObject {
-
- @PrimaryKey
- private String combinedKey;
- private String questKey;
- private String key;
- private String type;
- private String text;
- private boolean onlyOwner;
- private int count;
-
- public QuestDropItem() {
- super();
- }
-
- public String getCombinedKey() {
- return combinedKey;
- }
-
- public void setCombinedKey(String combinedKey) {
- this.combinedKey = combinedKey;
- }
-
- public String getQuestKey() {
- return questKey;
- }
-
- public void setQuestKey(String questKey) {
- this.questKey = questKey;
- combinedKey = questKey+key;
- }
-
- public String getKey() {
- return key;
- }
-
- public void setKey(String key) {
- this.key = key;
- combinedKey = questKey+key;
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public String getText() {
- return text;
- }
-
- public void setText(String text) {
- this.text = text;
- }
-
- public int getCount() {
- return count;
- }
-
- public void setCount(int count) {
- this.count = count;
- }
-
- public String getImageName() {
- if ("quests".equals(type)) {
- return "inventory_quest_scroll_"+key;
- } else if ("eggs".equals(type)) {
- return "Pet_Egg_" + getKey();
- } else
- if ("food".equals(type)) {
- return "Pet_Food_" + getKey();
- } else
- if ("hatchingPotions".equals(type)) {
- return "Pet_HatchingPotion_" + getKey();
- }
- return "shop_"+key;
- }
-
- public boolean isOnlyOwner() {
- return onlyOwner;
- }
-
- public void setOnlyOwner(boolean onlyOwner) {
- this.onlyOwner = onlyOwner;
- }
-}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestDropItem.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestDropItem.kt
new file mode 100644
index 000000000..0efd92ee9
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestDropItem.kt
@@ -0,0 +1,35 @@
+package com.habitrpg.android.habitica.models.inventory
+
+import io.realm.RealmObject
+import io.realm.annotations.PrimaryKey
+
+/**
+ * Created by phillip on 25.07.17.
+ */
+open class QuestDropItem : RealmObject() {
+ @PrimaryKey
+ var combinedKey: String? = null
+ var questKey: String? = null
+ set(value) {
+ field = value
+ combinedKey = value + key
+ }
+ var key: String = ""
+ set(value) {
+ field = value
+ combinedKey = questKey + value
+ }
+ var type: String? = null
+ var text: String? = null
+ var isOnlyOwner = false
+ var count = 0
+
+ val imageName: String
+ get() = when (type) {
+ "quests" -> "inventory_quest_scroll_$key"
+ "eggs" -> "Pet_Egg_$key"
+ "food" -> "Pet_Food_$key"
+ "hatchingPotions" -> "Pet_HatchingPotion_$key"
+ else -> "shop_$key"
+ }
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestDrops.java b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestDrops.java
deleted file mode 100644
index f76dc7c18..000000000
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestDrops.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package com.habitrpg.android.habitica.models.inventory;
-
-import io.realm.RealmList;
-import io.realm.RealmObject;
-import io.realm.annotations.PrimaryKey;
-
-/**
- * Created by phillip on 25.07.17.
- */
-
-public class QuestDrops extends RealmObject {
-
- @PrimaryKey
- private String key;
- public int gp;
- public int exp;
- public String unlock;
- private RealmList items;
-
- public QuestDrops() {
- super();
- }
-
- public String getKey() {
- return key;
- }
-
- public void setKey(String key) {
- this.key = key;
-
- if (items != null) {
- for (QuestDropItem item : items) {
- item.setQuestKey(key);
- }
- }
- }
-
-
- public RealmList getItems() {
- return items;
- }
-
- public void setItems(RealmList items) {
- this.items = items;
-
- if (items != null) {
- for (QuestDropItem item : items) {
- item.setQuestKey(key);
- }
- }
- }
-}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestDrops.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestDrops.kt
new file mode 100644
index 000000000..e4b5ae7ea
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestDrops.kt
@@ -0,0 +1,25 @@
+package com.habitrpg.android.habitica.models.inventory
+
+import io.realm.RealmList
+import io.realm.RealmObject
+import io.realm.annotations.PrimaryKey
+
+/**
+ * Created by phillip on 25.07.17.
+ */
+open class QuestDrops : RealmObject() {
+ @PrimaryKey
+ var key: String? = null
+ set(value) {
+ field = value
+ items?.forEach { it.questKey = key }
+ }
+ var gp = 0
+ var exp = 0
+ var unlock: String? = null
+ var items: RealmList? = null
+ set(value) {
+ field = value
+ items?.forEach { it.questKey = key }
+ }
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestProgress.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestProgress.kt
index eed63d322..8ab4e1d8e 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestProgress.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/QuestProgress.kt
@@ -11,6 +11,7 @@ open class QuestProgress : RealmObject() {
var key: String? = null
var hp: Double = 0.0
var rage: Double = 0.0
+ var collectedItems: Int = 0
var collect: RealmList? = null
var down: Float = 0.0f
var up: Float = 0.0f
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/SpecialItem.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/SpecialItem.kt
index dcee52123..bcaf614a8 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/SpecialItem.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/SpecialItem.kt
@@ -7,30 +7,16 @@ import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
open class SpecialItem : RealmObject(), Item {
+ override val type: String
+ get() = "special"
@PrimaryKey
- internal var key: String = ""
- internal var text: String = ""
+ override var key: String = ""
+ override var text: String = ""
internal var notes: String = ""
- internal var value: Int? = null
+ override var value: Int = 0
var isMysteryItem: Boolean = false
- override fun getType(): String {
- return "special"
- }
-
- override fun getKey(): String {
- return key
- }
-
- override fun getText(): String {
- return text
- }
-
- override fun getValue(): Int? {
- return value
- }
-
companion object {
fun makeMysteryItem(context: Context): SpecialItem {
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/StableSection.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/StableSection.kt
new file mode 100644
index 000000000..a8b390a9d
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/StableSection.kt
@@ -0,0 +1,7 @@
+package com.habitrpg.android.habitica.models.inventory
+
+class StableSection(val key: Any?, val text: String) {
+
+ var ownedCount = 0
+ var totalCount = 0
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/members/Member.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/members/Member.kt
index 4a80be93c..f59028103 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/members/Member.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/members/Member.kt
@@ -10,7 +10,6 @@ import io.realm.annotations.PrimaryKey
open class Member : RealmObject(), Avatar {
-
@PrimaryKey
@SerializedName("_id")
var id: String? = null
@@ -27,7 +26,7 @@ open class Member : RealmObject(), Avatar {
this.inbox?.userId = subID
}
if (preferences != null && preferences?.isManaged != true) {
- preferences?.setUserId(subID)
+ preferences?.userId = subID
}
if (this.profile != null && this.profile?.isManaged != true) {
this.profile?.userId = subID
@@ -45,7 +44,13 @@ open class Member : RealmObject(), Avatar {
this.authentication?.userId = subID
}
}
- private var stats: Stats? = null
+ override var stats: Stats? = null
+ set(value) {
+ field = value
+ if (value != null && this.id != null && !value.isManaged) {
+ field?.userId = this.id
+ }
+ }
var inbox: Inbox? = null
set(inbox) {
field = inbox
@@ -53,7 +58,17 @@ open class Member : RealmObject(), Avatar {
inbox.userId = this.id
}
}
- private var preferences: MemberPreferences? = null
+ override var preferences: MemberPreferences? = null
+ set(value) {
+ field = value
+ if (value != null && this.id != null && !value.isManaged) {
+ field?.userId = this.id
+ }
+ }
+ override val gemCount: Int
+ get() = 0
+ override val hourglassCount: Int
+ get() = 0
var profile: Profile? = null
set(profile) {
field = profile
@@ -96,11 +111,23 @@ open class Member : RealmObject(), Avatar {
items.userId = this.id
}
}
- private var costume: Outfit? = null
- private var equipped: Outfit? = null
+ override var costume: Outfit? = null
+ set(value) {
+ field = value
+ if (value != null && this.id != null) {
+ field?.userId = this.id + "costume"
+ }
+ }
+ override var equipped: Outfit? = null
+ set(value) {
+ field = value
+ if (value != null && this.id != null) {
+ field?.userId = this.id + "equipped"
+ }
+ }
- private var currentMount: String? = null
- private var currentPet: String? = null
+ override var currentMount: String? = null
+ override var currentPet: String? = null
var participatesInQuest: Boolean? = null
var loginIncentives: Int = 0
@@ -120,79 +147,10 @@ open class Member : RealmObject(), Avatar {
val formattedUsername: String?
get() = if (username != null) "@$username" else null
- override fun getPreferences(): MemberPreferences? {
- return preferences
- }
-
- fun setPreferences(preferences: MemberPreferences?) {
- this.preferences = preferences
- if (preferences != null && this.id != null && !preferences.isManaged) {
- preferences.setUserId(this.id ?: "")
- }
- }
-
- override fun getStats(): Stats? {
- return stats
- }
-
- fun setStats(stats: Stats?) {
- this.stats = stats
- if (stats != null && this.id != null && !stats.isManaged) {
- stats.userId = this.id
- }
- }
-
- override fun getGemCount(): Int? {
- return 0
- }
-
- override fun getHourglassCount(): Int? {
- return 0
- }
-
- override fun getCostume(): Outfit? {
- return costume
- }
-
- fun setCostume(costume: Outfit?) {
- this.costume = costume
- if (costume != null && this.id != null) {
- costume.userId = this.id + "costume"
- }
- }
-
- override fun getEquipped(): Outfit? {
- return equipped
- }
-
override fun hasClass(): Boolean {
return preferences?.disableClasses == false && stats?.habitClass?.isNotEmpty() == true
}
- fun setEquipped(equipped: Outfit?) {
- this.equipped = equipped
- if (equipped != null && this.id != null) {
- equipped.userId = this.id + "equipped"
- }
- }
-
- override fun getCurrentMount(): String? {
- return currentMount
- }
-
- fun setCurrentMount(currentMount: String) {
- this.currentMount = currentMount
- }
-
- override fun getCurrentPet(): String? {
- return currentPet
- }
-
- fun setCurrentPet(currentPet: String) {
- this.currentPet = currentPet
- }
-
- override fun getSleep(): Boolean {
- return getPreferences()?.sleep ?: false
- }
+ override val sleep: Boolean
+ get() = preferences?.sleep ?: false
}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/members/MemberPreferences.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/members/MemberPreferences.kt
index 011d2a9c8..d764ba74e 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/members/MemberPreferences.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/members/MemberPreferences.kt
@@ -10,104 +10,31 @@ import io.realm.annotations.PrimaryKey
open class MemberPreferences : RealmObject(), AvatarPreferences {
@PrimaryKey
- private var userId: String? = null
-
- private var hair: Hair? = null
- private var costume: Boolean = false
- private var disableClasses: Boolean = false
- private var sleep: Boolean = false
- private var shirt: String? = null
- private var skin: String? = null
- private var size: String? = null
- private var background: String? = null
- private var chair: String? = null
-
- fun setUserId(userId: String) {
- this.userId = userId
- if (hair != null && !hair!!.isManaged) {
- hair!!.userId = userId
+ override var userId: String? = null
+ set(value) {
+ field = value
+ if (hair?.isManaged != true) {
+ hair?.userId = userId
}
}
- override fun getUserId(): String? {
- return userId
- }
-
- override fun getHair(): Hair? {
- return hair
- }
-
- fun setHair(hair: Hair) {
- this.hair = hair
- }
-
- override fun getCostume(): Boolean {
- return costume
- }
-
- fun setCostume(costume: Boolean) {
- this.costume = costume
- }
-
- override fun getDisableClasses(): Boolean {
- return disableClasses
- }
-
- fun setDisableClasses(disableClasses: Boolean) {
- this.disableClasses = disableClasses
- }
-
- override fun getSleep(): Boolean {
- return sleep
- }
-
- fun setSleep(sleep: Boolean) {
- this.sleep = sleep
- }
-
- override fun getShirt(): String? {
- return shirt
- }
-
- fun setShirt(shirt: String) {
- this.shirt = shirt
- }
-
- override fun getSkin(): String? {
- return skin
- }
-
- fun setSkin(skin: String) {
- this.skin = skin
- }
-
- override fun getSize(): String? {
- return size
- }
-
- fun setSize(size: String) {
- this.size = size
- }
-
- override fun getBackground(): String? {
- return background
- }
-
- fun setBackground(background: String) {
- this.background = background
- }
-
- override fun getChair(): String? {
- return if (chair != null && chair != "none") {
- if (chair!!.length > 5 && chair!!.substring(0, 6) != "chair_") {
- chair
+ override var hair: Hair? = null
+ override var costume: Boolean = false
+ override var disableClasses: Boolean = false
+ override var sleep: Boolean = false
+ override var shirt: String? = null
+ override var skin: String? = null
+ override var size: String? = null
+ override var background: String? = null
+ override var chair: String? = null
+ get() {
+ return if (field != null && field != "none") {
+ if (field!!.length > 5 && field?.substring(0, 6) != "chair_") {
+ field
} else {
- "chair_" + chair!!
+ "chair_$field"
}
} else null
}
- fun setChair(chair: String) {
- this.chair = chair
- }
}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/notifications/Reward.java b/Habitica/src/main/java/com/habitrpg/android/habitica/models/notifications/Reward.java
deleted file mode 100644
index e44e08293..000000000
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/notifications/Reward.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.habitrpg.android.habitica.models.notifications;
-
-/**
- * Created by krh12 on 12/1/2016.
- */
-
-public class Reward {
- public String key;
-}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/notifications/Reward.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/notifications/Reward.kt
new file mode 100644
index 000000000..165d46669
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/notifications/Reward.kt
@@ -0,0 +1,5 @@
+package com.habitrpg.android.habitica.models.notifications
+
+class Reward {
+ var key: String? = null
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/promotions/FallExtraGemsHabiticaPromotion.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/promotions/FallExtraGemsHabiticaPromotion.kt
new file mode 100644
index 000000000..83b28dabe
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/promotions/FallExtraGemsHabiticaPromotion.kt
@@ -0,0 +1,142 @@
+package com.habitrpg.android.habitica.models.promotions
+
+import android.content.Context
+import android.graphics.Color
+import android.graphics.drawable.BitmapDrawable
+import android.graphics.drawable.Drawable
+import android.graphics.drawable.ShapeDrawable
+import android.view.View
+import androidx.core.content.ContextCompat
+import com.habitrpg.android.habitica.R
+import com.habitrpg.android.habitica.databinding.FragmentGemPurchaseBinding
+import com.habitrpg.android.habitica.databinding.PurchaseGemViewBinding
+import com.habitrpg.android.habitica.extensions.DateUtils
+import com.habitrpg.android.habitica.helpers.MainNavigationController
+import com.habitrpg.android.habitica.ui.fragments.PromoInfoFragment
+import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper
+import com.habitrpg.android.habitica.ui.views.promo.PromoMenuView
+import java.text.SimpleDateFormat
+import java.util.*
+
+class FallExtraGemsHabiticaPromotion(startDate: Date?, endDate: Date?) : HabiticaPromotion() {
+ override val identifier: String
+ get() = "fall_extra_gems"
+ override val promoType: PromoType
+ get() = PromoType.GEMS_AMOUNT
+ override val startDate: Date = startDate ?: DateUtils.createDate(2020, 8, 22)
+ override val endDate: Date = endDate ?: DateUtils.createDate(2020, 8, 30)
+
+ override fun pillBackgroundDrawable(context: Context): Drawable {
+ return ContextCompat.getDrawable(context, R.drawable.fall_promo_pill_bg) ?: ShapeDrawable()
+ }
+
+ override fun backgroundColor(context: Context): Int {
+ return ContextCompat.getColor(context, R.color.gray_10)
+ }
+
+ override fun promoBackgroundDrawable(context: Context): Drawable {
+ return ContextCompat.getDrawable(context, R.drawable.layout_rounded_bg_gray_10)
+ ?: ShapeDrawable()
+ }
+
+ override fun buttonDrawable(context: Context): Drawable {
+ return ContextCompat.getDrawable(context, R.drawable.fall_promo_button_bg)
+ ?: ShapeDrawable()
+ }
+
+ override fun configurePromoMenuView(view: PromoMenuView) {
+ val context = view.context
+ view.setBackgroundColor(backgroundColor(context))
+ view.setTitleImage(ContextCompat.getDrawable(context, R.drawable.fall_promo_title))
+ view.setTitleText(null)
+ view.setSubtitleImage(ContextCompat.getDrawable(context, R.drawable.fall_promo_menu_description))
+ view.setSubtitleText(null)
+
+ view.setDecoration(
+ ContextCompat.getDrawable(context, R.drawable.fall_promo_menu_left),
+ ContextCompat.getDrawable(context, R.drawable.fall_promo_menu_right)
+ )
+
+ view.binding.button.backgroundTintList = ContextCompat.getColorStateList(context, R.color.gray_1)
+ view.binding.button.setText(R.string.learn_more)
+ view.binding.button.setTextColor(ContextCompat.getColor(context, R.color.white))
+ view.binding.button.setOnClickListener {
+ menuOnNavigation(context)
+ }
+ }
+
+ override fun menuOnNavigation(context: Context) {
+ MainNavigationController.navigate(R.id.promoInfoFragment)
+ }
+
+ override fun configurePurchaseBanner(binding: FragmentGemPurchaseBinding) {
+ val context = binding.root.context
+ binding.promoBanner.visibility = View.VISIBLE
+ binding.promoBanner.background = promoBackgroundDrawable(context)
+ binding.promoBannerLeftImage.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.fall_promo_banner_left))
+ binding.promoBannerRightImage.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.fall_promo_banner_right))
+ binding.promoBannerTitleImage.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.fall_promo_title))
+ val formatter = SimpleDateFormat("MMM d", Locale.getDefault())
+ binding.promoBannerDurationView.text = context.getString(R.string.x_to_y,
+ formatter.format(startDate),
+ formatter.format(endDate))
+ binding.promoBannerDurationView.setTextColor(Color.parseColor("#FEE2B6"))
+ }
+
+ override fun configureGemView(binding: PurchaseGemViewBinding, regularAmount: Int) {
+ val context = binding.root.context
+ binding.root.background = promoBackgroundDrawable(context)
+ binding.purchaseButton.background = buttonDrawable(context)
+ val colors = listOf(
+ ContextCompat.getColor(context, R.color.red_10),
+ ContextCompat.getColor(context, R.color.blue_50),
+ ContextCompat.getColor(context, R.color.green_50),
+ ContextCompat.getColor(context, R.color.brand_300)
+ ).shuffled()
+ val drawable = BitmapDrawable(context.resources,
+ HabiticaIconsHelper.imageOfFallGemPromoBG(
+ colors[0],
+ colors[1],
+ colors[2],
+ colors[3]
+ ))
+ binding.amountBackgroundLeft.background = drawable
+ binding.amountBackgroundRight.background = drawable
+ binding.gemAmount.setTextColor(Color.parseColor("#FEE2B6"))
+ binding.gemsTextView.setTextColor(Color.parseColor("#FEE2B6"))
+ binding.footerTextView.visibility = View.VISIBLE
+ binding.footerTextView.text = context.getString(R.string.usually_x_gems, regularAmount)
+ binding.gemAmount.text = when (regularAmount) {
+ 4 -> "5"
+ 21 -> "30"
+ 42 -> "60"
+ 84 -> "125"
+ else -> regularAmount.toString()
+ }
+ }
+
+ override fun configureInfoFragment(fragment: PromoInfoFragment) {
+ val context = fragment.context ?: return
+ fragment.binding?.promoBanner?.background = promoBackgroundDrawable(context)
+ fragment.binding?.promoBannerLeftImage?.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.fall_promo_info_left))
+ fragment.binding?.promoBannerRightImage?.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.fall_promo_info_right))
+ fragment.binding?.promoBannerTitleImage?.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.fall_promo_title))
+ fragment.binding?.promoBannerSubtitleView?.setText(R.string.limited_event)
+ fragment.binding?.promoBannerDurationView?.setTextColor(Color.parseColor("#FEE2B6"))
+ val formatter = SimpleDateFormat("MMM d", Locale.getDefault())
+ fragment.binding?.promoBannerDurationView?.text = context.getString(R.string.x_to_y,
+ formatter.format(startDate),
+ formatter.format(endDate))
+ fragment.binding?.promoBannerDurationView?.setTextColor(ContextCompat.getColor(context, R.color.white))
+ fragment.binding?.promptText?.setText(R.string.fall_promo_info_prompt)
+ fragment.binding?.promptText?.setTextColor(Color.parseColor("#F78E2F"))
+ fragment.binding?.promptButton?.background = buttonDrawable(context)
+ fragment.binding?.promptButton?.setText(R.string.view_gem_bundles)
+ fragment.binding?.promptButton?.setTextColor(ContextCompat.getColor(context, R.color.white))
+ fragment.binding?.promptButton?.setOnClickListener { MainNavigationController.navigate(R.id.gemPurchaseActivity) }
+
+ fragment.binding?.instructionDescriptionView?.text = context.getString(R.string.fall_promo_info_instructions, formatter.format(startDate), formatter.format(endDate))
+ val limitationsFormatter = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.LONG, SimpleDateFormat.LONG)
+ fragment.binding?.limitationsDescriptionView?.text = context.getString(R.string.gems_promo_info_limitations, limitationsFormatter.format(startDate), limitationsFormatter.format(endDate))
+ }
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/promotions/HabiticaPromotion.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/promotions/HabiticaPromotion.kt
new file mode 100644
index 000000000..bc8e23e76
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/promotions/HabiticaPromotion.kt
@@ -0,0 +1,46 @@
+package com.habitrpg.android.habitica.models.promotions
+
+import android.content.Context
+import android.graphics.drawable.Drawable
+import com.habitrpg.android.habitica.databinding.FragmentGemPurchaseBinding
+import com.habitrpg.android.habitica.databinding.PurchaseGemViewBinding
+import com.habitrpg.android.habitica.ui.fragments.PromoInfoFragment
+import com.habitrpg.android.habitica.ui.views.promo.PromoMenuView
+import java.util.*
+
+enum class PromoType {
+ GEMS_AMOUNT,
+ GEMS_PRICE,
+ SUBSCRIPTION
+}
+
+abstract class HabiticaPromotion {
+ abstract val identifier: String
+ abstract val promoType: PromoType
+
+ abstract val startDate: Date
+ abstract val endDate: Date
+
+ abstract fun pillBackgroundDrawable(context: Context): Drawable
+ abstract fun backgroundColor(context: Context): Int
+ abstract fun promoBackgroundDrawable(context: Context): Drawable
+
+ abstract fun buttonDrawable(context: Context): Drawable
+
+ abstract fun configurePromoMenuView(view: PromoMenuView)
+ abstract fun menuOnNavigation(context: Context)
+
+ abstract fun configurePurchaseBanner(binding: FragmentGemPurchaseBinding)
+
+ abstract fun configureGemView(binding: PurchaseGemViewBinding, regularAmount: Int)
+ abstract fun configureInfoFragment(fragment: PromoInfoFragment)
+}
+
+fun getHabiticaPromotionFromKey(key: String, startDate: Date?, endDate: Date?): HabiticaPromotion? {
+ return when (key) {
+ "fall_extra_gems", "fall2020", "testFall2020" -> FallExtraGemsHabiticaPromotion(startDate, endDate)
+ "spooky_extra_gems", "fall2020SecondPromo", "spooky2020" -> SpookyExtraGemsHabiticaPromotion(startDate, endDate)
+ else -> null
+ }
+}
+
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/promotions/SpookyExtraGemsHabiticaPromo.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/promotions/SpookyExtraGemsHabiticaPromo.kt
new file mode 100644
index 000000000..29b846256
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/promotions/SpookyExtraGemsHabiticaPromo.kt
@@ -0,0 +1,130 @@
+package com.habitrpg.android.habitica.models.promotions
+
+import android.content.Context
+import android.graphics.Color
+import android.graphics.drawable.BitmapDrawable
+import android.graphics.drawable.Drawable
+import android.graphics.drawable.ShapeDrawable
+import android.view.View
+import androidx.core.content.ContextCompat
+import com.habitrpg.android.habitica.R
+import com.habitrpg.android.habitica.databinding.FragmentGemPurchaseBinding
+import com.habitrpg.android.habitica.databinding.PurchaseGemViewBinding
+import com.habitrpg.android.habitica.extensions.DateUtils
+import com.habitrpg.android.habitica.helpers.MainNavigationController
+import com.habitrpg.android.habitica.ui.fragments.PromoInfoFragment
+import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper
+import com.habitrpg.android.habitica.ui.views.promo.PromoMenuView
+import java.text.SimpleDateFormat
+import java.util.*
+
+class SpookyExtraGemsHabiticaPromotion(startDate: Date?, endDate: Date?) : HabiticaPromotion() {
+ override val identifier: String
+ get() = "spooky_extra_gems"
+ override val promoType: PromoType
+ get() = PromoType.GEMS_AMOUNT
+ override val startDate: Date = startDate ?: DateUtils.createDate(2020, 9, 29)
+ override val endDate: Date = endDate ?: DateUtils.createDate(2020, 10, 2)
+
+ override fun pillBackgroundDrawable(context: Context): Drawable {
+ return ContextCompat.getDrawable(context, R.drawable.spooky_promo_pill_bg) ?: ShapeDrawable()
+ }
+
+ override fun backgroundColor(context: Context): Int {
+ return ContextCompat.getColor(context, R.color.gray_10)
+ }
+
+ override fun promoBackgroundDrawable(context: Context): Drawable {
+ return ContextCompat.getDrawable(context, R.drawable.layout_rounded_bg_gray_10)
+ ?: ShapeDrawable()
+ }
+
+ override fun buttonDrawable(context: Context): Drawable {
+ return ContextCompat.getDrawable(context, R.drawable.spooky_promo_button_bg)
+ ?: ShapeDrawable()
+ }
+
+ override fun configurePromoMenuView(view: PromoMenuView) {
+ val context = view.context
+ view.setBackgroundColor(backgroundColor(context))
+ view.setTitleImage(ContextCompat.getDrawable(context, R.drawable.spooky_promo_title))
+ view.setTitleText(null)
+ view.setSubtitleImage(ContextCompat.getDrawable(context, R.drawable.spooky_promo_menu_description))
+ view.setSubtitleText(null)
+
+ view.setDecoration(
+ ContextCompat.getDrawable(context, R.drawable.spooky_promo_menu_left),
+ ContextCompat.getDrawable(context, R.drawable.spooky_promo_menu_right)
+ )
+
+ view.binding.button.backgroundTintList = ContextCompat.getColorStateList(context, R.color.gray_1)
+ view.binding.button.setText(R.string.learn_more)
+ view.binding.button.setTextColor(ContextCompat.getColor(context, R.color.white))
+ view.binding.button.setOnClickListener {
+ menuOnNavigation(context)
+ }
+ }
+
+ override fun menuOnNavigation(context: Context) {
+ MainNavigationController.navigate(R.id.promoInfoFragment)
+ }
+
+ override fun configurePurchaseBanner(binding: FragmentGemPurchaseBinding) {
+ val context = binding.root.context
+ binding.promoBanner.visibility = View.VISIBLE
+ binding.promoBanner.background = promoBackgroundDrawable(context)
+ binding.promoBannerLeftImage.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.spooky_promo_banner_left))
+ binding.promoBannerRightImage.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.spooky_promo_banner_right))
+ binding.promoBannerTitleImage.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.spooky_promo_title))
+ val formatter = SimpleDateFormat("MMM d", Locale.getDefault())
+ binding.promoBannerDurationView.text = context.getString(R.string.x_to_y,
+ formatter.format(startDate),
+ formatter.format(endDate))
+ binding.promoBannerDurationView.setTextColor(ContextCompat.getColor(context, R.color.white))
+ }
+
+ override fun configureGemView(binding: PurchaseGemViewBinding, regularAmount: Int) {
+ val context = binding.root.context
+ binding.root.background = promoBackgroundDrawable(context)
+ binding.purchaseButton.background = buttonDrawable(context)
+ val drawable = BitmapDrawable(context.resources,
+ HabiticaIconsHelper.imageOfSpookyGemPromoBG())
+ binding.amountBackgroundLeft.background = drawable
+ binding.amountBackgroundRight.background = drawable
+ binding.gemAmount.setTextColor(Color.parseColor("#FEE2B6"))
+ binding.gemsTextView.setTextColor(Color.parseColor("#FEE2B6"))
+ binding.footerTextView.visibility = View.VISIBLE
+ binding.footerTextView.text = context.getString(R.string.usually_x_gems, regularAmount)
+ binding.gemAmount.text = when (regularAmount) {
+ 4 -> "5"
+ 21 -> "30"
+ 42 -> "60"
+ 84 -> "125"
+ else -> regularAmount.toString()
+ }
+ }
+
+ override fun configureInfoFragment(fragment: PromoInfoFragment) {
+ val context = fragment.context ?: return
+ fragment.binding?.promoBanner?.background = promoBackgroundDrawable(context)
+ fragment.binding?.promoBannerLeftImage?.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.spooky_promo_info_left))
+ fragment.binding?.promoBannerRightImage?.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.spooky_promo_info_right))
+ fragment.binding?.promoBannerTitleImage?.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.spooky_promo_title))
+ fragment.binding?.promoBannerSubtitleView?.setText(R.string.limited_event)
+ fragment.binding?.promoBannerDurationView?.setTextColor(ContextCompat.getColor(context, R.color.white))
+ val formatter = SimpleDateFormat("MMM d", Locale.getDefault())
+ fragment.binding?.promoBannerDurationView?.text = context.getString(R.string.x_to_y,
+ formatter.format(startDate),
+ formatter.format(endDate))
+ fragment.binding?.promoBannerDurationView?.setTextColor(ContextCompat.getColor(context, R.color.white))
+ fragment.binding?.promptText?.setText(R.string.spooky_promo_info_prompt)
+ fragment.binding?.promptText?.setTextColor(ContextCompat.getColor(context, R.color.orange_50))
+ fragment.binding?.promptButton?.background = buttonDrawable(context)
+ fragment.binding?.promptButton?.setText(R.string.view_gem_bundles)
+ fragment.binding?.promptButton?.setTextColor(ContextCompat.getColor(context, R.color.white))
+ fragment.binding?.promptButton?.setOnClickListener { MainNavigationController.navigate(R.id.gemPurchaseActivity) }
+
+ fragment.binding?.instructionDescriptionView?.text = context.getString(R.string.spooky_promo_info_instructions, formatter.format(startDate), formatter.format(endDate))
+ val limitationsFormatter = SimpleDateFormat.getDateTimeInstance()
+ fragment.binding?.limitationsDescriptionView?.text = context.getString(R.string.gems_promo_info_limitations, limitationsFormatter.format(startDate), limitationsFormatter.format(endDate)) }
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/responses/TaskDirectionDataTemp.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/responses/TaskDirectionDataTemp.kt
index 42f4e3e7c..3d31263ba 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/responses/TaskDirectionDataTemp.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/responses/TaskDirectionDataTemp.kt
@@ -9,6 +9,7 @@ class TaskDirectionDataTemp {
class TaskDirectionDataQuest {
var progressDelta: Double = 0.0
+ var collection: Int = 0
}
class TaskDirectionDataDrop {
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/responses/TaskScoringResult.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/responses/TaskScoringResult.kt
index bd20eb9b1..c27faede5 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/responses/TaskScoringResult.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/responses/TaskScoringResult.kt
@@ -9,4 +9,5 @@ class TaskScoringResult {
var manaDelta: Double? = null
var hasLeveledUp: Boolean = false
var questDamage: Double? = null
+ var questItemsFound: Int? = null
}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/shops/ShopItem.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/shops/ShopItem.kt
index 5e7fa29f4..a6c52fd8c 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/shops/ShopItem.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/shops/ShopItem.kt
@@ -69,13 +69,11 @@ open class ShopItem : RealmObject() {
get() = "pets" == purchaseType || "mounts" == purchaseType
val canPurchaseBulk: Boolean
- get() = "eggs" == purchaseType || "hatchingPotions" == purchaseType || "food" == purchaseType
+ get() = "eggs" == purchaseType || "hatchingPotions" == purchaseType || "food" == purchaseType || "gems" == purchaseType
fun canAfford(user: User?, quantity: Int): Boolean = when(currency) {
"gold" -> (value * quantity) <= user?.stats?.gp ?: 0.0
- "gems" -> (value * quantity) <= user?.gemCount?.toDouble() ?: 0.0
- "hourglasses" -> (value * quantity) <= user?.hourglassCount?.toDouble() ?: 0.0
- else -> false
+ else -> true
}
override fun equals(other: Any?): Boolean {
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/social/FindUsernameResult.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/social/FindUsernameResult.kt
index 89c187510..fe6387683 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/social/FindUsernameResult.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/social/FindUsernameResult.kt
@@ -4,7 +4,6 @@ import com.google.gson.annotations.SerializedName
import com.habitrpg.android.habitica.models.user.Authentication
import com.habitrpg.android.habitica.models.user.ContributorInfo
import com.habitrpg.android.habitica.models.user.Profile
-import io.realm.annotations.PrimaryKey
class FindUsernameResult {
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/social/UserStyles.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/social/UserStyles.kt
index cd6b32c81..a6e246422 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/social/UserStyles.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/social/UserStyles.kt
@@ -1,7 +1,6 @@
package com.habitrpg.android.habitica.models.social
import com.habitrpg.android.habitica.models.Avatar
-import com.habitrpg.android.habitica.models.AvatarPreferences
import com.habitrpg.android.habitica.models.user.Items
import com.habitrpg.android.habitica.models.user.Outfit
import com.habitrpg.android.habitica.models.user.Preferences
@@ -18,47 +17,32 @@ open class UserStyles : RealmObject(), Avatar {
preferences?.userId = id
items?.userId = id
}
- override fun getCurrentMount(): String? {
- return items?.currentMount
- }
- override fun getCurrentPet(): String? {
- return items?.currentPet
- }
+ override val currentMount: String?
+ get() = items?.currentMount
- override fun getSleep(): Boolean {
- return false
- }
+ override val currentPet: String?
+ get() = items?.currentPet
- override fun getStats(): Stats? {
- return stats
- }
+ override val sleep: Boolean
+ get() = false
- override fun getPreferences(): AvatarPreferences? {
- return preferences
- }
+ override val gemCount: Int
+ get() = 0
+ override val hourglassCount: Int
+ get() = 0
- override fun getGemCount(): Int {
- return 0
- }
+ override val costume: Outfit?
+ get() = items?.gear?.costume
- override fun getHourglassCount(): Int {
- return 0
- }
-
- override fun getCostume(): Outfit? {
- return items?.gear?.costume
- }
-
- override fun getEquipped(): Outfit? {
- return items?.gear?.equipped
- }
+ override val equipped: Outfit?
+ get() = items?.gear?.equipped
override fun hasClass(): Boolean {
return false
}
- private var stats: Stats? = null
- private var preferences: Preferences? = null
+ override var stats: Stats? = null
+ override var preferences: Preferences? = null
private var items: Items? = null
}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/tasks/Task.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/tasks/Task.kt
index 60af9bf85..7cdf310a2 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/tasks/Task.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/tasks/Task.kt
@@ -9,7 +9,6 @@ import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.models.Tag
import com.habitrpg.android.habitica.models.user.Stats
import com.habitrpg.android.habitica.ui.helpers.MarkdownParser
-import io.reactivex.functions.Consumer
import io.realm.RealmList
import io.realm.RealmObject
import io.realm.annotations.Ignore
@@ -123,7 +122,7 @@ open class Task : RealmObject, Parcelable {
this.value < -20 -> return R.color.maroon_50
this.value < -10 -> return R.color.red_50
this.value < -1 -> return R.color.orange_50
- this.value < 1 -> return R.color.yellow_50
+ this.value < 1 -> return R.color.yellow_10
this.value < 5 -> return R.color.green_50
this.value < 10 -> return R.color.teal_50
else -> R.color.blue_50
@@ -136,7 +135,7 @@ open class Task : RealmObject, Parcelable {
this.value < -20 -> return R.color.maroon_10
this.value < -10 -> return R.color.red_10
this.value < -1 -> return R.color.orange_10
- this.value < 1 -> return R.color.yellow_10
+ this.value < 1 -> return R.color.yellow_5
this.value < 5 -> return R.color.green_10
this.value < 10 -> return R.color.teal_10
else -> R.color.blue_10
@@ -199,7 +198,7 @@ open class Task : RealmObject, Parcelable {
return this.parsedText ?: ""
}
- MarkdownParser.parseMarkdownAsync(this.text, Consumer { parsedText ->
+ MarkdownParser.parseMarkdownAsync(this.text, { parsedText ->
this.parsedText = parsedText
callback(parsedText)
})
@@ -213,7 +212,7 @@ open class Task : RealmObject, Parcelable {
}
if (notes?.isNotEmpty() == true) {
- MarkdownParser.parseMarkdownAsync(notes, Consumer { parsedText ->
+ MarkdownParser.parseMarkdownAsync(notes, { parsedText ->
parsedNotes = parsedText
callback(parsedText)
})
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/tasks/TaskList.java b/Habitica/src/main/java/com/habitrpg/android/habitica/models/tasks/TaskList.java
deleted file mode 100644
index 9cb9c6ffa..000000000
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/tasks/TaskList.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.habitrpg.android.habitica.models.tasks;
-
-import java.util.Map;
-
-public class TaskList {
-
- public Map tasks;
-
-}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/tasks/TaskList.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/tasks/TaskList.kt
new file mode 100644
index 000000000..2b754b324
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/tasks/TaskList.kt
@@ -0,0 +1,5 @@
+package com.habitrpg.android.habitica.models.tasks
+
+class TaskList {
+ var tasks: MutableMap = mutableMapOf()
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/tasks/TaskTag.java b/Habitica/src/main/java/com/habitrpg/android/habitica/models/tasks/TaskTag.java
deleted file mode 100644
index 979cda714..000000000
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/tasks/TaskTag.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package com.habitrpg.android.habitica.models.tasks;
-
-
-import com.habitrpg.android.habitica.models.Tag;
-
-import io.realm.RealmObject;
-import io.realm.annotations.PrimaryKey;
-
-/**
- * Created by viirus on 08/08/15.
- */
-
-public class TaskTag extends RealmObject {
-
- public Tag tag;
- public Task task;
- @PrimaryKey
- String id;
- private String tagId = "";
- private String taskId = "";
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public Tag getTag() {
- return tag;
- }
-
- public void setTag(Tag tag) {
- this.tag = tag;
- tagId = tag.getId();
- updatePrimaryKey();
- }
-
- public Task getTask() {
- return task;
- }
-
- public void setTask(Task task) {
- this.task = task;
-
- taskId = task.getId();
- updatePrimaryKey();
- }
-
- private void updatePrimaryKey() {
- this.id = taskId + "_" + tagId;
- }
-}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/tasks/TaskTag.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/tasks/TaskTag.kt
new file mode 100644
index 000000000..cc8e02636
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/tasks/TaskTag.kt
@@ -0,0 +1,29 @@
+package com.habitrpg.android.habitica.models.tasks
+
+import com.habitrpg.android.habitica.models.Tag
+import io.realm.RealmObject
+import io.realm.annotations.PrimaryKey
+
+open class TaskTag : RealmObject() {
+ var tag: Tag? = null
+ set(value) {
+ field = value
+ tagId = tag?.id ?: ""
+ updatePrimaryKey()
+ }
+ var task: Task? = null
+ set(value) {
+ field = value
+ taskId = task?.id ?: ""
+ updatePrimaryKey()
+ }
+
+ @PrimaryKey
+ var id: String? = null
+ private var tagId = ""
+ private var taskId: String? = ""
+
+ private fun updatePrimaryKey() {
+ id = taskId + "_" + tagId
+ }
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/tasks/TasksOrder.java b/Habitica/src/main/java/com/habitrpg/android/habitica/models/tasks/TasksOrder.java
deleted file mode 100644
index 227566ab8..000000000
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/tasks/TasksOrder.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.habitrpg.android.habitica.models.tasks;
-
-import java.util.List;
-
-public class TasksOrder {
-
- List habits;
- List dailys;
- List todos;
- List rewards;
-
- public List getHabits() {
- return habits;
- }
-
- public void setHabits(List habits) {
- this.habits = habits;
- }
-
- public List getDailys() {
- return dailys;
- }
-
- public void setDailys(List dailys) {
- this.dailys = dailys;
- }
-
- public List getTodos() {
- return todos;
- }
-
- public void setTodos(List todos) {
- this.todos = todos;
- }
-
- public List getRewards() {
- return rewards;
- }
-
- public void setRewards(List rewards) {
- this.rewards = rewards;
- }
-}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/tasks/TasksOrder.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/tasks/TasksOrder.kt
new file mode 100644
index 000000000..e345c1ccc
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/tasks/TasksOrder.kt
@@ -0,0 +1,8 @@
+package com.habitrpg.android.habitica.models.tasks
+
+class TasksOrder {
+ var habits: List = listOf()
+ var dailys: List = listOf()
+ var todos: List = listOf()
+ var rewards: List = listOf()
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/Buffs.java b/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/Buffs.java
deleted file mode 100644
index 21898ac0b..000000000
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/Buffs.java
+++ /dev/null
@@ -1,108 +0,0 @@
-package com.habitrpg.android.habitica.models.user;
-
-import com.google.gson.annotations.SerializedName;
-
-import io.realm.RealmObject;
-import io.realm.annotations.PrimaryKey;
-
-public class Buffs extends RealmObject {
-
- @PrimaryKey
- private String userId;
-
- public Float con, str, per;
- @SerializedName("int")
- public Float _int; private Boolean snowball;
- private Boolean streaks;
- private Boolean seafoam;
- private Boolean spookySparkles;
- private Boolean shinySeed;
-
- public Buffs() {
- this(false, false);
- }
-
- public Buffs(Boolean snowball, Boolean streaks) {
- this.snowball = snowball;
- this.streaks = streaks;
- }
-
- public Boolean getSnowball() {
- return snowball != null ? snowball : Boolean.FALSE;
- }
-
- public void setSnowball(Boolean snowball) {
- this.snowball = snowball;
- }
-
- public Boolean getSeafoam() {
- return seafoam != null ? seafoam : Boolean.FALSE;
- }
-
- public void setSeafoam(Boolean seafoam) {
- this.seafoam = seafoam;
- }
-
- public Boolean getSpookySparkles() {
- return spookySparkles != null ? spookySparkles : Boolean.FALSE;
- }
-
- public void setSpookySparkles(Boolean spookySparkles) {
- this.spookySparkles = spookySparkles;
- }
-
- public Boolean getShinySeed() {
- return shinySeed != null ? shinySeed : Boolean.FALSE;
- }
-
- public void setShinySeed(Boolean shinySeed) {
- this.shinySeed = shinySeed;
- }
-
- public Boolean getStreaks() {
- return streaks != null ? streaks : Boolean.FALSE;
- }
-
- public void setStreaks(Boolean streaks) {
- this.streaks = streaks;
- }
-
- public void merge(Buffs stats) {
- if (stats == null) {
- return;
- }
- this.con = stats.con != null ? stats.con : this.con;
- this.str = stats.str != null ? stats.str : this.str;
- this.per = stats.per != null ? stats.per : this.per;
- this._int = stats._int != null ? stats._int : this._int;
- this.snowball = stats.snowball != null ? stats.snowball : this.snowball;
- this.streaks = stats.streaks != null ? stats.streaks : this.streaks;
- this.seafoam = stats.seafoam != null ? stats.seafoam : this.seafoam;
- this.shinySeed = stats.shinySeed != null ? stats.shinySeed : this.shinySeed;
- this.spookySparkles = stats.spookySparkles != null ? stats.spookySparkles : this.spookySparkles;
- }
-
- public Float getStr() {
- return str;
- }
-
- public Float get_int() {
- return _int;
- }
-
- public Float getCon() {
- return con;
- }
-
- public Float getPer() {
- return per;
- }
-
- public String getUserId() {
- return userId;
- }
-
- public void setUserId(String userId) {
- this.userId = userId;
- }
-}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/Buffs.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/Buffs.kt
new file mode 100644
index 000000000..d366f518c
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/Buffs.kt
@@ -0,0 +1,42 @@
+package com.habitrpg.android.habitica.models.user
+
+import com.google.gson.annotations.SerializedName
+import io.realm.RealmObject
+import io.realm.annotations.PrimaryKey
+
+open class Buffs : RealmObject() {
+ @PrimaryKey
+ var userId: String? = null
+ var con: Float? = null
+ var str: Float? = null
+ var per: Float? = null
+
+ @SerializedName("int")
+ var _int: Float? = null
+ var seafoam: Boolean? = null
+ get() { return field ?: false }
+ var spookySparkles: Boolean? = null
+ get() { return field ?: false }
+ var shinySeed: Boolean? = null
+ get() { return field ?: false }
+ var snowball: Boolean? = null
+ get() { return field ?: false }
+ var streaks: Boolean? = null
+ get() { return field ?: false }
+
+
+ fun merge(stats: Buffs?) {
+ if (stats == null) {
+ return
+ }
+ con = if (stats.con != null) stats.con else con
+ str = if (stats.str != null) stats.str else str
+ per = if (stats.per != null) stats.per else per
+ _int = if (stats._int != null) stats._int else _int
+ snowball = if (stats.snowball != null) stats.snowball else snowball
+ streaks = if (stats.streaks != null) stats.streaks else streaks
+ seafoam = if (stats.seafoam != null) stats.seafoam else seafoam
+ shinySeed = if (stats.shinySeed != null) stats.shinySeed else shinySeed
+ spookySparkles = if (stats.spookySparkles != null) stats.spookySparkles else spookySparkles
+ }
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/ContributorInfo.java b/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/ContributorInfo.java
deleted file mode 100644
index 1eb1589a5..000000000
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/ContributorInfo.java
+++ /dev/null
@@ -1,94 +0,0 @@
-package com.habitrpg.android.habitica.models.user;
-
-import android.util.SparseArray;
-import android.util.SparseIntArray;
-
-import com.habitrpg.android.habitica.R;
-
-import java.util.HashMap;
-
-import io.realm.RealmObject;
-import io.realm.annotations.PrimaryKey;
-
-public class ContributorInfo extends RealmObject {
-
- public static final SparseIntArray CONTRIBUTOR_COLOR_DICT;
-
- static {
- CONTRIBUTOR_COLOR_DICT = new SparseIntArray();
- CONTRIBUTOR_COLOR_DICT.put(0, R.color.contributor_0);
- CONTRIBUTOR_COLOR_DICT.put(1, R.color.contributor_1);
- CONTRIBUTOR_COLOR_DICT.put(2, R.color.contributor_2);
- CONTRIBUTOR_COLOR_DICT.put(3, R.color.contributor_3);
- CONTRIBUTOR_COLOR_DICT.put(4, R.color.contributor_4);
- CONTRIBUTOR_COLOR_DICT.put(5, R.color.contributor_5);
- CONTRIBUTOR_COLOR_DICT.put(6, R.color.contributor_6);
- CONTRIBUTOR_COLOR_DICT.put(7, R.color.contributor_7);
- CONTRIBUTOR_COLOR_DICT.put(8, R.color.contributor_mod);
- CONTRIBUTOR_COLOR_DICT.put(9, R.color.contributor_staff);
- }
-
- @PrimaryKey
- private String userId;
-
- public User user;
- private boolean admin;
- private String contributions;
- private int level;
- private String text;
-
- public Boolean getAdmin() {
- return this.admin;
- }
-
- public void setAdmin(Boolean admin) {
- this.admin = admin;
- }
-
- public String getContributions() {
- return this.contributions;
- }
-
- public void setContributions(String contributions) {
- this.contributions = contributions;
- }
-
- public int getLevel() {
- return this.level;
- }
-
- public void setLevel(int level) {
- this.level = level;
- }
-
- public String getText() {
- return this.text;
- }
-
- public void setText(String text) {
- this.text = text;
- }
-
- public int getContributorColor() {
- int rColor = android.R.color.black;
-
-
- if (CONTRIBUTOR_COLOR_DICT.get(this.level, -1) > 0) {
- rColor = CONTRIBUTOR_COLOR_DICT.get(this.level);
- }
-
- return rColor;
- }
-
- public int getContributorForegroundColor() {
- return android.R.color.white;
- }
-
- public String getUserId() {
- return userId;
- }
-
- public void setUserId(String userId) {
- this.userId = userId;
- }
-}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/ContributorInfo.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/ContributorInfo.kt
new file mode 100644
index 000000000..a3aa155b7
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/ContributorInfo.kt
@@ -0,0 +1,42 @@
+package com.habitrpg.android.habitica.models.user
+
+import io.realm.RealmObject
+import android.util.SparseIntArray
+import com.habitrpg.android.habitica.models.user.ContributorInfo
+import com.habitrpg.android.habitica.R
+import io.realm.annotations.PrimaryKey
+
+open class ContributorInfo : RealmObject() {
+ companion object {
+ val CONTRIBUTOR_COLOR_DICT: SparseIntArray = SparseIntArray()
+
+ init {
+ CONTRIBUTOR_COLOR_DICT.put(0, R.color.contributor_0)
+ CONTRIBUTOR_COLOR_DICT.put(1, R.color.contributor_1)
+ CONTRIBUTOR_COLOR_DICT.put(2, R.color.contributor_2)
+ CONTRIBUTOR_COLOR_DICT.put(3, R.color.contributor_3)
+ CONTRIBUTOR_COLOR_DICT.put(4, R.color.contributor_4)
+ CONTRIBUTOR_COLOR_DICT.put(5, R.color.contributor_5)
+ CONTRIBUTOR_COLOR_DICT.put(6, R.color.contributor_6)
+ CONTRIBUTOR_COLOR_DICT.put(7, R.color.contributor_7)
+ CONTRIBUTOR_COLOR_DICT.put(8, R.color.contributor_mod)
+ CONTRIBUTOR_COLOR_DICT.put(9, R.color.contributor_staff)
+ }
+ }
+
+ @PrimaryKey
+ var userId: String? = null
+ var user: User? = null
+ var admin = false
+ var contributions: String? = null
+ var level = 0
+ var text: String? = null
+ val contributorColor: Int
+ get() {
+ var rColor = R.color.text_primary
+ if (CONTRIBUTOR_COLOR_DICT[level, -1] > 0) {
+ rColor = CONTRIBUTOR_COLOR_DICT[level]
+ }
+ return rColor
+ }
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/Flags.java b/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/Flags.java
deleted file mode 100644
index 402f66d67..000000000
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/Flags.java
+++ /dev/null
@@ -1,150 +0,0 @@
-package com.habitrpg.android.habitica.models.user;
-
-import com.habitrpg.android.habitica.models.TutorialStep;
-
-import java.util.List;
-
-import io.realm.RealmList;
-import io.realm.RealmObject;
-import io.realm.annotations.PrimaryKey;
-
-public class Flags extends RealmObject {
-
- @PrimaryKey
- private String userId;
-
- RealmList