? = 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/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/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/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/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/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/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/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/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/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/ContributorInfo.java b/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/ContributorInfo.java
deleted file mode 100644
index 1b940aa02..000000000
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/ContributorInfo.java
+++ /dev/null
@@ -1,86 +0,0 @@
-package com.habitrpg.android.habitica.models.user;
-
-import android.util.SparseIntArray;
-
-import com.habitrpg.android.habitica.R;
-
-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 = R.color.text_primary;
-
- if (CONTRIBUTOR_COLOR_DICT.get(this.level, -1) > 0) {
- rColor = CONTRIBUTOR_COLOR_DICT.get(this.level);
- }
-
- return rColor;
- }
-
- 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/Purchases.java b/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/Purchases.java
deleted file mode 100644
index 89f35152e..000000000
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/Purchases.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package com.habitrpg.android.habitica.models.user;
-
-import java.util.List;
-
-import io.realm.RealmList;
-import io.realm.RealmObject;
-import io.realm.annotations.PrimaryKey;
-
-public class Purchases extends RealmObject {
-
- @PrimaryKey
- private String userId;
-
- public RealmList customizations;
- User user;
- private SubscriptionPlan plan;
-
- public List getCustomizations() {
- return customizations;
- }
-
- public void setCustomizations(RealmList customizations) {
- this.customizations = customizations;
- }
-
- public SubscriptionPlan getPlan() {
- return plan;
- }
-
- public void setPlan(SubscriptionPlan plan) {
- this.plan = plan;
- }
-
- 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/Purchases.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/Purchases.kt
new file mode 100644
index 000000000..37f8f0f3c
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/Purchases.kt
@@ -0,0 +1,14 @@
+package com.habitrpg.android.habitica.models.user
+
+import io.realm.RealmList
+import io.realm.RealmObject
+import io.realm.annotations.PrimaryKey
+
+open class Purchases : RealmObject() {
+ @PrimaryKey
+ var userId: String? = null
+ @JvmField
+ var customizations: RealmList? = null
+ var user: User? = null
+ var plan: SubscriptionPlan? = null
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/Stats.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/Stats.kt
index 1b413f3a7..b04867e22 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/Stats.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/Stats.kt
@@ -3,7 +3,6 @@ package com.habitrpg.android.habitica.models.user
import android.content.Context
import com.google.gson.annotations.SerializedName
import com.habitrpg.android.habitica.R
-import com.habitrpg.android.habitica.models.HabitRpgClass
import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
@@ -102,10 +101,6 @@ open class Stats : RealmObject() {
this.maxMP = if (stats.maxMP != null) stats.maxMP else this.maxMP
}
- fun setHabitClass(habitRpgClass: HabitRpgClass) {
- habitClass = habitRpgClass.toString()
- }
-
companion object {
const val STRENGTH = "str"
const val INTELLIGENCE = "int"
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/SubscriptionPlanConsecutive.java b/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/SubscriptionPlanConsecutive.java
deleted file mode 100644
index 2bade8afe..000000000
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/SubscriptionPlanConsecutive.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package com.habitrpg.android.habitica.models.user;
-
-import io.realm.RealmObject;
-import io.realm.annotations.PrimaryKey;
-
-public class SubscriptionPlanConsecutive extends RealmObject {
-
- @PrimaryKey
- private String customerId;
-
- SubscriptionPlan subscriptionPlan;
- private int trinkets;
- private int gemCapExtra;
- private int offset;
- private int count;
-
- public int getTrinkets() {
- return trinkets;
- }
-
- public void setTrinkets(int trinkets) {
- this.trinkets = trinkets;
- }
-
- public int getGemCapExtra() {
- return gemCapExtra;
- }
-
- public void setGemCapExtra(int gemCapExtra) {
- this.gemCapExtra = gemCapExtra;
- }
-
- public int getOffset() {
- return offset;
- }
-
- public void setOffset(int offset) {
- this.offset = offset;
- }
-
- public int getCount() {
- return count;
- }
-
- public void setCount(int count) {
- this.count = count;
- }
-
- public String getCustomerId() {
- return customerId;
- }
-
- public void setCustomerId(String customerId) {
- this.customerId = customerId;
- }
-}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/SubscriptionPlanConsecutive.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/SubscriptionPlanConsecutive.kt
new file mode 100644
index 000000000..05541cd6d
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/SubscriptionPlanConsecutive.kt
@@ -0,0 +1,14 @@
+package com.habitrpg.android.habitica.models.user
+
+import io.realm.RealmObject
+import io.realm.annotations.PrimaryKey
+
+open class SubscriptionPlanConsecutive : RealmObject() {
+ @PrimaryKey
+ var customerId: String? = null
+ var subscriptionPlan: SubscriptionPlan? = null
+ var trinkets = 0
+ var gemCapExtra = 0
+ var offset = 0
+ var count = 0
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/SuppressedModals.java b/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/SuppressedModals.java
deleted file mode 100644
index 77b40827b..000000000
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/SuppressedModals.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package com.habitrpg.android.habitica.models.user;
-
-import io.realm.RealmObject;
-import io.realm.annotations.PrimaryKey;
-
-public class SuppressedModals extends RealmObject {
-
- @PrimaryKey
- private String userId;
-
- Preferences preferences;
- private Boolean streak, raisePet, hatchPet, levelUp;
-
- public Boolean getStreak() {
- return streak;
- }
-
- public void setStreak(Boolean streak) {
- this.streak = streak;
- }
-
- public Boolean getRaisePet() {
- return raisePet;
- }
-
- public void setRaisePet(Boolean raisePet) {
- this.raisePet = raisePet;
- }
-
- public Boolean getHatchPet() {
- return hatchPet;
- }
-
- public void setHatchPet(Boolean hatchPet) {
- this.hatchPet = hatchPet;
- }
-
- public Boolean getLevelUp() {
- return levelUp;
- }
-
- public void setLevelUp(Boolean levelUp) {
- this.levelUp = levelUp;
- }
-
- 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/SuppressedModals.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/SuppressedModals.kt
new file mode 100644
index 000000000..ed69c1996
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/SuppressedModals.kt
@@ -0,0 +1,14 @@
+package com.habitrpg.android.habitica.models.user
+
+import io.realm.RealmObject
+import io.realm.annotations.PrimaryKey
+
+open class SuppressedModals : RealmObject() {
+ @PrimaryKey
+ var userId: String? = null
+ var preferences: Preferences? = null
+ var streak: Boolean? = null
+ var raisePet: Boolean? = null
+ var hatchPet: Boolean? = null
+ var levelUp: Boolean? = null
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/Training.java b/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/Training.java
deleted file mode 100644
index 1e7154f48..000000000
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/Training.java
+++ /dev/null
@@ -1,68 +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 Training extends RealmObject {
-
- @PrimaryKey
- private String userId;
-
- Stats stats;
- public Float con, str, per;
- @SerializedName("int")
- public Float _int;
-
- public Float getCon() {
- return con != null ? con : Float.valueOf(0);
- }
-
- public void setCon(Float con) {
- this.con = con;
- }
-
- public Float getStr() {
- return str != null ? str : Float.valueOf(0);
- }
-
- public void setStr(Float str) {
- this.str = str;
- }
-
- public Float getPer() {
- return per != null ? per : Float.valueOf(0);
- }
-
- public void setPer(Float per) {
- this.per = per;
- }
-
- public Float get_int() {
- return _int != null ? _int : Float.valueOf(0);
- }
-
- public void set_int(Float _int) {
- this._int = _int;
- }
-
- public void merge(Training 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;
- }
-
- 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/Training.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/Training.kt
new file mode 100644
index 000000000..94819837d
--- /dev/null
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/user/Training.kt
@@ -0,0 +1,27 @@
+package com.habitrpg.android.habitica.models.user
+
+import com.google.gson.annotations.SerializedName
+import io.realm.RealmObject
+import io.realm.annotations.PrimaryKey
+
+open class Training : RealmObject() {
+ @PrimaryKey
+ var userId: String? = null
+ var stats: Stats? = null
+ var con: Float = 0f
+ var str: Float = 0f
+ var per: Float = 0f
+
+ @SerializedName("int")
+ var _int: Float = 0f
+
+ fun merge(stats: Training?) {
+ if (stats == null) {
+ return
+ }
+ con = stats.con
+ str = stats.str
+ per = stats.per
+ _int = stats._int
+ }
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/AvatarWithBarsViewModel.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/AvatarWithBarsViewModel.kt
index e479b872f..0789c334a 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/AvatarWithBarsViewModel.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/AvatarWithBarsViewModel.kt
@@ -65,7 +65,7 @@ class AvatarWithBarsViewModel(private val context: Context, private val binding:
if (!user.hasClass()) {
setUserLevel(context, binding.lvlTv, stats.lvl)
} else {
- setUserLevelWithClass(context, binding.lvlTv, stats.lvl, capitalize(userClass), stats.habitClass)
+ setUserLevelWithClass(context, binding.lvlTv, stats.lvl, userClass.capitalize(Locale.getDefault()), stats.habitClass)
}
setHpBarData(stats.hp?.toFloat() ?: 0.toFloat(), stats.maxHealth ?: 0)
@@ -78,8 +78,8 @@ class AvatarWithBarsViewModel(private val context: Context, private val binding:
binding.currencyView.gold = stats.gp ?: 0.0
if (user is User) {
- binding.currencyView.hourglasses = user.hourglassCount?.toDouble() ?: 0.0
- binding.currencyView.gems = user.gemCount?.toDouble() ?: 0.0
+ binding.currencyView.hourglasses = user.hourglassCount.toDouble()
+ binding.currencyView.gems = user.gemCount.toDouble()
}
binding.currencyView.setOnClickListener {
@@ -138,8 +138,5 @@ class AvatarWithBarsViewModel(private val context: Context, private val binding:
drawable?.setBounds(0, 0, drawable.minimumWidth, drawable.minimumHeight)
textView.setCompoundDrawables(drawable, null, null, null)
}
-
- private fun capitalize(s: String) =
- s.substring(0, 1).toUpperCase(Locale.getDefault()) + s.substring(1)
}
}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/BaseActivity.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/BaseActivity.kt
index 2673cf02c..7ef143ced 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/BaseActivity.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/BaseActivity.kt
@@ -3,7 +3,7 @@ package com.habitrpg.android.habitica.ui.activities
import android.content.Context
import android.content.SharedPreferences
import android.content.res.Configuration
-import android.os.Build
+import android.content.res.Resources
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
@@ -19,6 +19,7 @@ import com.habitrpg.android.habitica.components.UserComponent
import com.habitrpg.android.habitica.events.ShowConnectionProblemEvent
import com.habitrpg.android.habitica.extensions.getThemeColor
import com.habitrpg.android.habitica.extensions.isUsingNightModeResources
+import com.habitrpg.android.habitica.extensions.updateStatusBarColor
import com.habitrpg.android.habitica.helpers.LanguageHelper
import com.habitrpg.android.habitica.ui.helpers.ToolbarColorHelper
import com.habitrpg.android.habitica.ui.views.dialogs.HabiticaAlertDialog
@@ -57,10 +58,7 @@ abstract class BaseActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
val languageHelper = LanguageHelper(sharedPreferences.getString("language", "en"))
- Locale.setDefault(languageHelper.locale)
- val configuration = Configuration()
- configuration.setLocale(languageHelper.locale)
- resources.updateConfiguration(configuration, resources.displayMetrics)
+ resources.forceLocale(languageHelper.locale)
delegate.localNightMode = when (sharedPreferences.getString("theme_mode", "system")) {
"light" -> AppCompatDelegate.MODE_NIGHT_NO
"dark" -> AppCompatDelegate.MODE_NIGHT_YES
@@ -134,12 +132,10 @@ abstract class BaseActivity : AppCompatActivity() {
} else {
window.navigationBarColor = getThemeColor(R.attr.colorPrimaryDark)
}
- if (!isNightMode && modernHeaderStyle && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- window.statusBarColor = getThemeColor(R.attr.headerBackgroundColor)
- window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
+ if (!isNightMode && modernHeaderStyle) {
+ window.updateStatusBarColor(getThemeColor(R.attr.headerBackgroundColor), true)
} else {
- window.statusBarColor = getThemeColor(R.attr.statusBarBackground)
- window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
+ window.updateStatusBarColor(getThemeColor(R.attr.statusBarBackground), false)
}
if (currentTheme != null && theme != currentTheme) {
@@ -201,3 +197,10 @@ abstract class BaseActivity : AppCompatActivity() {
startActivity(intent)
}
}
+
+private fun Resources.forceLocale(locale: Locale) {
+ Locale.setDefault(locale)
+ val configuration = Configuration()
+ configuration.setLocale(locale)
+ updateConfiguration(configuration, displayMetrics)
+}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/ChallengeFormActivity.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/ChallengeFormActivity.kt
index 5445a66c2..80747891f 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/ChallengeFormActivity.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/ChallengeFormActivity.kt
@@ -209,7 +209,7 @@ class ChallengeFormActivity : BaseActivity() {
val intent = intent
val bundle = intent.extras
- challengeTasks = ChallengeTasksRecyclerViewAdapter(null, 0, this, "", null, false, true)
+ challengeTasks = ChallengeTasksRecyclerViewAdapter(null, 0, this, "", false, true)
compositeSubscription.add(challengeTasks.taskOpenEvents.subscribe {
if (it.isValid) {
openNewTaskActivity(it.type, it)
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/GroupInviteActivity.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/GroupInviteActivity.kt
index 02485b00b..8f6322ce6 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/GroupInviteActivity.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/GroupInviteActivity.kt
@@ -133,24 +133,7 @@ class GroupInviteActivity : BaseActivity() {
binding.tabLayout.setupWithViewPager(binding.viewPager)
}
- private fun handleUserReceived(user: User) {
- if (this.userIdToInvite == null) {
- return
- }
-
- val inviteData = HashMap()
- val invites = ArrayList()
- userIdToInvite?.let {
- invites.add(it)
- }
- inviteData["uuids"] = invites
-
- compositeSubscription.add(this.socialRepository.inviteToGroup(user.party?.id ?: "", inviteData)
- .subscribe({ }, RxErrorHandler.handleEmptyError()))
- }
-
companion object {
-
const val RESULT_SEND_INVITES = 100
const val USER_IDS_KEY = "userIDs"
const val IS_EMAIL_KEY = "isEmail"
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/MainActivity.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/MainActivity.kt
index d44dc8cdb..744c40a09 100755
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/MainActivity.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/activities/MainActivity.kt
@@ -13,7 +13,6 @@ import android.graphics.Bitmap
import android.graphics.Canvas
import android.os.Build
import android.os.Bundle
-import android.os.Handler
import android.util.Log
import android.view.*
import android.widget.FrameLayout
@@ -37,10 +36,7 @@ import com.habitrpg.android.habitica.data.*
import com.habitrpg.android.habitica.databinding.ActivityMainBinding
import com.habitrpg.android.habitica.events.*
import com.habitrpg.android.habitica.events.commands.FeedCommand
-import com.habitrpg.android.habitica.extensions.dpToPx
-import com.habitrpg.android.habitica.extensions.getThemeColor
-import com.habitrpg.android.habitica.extensions.isUsingNightModeResources
-import com.habitrpg.android.habitica.extensions.subscribeWithErrorHandler
+import com.habitrpg.android.habitica.extensions.*
import com.habitrpg.android.habitica.helpers.*
import com.habitrpg.android.habitica.helpers.notifications.PushNotificationManager
import com.habitrpg.android.habitica.interactors.CheckClassSelectionUseCase
@@ -77,12 +73,14 @@ import com.habitrpg.android.habitica.widget.DailiesWidgetProvider
import com.habitrpg.android.habitica.widget.HabitButtonWidgetProvider
import com.habitrpg.android.habitica.widget.TodoListWidgetProvider
import io.reactivex.Completable
+import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.functions.Consumer
import io.reactivex.schedulers.Schedulers
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import java.util.*
+import java.util.concurrent.TimeUnit
import javax.inject.Inject
open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
@@ -138,8 +136,6 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
private var resumeFromActivity = false
private var userIsOnQuest = false
- private var connectionIssueHandler: Handler? = null
-
val userID: String
get() = user?.id ?: ""
@@ -211,14 +207,12 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
override fun onDrawerSlide(drawerView: View, slideOffset: Float) {
val modernHeaderStyle = sharedPreferences.getBoolean("modern_header_style", true)
- if (!isUsingNightModeResources() && modernHeaderStyle && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ if (!isUsingNightModeResources() && modernHeaderStyle) {
if (slideOffset < 0.5f && isOpeningDrawer == null) {
- window.statusBarColor = getThemeColor(R.attr.colorPrimaryDark)
- window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
+ window.updateStatusBarColor(getThemeColor(R.attr.colorPrimaryDark), false)
isOpeningDrawer = true
} else if (slideOffset > 0.5f && isOpeningDrawer == null) {
- window.statusBarColor = getThemeColor(R.attr.headerBackgroundColor)
- window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
+ window.updateStatusBarColor(getThemeColor(R.attr.headerBackgroundColor), true)
isOpeningDrawer = false
}
}
@@ -226,9 +220,8 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
override fun onDrawerOpened(drawerView: View) {
val modernHeaderStyle = sharedPreferences.getBoolean("modern_header_style", true)
- if (!isUsingNightModeResources() && modernHeaderStyle && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- window.statusBarColor = getThemeColor(R.attr.colorPrimaryDark)
- window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
+ if (!isUsingNightModeResources() && modernHeaderStyle) {
+ window.updateStatusBarColor(getThemeColor(R.attr.colorPrimaryDark), false)
}
isOpeningDrawer = null
@@ -237,9 +230,8 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
override fun onDrawerClosed(drawerView: View) {
val modernHeaderStyle = sharedPreferences.getBoolean("modern_header_style", true)
- if (!isUsingNightModeResources() && modernHeaderStyle && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- window.statusBarColor = getThemeColor(R.attr.headerBackgroundColor)
- window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
+ if (!isUsingNightModeResources() && modernHeaderStyle) {
+ window.updateStatusBarColor(getThemeColor(R.attr.headerBackgroundColor), true)
}
isOpeningDrawer = null
}
@@ -770,8 +762,8 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
fun showAchievementDialog(event: ShowAchievementDialog) {
if (User.ONBOARDING_ACHIEVEMENT_KEYS.contains(event.type) || event.type == Notification.Type.ACHIEVEMENT_ONBOARDING_COMPLETE.type) {
if (!appConfigManager.enableAdventureGuide()) {
- apiClient.readNotification(event.id)
- .subscribe({ }, RxErrorHandler.handleEmptyError())
+ compositeSubscription.add(apiClient.readNotification(event.id)
+ .subscribe({ }, RxErrorHandler.handleEmptyError()))
return
}
}
@@ -811,13 +803,13 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
if (event.title != null) {
super.onEvent(event)
} else {
- connectionIssueHandler?.removeCallbacksAndMessages(null)
binding.connectionIssueTextview.visibility = View.VISIBLE
binding.connectionIssueTextview.text = event.message
- connectionIssueHandler = Handler()
- connectionIssueHandler?.postDelayed({
- binding.connectionIssueTextview.visibility = View.GONE
- }, 5000)
+ compositeSubscription.add(Observable.just("")
+ .delay(500, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())
+ .subscribe( {
+ binding.connectionIssueTextview.visibility = View.GONE
+ }, {}))
}
}
@@ -865,4 +857,4 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
const val NOTIFICATION_ACCEPT = 223
const val NOTIFICATION_REJECT = 224
}
-}
+}
\ No newline at end of file
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/CustomizationRecyclerViewAdapter.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/CustomizationRecyclerViewAdapter.kt
index 2dee954cd..dd3a1e260 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/CustomizationRecyclerViewAdapter.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/CustomizationRecyclerViewAdapter.kt
@@ -106,7 +106,7 @@ class CustomizationRecyclerViewAdapter : androidx.recyclerview.widget.RecyclerVi
val set = CustomizationSet()
set.identifier = customization.customizationSet
set.text = customization.customizationSetName
- set.price = customization.setPrice
+ set.price = customization.setPrice ?: 0
set.hasPurchasable = !customization.isUsable(ownedCustomiztations.contains(customization.identifier))
lastSet = set
customizationList.add(set)
@@ -234,7 +234,7 @@ class CustomizationRecyclerViewAdapter : androidx.recyclerview.widget.RecyclerVi
fun bind(set: CustomizationSet) {
this.set = set
binding.label.text = set.text
- if (set.hasPurchasable && !set.identifier.contains("timeTravel")) {
+ if (set.hasPurchasable && set.identifier?.contains("timeTravel") != true) {
binding.purchaseSetButton.visibility = View.VISIBLE
binding.setPriceLabel.value = set.price.toDouble()
binding.setPriceLabel.currency = "gems"
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/NavigationDrawerAdapter.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/NavigationDrawerAdapter.kt
index e0f2a0d63..13050b70a 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/NavigationDrawerAdapter.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/NavigationDrawerAdapter.kt
@@ -49,13 +49,9 @@ class NavigationDrawerAdapter(tintColor: Int, backgroundTintColor: Int): Recycle
fun getItemSelectionEvents(): Flowable = itemSelectedEvents.toFlowable(BackpressureStrategy.DROP)
- fun getItemWithTransitionId(transitionId: Int): HabiticaDrawerItem? =
- items.find { it.transitionId == transitionId }
fun getItemWithIdentifier(identifier: String): HabiticaDrawerItem? =
items.find { it.identifier == identifier }
- private fun getItemPosition(transitionId: Int): Int =
- items.indexOfFirst { it.transitionId == transitionId }
private fun getItemPosition(identifier: String): Int =
items.indexOfFirst { it.identifier == identifier }
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/SkillsRecyclerViewAdapter.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/SkillsRecyclerViewAdapter.kt
index d6467ff7d..ec7f3e8ff 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/SkillsRecyclerViewAdapter.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/SkillsRecyclerViewAdapter.kt
@@ -16,12 +16,13 @@ import com.habitrpg.android.habitica.models.user.SpecialItems
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils
import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper
import io.reactivex.BackpressureStrategy
+import io.reactivex.Flowable
import io.reactivex.subjects.PublishSubject
class SkillsRecyclerViewAdapter : RecyclerView.Adapter() {
private val useSkillSubject = PublishSubject.create()
- val useSkillEvents = useSkillSubject.toFlowable(BackpressureStrategy.DROP)
+ val useSkillEvents: Flowable = useSkillSubject.toFlowable(BackpressureStrategy.DROP)
var mana: Double = 0.0
set(value) {
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/inventory/ItemRecyclerAdapter.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/inventory/ItemRecyclerAdapter.kt
index c75ba4cdd..5ed3a2405 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/inventory/ItemRecyclerAdapter.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/inventory/ItemRecyclerAdapter.kt
@@ -59,8 +59,8 @@ class ItemRecyclerAdapter(data: OrderedRealmCollection?, autoUpdate:
return openMysteryItemEvents.toFlowable(BackpressureStrategy.DROP)
}
- val startHatchingEvents = startHatchingSubject.toFlowable(BackpressureStrategy.DROP)
- val hatchPetEvents = hatchPetSubject.toFlowable(BackpressureStrategy.DROP)
+ val startHatchingEvents: Flowable- = startHatchingSubject.toFlowable(BackpressureStrategy.DROP)
+ val hatchPetEvents: Flowable> = hatchPetSubject.toFlowable(BackpressureStrategy.DROP)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
return ItemViewHolder(ItemItemBinding.inflate(context.layoutInflater, parent, false))
@@ -84,7 +84,7 @@ class ItemRecyclerAdapter(data: OrderedRealmCollection?, autoUpdate:
}
inner class ItemViewHolder(val binding: ItemItemBinding) : RecyclerView.ViewHolder(binding.root), View.OnClickListener {
- var ownedItem: OwnedItem? = null
+ private var ownedItem: OwnedItem? = null
var item: Item? = null
var resources: Resources = itemView.resources
@@ -113,7 +113,7 @@ class ItemRecyclerAdapter(data: OrderedRealmCollection?, autoUpdate:
var disabled = false
val imageName: String?
if (item is QuestContent) {
- imageName = "inventory_quest_scroll_" + item.getKey()
+ imageName = "inventory_quest_scroll_" + item.key
} else if (item is SpecialItem) {
val sdf = SimpleDateFormat("MM", Locale.getDefault())
val month = sdf.format(Date())
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/inventory/PetDetailRecyclerAdapter.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/inventory/PetDetailRecyclerAdapter.kt
index a611af4f7..fe554d44b 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/inventory/PetDetailRecyclerAdapter.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/inventory/PetDetailRecyclerAdapter.kt
@@ -96,7 +96,7 @@ class PetDetailRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapt
fun setOwnedItems(ownedItems: Map) {
this.ownedItems = ownedItems
- ownsSaddles = ownedItems.containsKey("Saddle-food")
+ ownsSaddles = if (ownedItems.containsKey("Saddle-food")) (ownedItems["Saddle-food"]?.numberOwned ?: 0)> 0 else false
notifyDataSetChanged()
}
}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/inventory/StableRecyclerAdapter.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/inventory/StableRecyclerAdapter.kt
index bd239eb2b..d895cb6aa 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/inventory/StableRecyclerAdapter.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/inventory/StableRecyclerAdapter.kt
@@ -165,7 +165,7 @@ class StableRecyclerAdapter : RecyclerView.Adapter() {
ownedTextView.visibility = View.VISIBLE
imageView.loadImage(imageName)
- val alpha = if (item.numberOwned <= 0 && ownedEggs?.containsKey(item.animal ?: "") != true) 0.2f else 1.0f
+ val alpha = if (item.numberOwned <= 0 && ownedEggs?.containsKey(item.animal) != true) 0.2f else 1.0f
this.imageView.alpha = alpha
this.titleView.alpha = alpha
this.ownedTextView.alpha = alpha
@@ -180,11 +180,11 @@ class StableRecyclerAdapter : RecyclerView.Adapter() {
val animal = this.animal
if (animal != null) {
val color = if (animal.type == "special") animal.color else null
- if (animal.numberOwned > 0 || ownedEggs?.containsKey(animal.animal ?: "") == true) {
+ if (animal.numberOwned > 0 || ownedEggs?.containsKey(animal.animal) == true) {
if (itemType == "pets") {
- MainNavigationController.navigate(StableFragmentDirections.openPetDetail(animal.animal ?: "", animal.type ?: "", color))
+ MainNavigationController.navigate(StableFragmentDirections.openPetDetail(animal.animal, animal.type ?: "", color))
} else {
- MainNavigationController.navigate(StableFragmentDirections.openMountDetail(animal.animal ?: "", animal.type ?: "", color))
+ MainNavigationController.navigate(StableFragmentDirections.openMountDetail(animal.animal, animal.type ?: "", color))
}
}
}
diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/setup/CustomizationSetupAdapter.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/setup/CustomizationSetupAdapter.kt
index 56355fb2b..56b2fee09 100644
--- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/setup/CustomizationSetupAdapter.kt
+++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/adapter/setup/CustomizationSetupAdapter.kt
@@ -13,6 +13,7 @@ import com.habitrpg.android.habitica.extensions.setTintWith
import com.habitrpg.android.habitica.models.SetupCustomization
import com.habitrpg.android.habitica.models.user.User
import io.reactivex.BackpressureStrategy
+import io.reactivex.Flowable
import io.reactivex.subjects.PublishSubject
internal class CustomizationSetupAdapter : RecyclerView.Adapter() {
@@ -22,9 +23,9 @@ internal class CustomizationSetupAdapter : RecyclerView.Adapter = emptyList()
private val equipGearEventSubject = PublishSubject.create()
- val equipGearEvents = equipGearEventSubject.toFlowable(BackpressureStrategy.DROP)
- private val updateUserEventsSubject = PublishSubject.create>()
- val updateUserEvents = updateUserEventsSubject.toFlowable(BackpressureStrategy.DROP)
+ val equipGearEvents: Flowable = equipGearEventSubject.toFlowable(BackpressureStrategy.DROP)
+ private val updateUserEventsSubject = PublishSubject.create