Cleanup code

This commit is contained in:
Phillip Thelen 2020-09-17 16:36:38 +02:00
parent 564ad8ecbe
commit 259b8970b0
98 changed files with 1088 additions and 2493 deletions

View file

@ -767,7 +767,7 @@
<string name="login_incentive_short">Accedi ad Habitica regolarmente</string>
<string name="party_invite_short">Invita degli Amici</string>
<string name="login_incentive_count">Sbloccalo accedendo ad Habitica %d volte.</string>
<string name="user_level_with_class_unabbreviated">Livello %1$d &amp;2$s</string>
<string name="user_level_with_class_unabbreviated">Livello %1$d &amp;%2$s</string>
<string name="remaining_1hour">1 ora rimanente</string>
<string name="remaining_hours">%d ore rimanenti</string>
<string name="remaining_days">%d giorni rimanenti</string>

View file

@ -1,35 +0,0 @@
package com.habitrpg.android.habitica.api;
/**
* Created by MagicMicky on 15/06/2014.
*/
public class Server {
private String addr;
public Server(String addr) {
this(addr, true);
}
private Server(String addr, boolean attachSuffix) {
if (attachSuffix) {
if (addr.endsWith("/api/v4") || addr.endsWith("/api/v4/")) {
this.addr = addr;
} else if (addr.endsWith("/")) {
this.addr = addr + "api/v4/";
} else {
this.addr = addr + "/api/v4/";
}
} else {
this.addr = addr;
}
}
public Server(Server server) {
this.addr = server.toString();
}
@Override
public String toString() {
return this.addr;
}
}

View file

@ -0,0 +1,28 @@
package com.habitrpg.android.habitica.api
class Server {
private var addr: String
constructor(addr: String) : this(addr, true) {}
private constructor(addr: String, attachSuffix: Boolean) {
if (attachSuffix) {
if (addr.endsWith("/api/v4") || addr.endsWith("/api/v4/")) {
this.addr = addr
} else if (addr.endsWith("/")) {
this.addr = addr + "api/v4/"
} else {
this.addr = "$addr/api/v4/"
}
} else {
this.addr = addr
}
}
constructor(server: Server) {
addr = server.toString()
}
override fun toString(): String {
return addr
}
}

View file

@ -20,5 +20,5 @@ public interface AppComponent {
UserComponent plus(UserModule userModule, UserRepositoryModule userRepositoryModule);
void inject(@NotNull HabiticaBaseApplication habiticaBaseApplication);
void inject(HabiticaBaseApplication habiticaBaseApplication);
}

View file

@ -272,69 +272,69 @@ public interface UserComponent {
void inject(PurchaseDialog purchaseDialog);
void inject(@NotNull FixCharacterValuesActivity fixCharacterValuesActivity);
void inject(FixCharacterValuesActivity fixCharacterValuesActivity);
void inject(@NotNull AuthenticationPreferenceFragment authenticationPreferenceFragment);
void inject(AuthenticationPreferenceFragment authenticationPreferenceFragment);
void inject(@NotNull ProfilePreferencesFragment profilePreferencesFragment);
void inject(ProfilePreferencesFragment profilePreferencesFragment);
void inject(@NotNull APIPreferenceFragment apiPreferenceFragment);
void inject(APIPreferenceFragment apiPreferenceFragment);
void inject(@NotNull StatsFragment statsFragment);
void inject(StatsFragment statsFragment);
void inject(@NotNull BulkAllocateStatsDialog bulkAllocateStatsDialog);
void inject(BulkAllocateStatsDialog bulkAllocateStatsDialog);
void inject(@NotNull PushNotificationsPreferencesFragment pushNotificationsPreferencesFragment);
void inject(PushNotificationsPreferencesFragment pushNotificationsPreferencesFragment);
void inject(WelcomeFragment welcomeFragment);
void inject(@NotNull NavigationDrawerFragment navigationDrawerFragment);
void inject(NavigationDrawerFragment navigationDrawerFragment);
void inject(@NotNull ChallengeDetailFragment challengeDetailFragment);
void inject(ChallengeDetailFragment challengeDetailFragment);
void inject(@NotNull VerifyUsernameActivity verifyUsernameActivity);
void inject(VerifyUsernameActivity verifyUsernameActivity);
void inject(@NotNull GroupViewModel viewModel);
void inject(GroupViewModel viewModel);
void inject(@NotNull NotificationsViewModel viewModel);
void inject(NotificationsViewModel viewModel);
void inject(@NotNull ChatFragment chatFragment);
void inject(ChatFragment chatFragment);
void inject(@NotNull GiftSubscriptionActivity giftSubscriptionActivity);
void inject(GiftSubscriptionActivity giftSubscriptionActivity);
void inject(@NotNull AboutFragment aboutFragment);
void inject(AboutFragment aboutFragment);
void inject(@NotNull ChatBarView chatBarView);
void inject(ChatBarView chatBarView);
void inject(@NotNull TaskFormActivity taskFormActivity);
void inject(TaskFormActivity taskFormActivity);
void inject(@NotNull ReportMessageActivity reportMessageActivity);
void inject(ReportMessageActivity reportMessageActivity);
void inject(@NotNull GuildDetailFragment guildDetailFragment);
void inject(GuildDetailFragment guildDetailFragment);
void inject(@NotNull AchievementsFragment achievementsFragment);
void inject(AchievementsFragment achievementsFragment);
void inject(@NotNull InboxViewModel inboxViewModel);
void inject(InboxViewModel inboxViewModel);
void inject(@NotNull InsufficientGemsDialog insufficientGemsDialog);
void inject(InsufficientGemsDialog insufficientGemsDialog);
void inject(@NotNull GiftGemsActivity giftGemsActivity);
void inject(GiftGemsActivity giftGemsActivity);
void inject(@NotNull GiftPurchaseGemsFragment giftPurchaseGemsFragment);
void inject(GiftPurchaseGemsFragment giftPurchaseGemsFragment);
void inject(@NotNull GiftBalanceGemsFragment giftBalanceGemsFragment);
void inject(GiftBalanceGemsFragment giftBalanceGemsFragment);
void inject(@NotNull EmailNotificationsPreferencesFragment emailNotificationsPreferencesFragment);
void inject(EmailNotificationsPreferencesFragment emailNotificationsPreferencesFragment);
void inject(@NotNull SupportMainFragment supportMainFragment);
void inject(SupportMainFragment supportMainFragment);
void inject(@NotNull BugFixFragment bugFixFragment);
void inject(BugFixFragment bugFixFragment);
void inject(@NotNull AvatarEquipmentFragment avatarEquipmentFragment);
void inject(AvatarEquipmentFragment avatarEquipmentFragment);
void inject(@NotNull FAQDetailFragment faqDetailFragment);
void inject(FAQDetailFragment faqDetailFragment);
void inject(@NotNull AdventureGuideActivity adventureGuideFragment);
void inject(AdventureGuideActivity adventureGuideFragment);
void inject(@NotNull PromoInfoFragment promoInfoFragment);
void inject(PromoInfoFragment promoInfoFragment);
}

View file

@ -48,9 +48,7 @@ class TaskRepositoryImpl(localRepository: TaskLocalRepository, apiClient: ApiCli
return this.apiClient.getTasks("completedTodos")
.doOnNext { taskList ->
val tasks = taskList.tasks
if (tasks != null) {
this.localRepository.saveCompletedTodos(userId, tasks.values)
}
this.localRepository.saveCompletedTodos(userId, tasks.values)
}
}

View file

@ -0,0 +1,15 @@
package com.habitrpg.android.habitica.extensions
import android.os.Build
import android.view.View
import android.view.Window
fun Window.updateStatusBarColor(color: Int, isLight: Boolean) {
statusBarColor = color
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
isStatusBarContrastEnforced = true
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
@Suppress("DEPRECATION")
decorView.systemUiVisibility = if (isLight) View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR else View.SYSTEM_UI_FLAG_VISIBLE
}
}

View file

@ -1,49 +0,0 @@
package com.habitrpg.android.habitica.helpers;
import com.amplitude.api.Amplitude;
import com.habitrpg.android.habitica.BuildConfig;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Map;
/**
* Created by viirus on 23-Sep-16.
*/
public class AmplitudeManager {
public static String EVENT_CATEGORY_BEHAVIOUR = "behaviour";
public static String EVENT_CATEGORY_NAVIGATION = "navigation";
public static String EVENT_HITTYPE_EVENT = "event";
public static String EVENT_HITTYPE_PAGEVIEW = "pageview";
public static String EVENT_HITTYPE_CREATE_WIDGET = "create";
public static String EVENT_HITTYPE_REMOVE_WIDGET = "remove";
public static String EVENT_HITTYPE_UPDATE_WIDGET = "update";
public static void sendEvent(String eventAction, String eventCategory, String hitType) {
sendEvent(eventAction, eventCategory, hitType, null);
}
public static void sendEvent(String eventAction, String eventCategory, String hitType, Map<String, Object> additionalData) {
if (BuildConfig.DEBUG) {
return;
}
JSONObject eventProperties = new JSONObject();
try {
eventProperties.put("eventAction", eventAction);
eventProperties.put("eventCategory", eventCategory);
eventProperties.put("hitType", hitType);
eventProperties.put("status", "displayed");
if (additionalData != null) {
for (Map.Entry<String, Object> entry : additionalData.entrySet()) {
eventProperties.put(entry.getKey(), entry.getValue());
}
}
} catch (JSONException exception) {
}
Amplitude.getInstance().logEvent(eventAction, eventProperties);
}
}

View file

@ -0,0 +1,38 @@
package com.habitrpg.android.habitica.helpers
import com.amplitude.api.Amplitude
import com.habitrpg.android.habitica.BuildConfig
import org.json.JSONException
import org.json.JSONObject
object AmplitudeManager {
var EVENT_CATEGORY_BEHAVIOUR = "behaviour"
var EVENT_CATEGORY_NAVIGATION = "navigation"
var EVENT_HITTYPE_EVENT = "event"
var EVENT_HITTYPE_PAGEVIEW = "pageview"
var EVENT_HITTYPE_CREATE_WIDGET = "create"
var EVENT_HITTYPE_REMOVE_WIDGET = "remove"
var EVENT_HITTYPE_UPDATE_WIDGET = "update"
@JvmOverloads
fun sendEvent(eventAction: String?, eventCategory: String?, hitType: String?, additionalData: Map<String, Any>? = 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)
}
}

View file

@ -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:**
*
* <pre>
* String deviceName = DeviceName.getDeviceName();
</pre> *
*
*
* 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:**
*
* <pre>
* // Retruns "Moto X Style"
* DeviceName.getDeviceName("clark", "Unknown device");
</pre> *
*
*
* **Get information about the device:**
*
* <pre>
* DeviceName.with(context).request(new DeviceName.Callback() {
*
* &#64;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.
* }
* });
</pre> *
*
*
* 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())
}
}

View file

@ -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
}

View file

@ -33,10 +33,6 @@ class TaskFilterHelper {
}
}
fun isTagChecked(tagID: String): Boolean {
return this.tagsId.contains(tagID)
}
fun filter(tasks: List<Task>): List<Task> {
if (tasks.isEmpty()) {
return tasks

View file

@ -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
}

View file

@ -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;
}
}

View file

@ -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
}

View file

@ -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<Customization> customizations;
}

View file

@ -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<Customization> = mutableListOf()
}

View file

@ -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;
}
}

View file

@ -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"
}

View file

@ -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;
}
}

View file

@ -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"
}

View file

@ -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;
}
}

View file

@ -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"
}

View file

@ -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();
}

View file

@ -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
}

View file

@ -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<QuestCollect>()) {

View file

@ -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;
}
}

View file

@ -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"
}
}

View file

@ -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<QuestDropItem> 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<QuestDropItem> getItems() {
return items;
}
public void setItems(RealmList<QuestDropItem> items) {
this.items = items;
if (items != null) {
for (QuestDropItem item : items) {
item.setQuestKey(key);
}
}
}
}

View file

@ -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<QuestDropItem>? = null
set(value) {
field = value
items?.forEach { it.questKey = key }
}
}

View file

@ -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 {

View file

@ -1,9 +0,0 @@
package com.habitrpg.android.habitica.models.notifications;
/**
* Created by krh12 on 12/1/2016.
*/
public class Reward {
public String key;
}

View file

@ -0,0 +1,5 @@
package com.habitrpg.android.habitica.models.notifications
class Reward {
var key: String? = null
}

View file

@ -1,9 +0,0 @@
package com.habitrpg.android.habitica.models.tasks;
import java.util.Map;
public class TaskList {
public Map<String, Task> tasks;
}

View file

@ -0,0 +1,5 @@
package com.habitrpg.android.habitica.models.tasks
class TaskList {
var tasks: MutableMap<String, Task> = mutableMapOf()
}

View file

@ -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;
}
}

View file

@ -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
}
}

View file

@ -1,43 +0,0 @@
package com.habitrpg.android.habitica.models.tasks;
import java.util.List;
public class TasksOrder {
List<String> habits;
List<String> dailys;
List<String> todos;
List<String> rewards;
public List<String> getHabits() {
return habits;
}
public void setHabits(List<String> habits) {
this.habits = habits;
}
public List<String> getDailys() {
return dailys;
}
public void setDailys(List<String> dailys) {
this.dailys = dailys;
}
public List<String> getTodos() {
return todos;
}
public void setTodos(List<String> todos) {
this.todos = todos;
}
public List<String> getRewards() {
return rewards;
}
public void setRewards(List<String> rewards) {
this.rewards = rewards;
}
}

View file

@ -0,0 +1,8 @@
package com.habitrpg.android.habitica.models.tasks
class TasksOrder {
var habits: List<String> = listOf()
var dailys: List<String> = listOf()
var todos: List<String> = listOf()
var rewards: List<String> = listOf()
}

View file

@ -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;
}
}

View file

@ -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
}
}

View file

@ -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<OwnedCustomization> customizations;
User user;
private SubscriptionPlan plan;
public List<OwnedCustomization> getCustomizations() {
return customizations;
}
public void setCustomizations(RealmList<OwnedCustomization> 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;
}
}

View file

@ -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<OwnedCustomization>? = null
var user: User? = null
var plan: SubscriptionPlan? = null
}

View file

@ -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"

View file

@ -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;
}
}

View file

@ -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
}

View file

@ -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;
}
}

View file

@ -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
}

View file

@ -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;
}
}

View file

@ -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
}
}

View file

@ -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)
}
}

View file

@ -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)
}

View file

@ -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)

View file

@ -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<String, Any>()
val invites = ArrayList<String>()
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"

View file

@ -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
}
}
}

View file

@ -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"

View file

@ -49,13 +49,9 @@ class NavigationDrawerAdapter(tintColor: Int, backgroundTintColor: Int): Recycle
fun getItemSelectionEvents(): Flowable<HabiticaDrawerItem> = 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 }

View file

@ -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<SkillsRecyclerViewAdapter.SkillViewHolder>() {
private val useSkillSubject = PublishSubject.create<Skill>()
val useSkillEvents = useSkillSubject.toFlowable(BackpressureStrategy.DROP)
val useSkillEvents: Flowable<Skill> = useSkillSubject.toFlowable(BackpressureStrategy.DROP)
var mana: Double = 0.0
set(value) {

View file

@ -59,8 +59,8 @@ class ItemRecyclerAdapter(data: OrderedRealmCollection<OwnedItem>?, autoUpdate:
return openMysteryItemEvents.toFlowable(BackpressureStrategy.DROP)
}
val startHatchingEvents = startHatchingSubject.toFlowable(BackpressureStrategy.DROP)
val hatchPetEvents = hatchPetSubject.toFlowable(BackpressureStrategy.DROP)
val startHatchingEvents: Flowable<Item> = startHatchingSubject.toFlowable(BackpressureStrategy.DROP)
val hatchPetEvents: Flowable<Pair<HatchingPotion, Egg>> = 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<OwnedItem>?, 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<OwnedItem>?, 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())

View file

@ -96,7 +96,7 @@ class PetDetailRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapt
fun setOwnedItems(ownedItems: Map<String, OwnedItem>) {
this.ownedItems = ownedItems
ownsSaddles = ownedItems.containsKey("Saddle-food")
ownsSaddles = if (ownedItems.containsKey("Saddle-food")) (ownedItems["Saddle-food"]?.numberOwned ?: 0)> 0 else false
notifyDataSetChanged()
}
}

View file

@ -165,7 +165,7 @@ class StableRecyclerAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
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<RecyclerView.ViewHolder>() {
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))
}
}
}

View file

@ -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<CustomizationSetupAdapter.CustomizationViewHolder>() {
@ -22,9 +23,9 @@ internal class CustomizationSetupAdapter : RecyclerView.Adapter<CustomizationSet
private var customizationList: List<SetupCustomization> = emptyList()
private val equipGearEventSubject = PublishSubject.create<String>()
val equipGearEvents = equipGearEventSubject.toFlowable(BackpressureStrategy.DROP)
private val updateUserEventsSubject = PublishSubject.create<HashMap<String, Any>>()
val updateUserEvents = updateUserEventsSubject.toFlowable(BackpressureStrategy.DROP)
val equipGearEvents: Flowable<String> = equipGearEventSubject.toFlowable(BackpressureStrategy.DROP)
private val updateUserEventsSubject = PublishSubject.create<Map<String, Any>>()
val updateUserEvents: Flowable<Map<String, Any>> = updateUserEventsSubject.toFlowable(BackpressureStrategy.DROP)
fun setCustomizationList(newCustomizationList: List<SetupCustomization>) {
this.customizationList = newCustomizationList

View file

@ -2,7 +2,6 @@ package com.habitrpg.android.habitica.ui.adapter.social
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.databinding.ChallengeItemBinding

View file

@ -9,7 +9,7 @@ import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.components.UserComponent
import com.habitrpg.android.habitica.helpers.TaskFilterHelper
import com.habitrpg.android.habitica.models.tasks.Task
import com.habitrpg.android.habitica.ui.adapter.tasks.SortableTasksRecyclerViewAdapter
import com.habitrpg.android.habitica.ui.adapter.tasks.BaseTasksRecyclerViewAdapter
import com.habitrpg.android.habitica.ui.viewHolders.BindableViewHolder
import com.habitrpg.android.habitica.ui.viewHolders.tasks.*
import io.reactivex.BackpressureStrategy
@ -17,8 +17,8 @@ import io.reactivex.Flowable
import io.reactivex.subjects.PublishSubject
class ChallengeTasksRecyclerViewAdapter(taskFilterHelper: TaskFilterHelper?, layoutResource: Int,
newContext: Context, userID: String, sortCallback: SortTasksCallback?,
private val openTaskDisabled: Boolean, private val taskActionsDisabled: Boolean) : SortableTasksRecyclerViewAdapter<BindableViewHolder<Task>>("", taskFilterHelper, layoutResource, newContext, userID, sortCallback) {
newContext: Context, userID: String,
private val openTaskDisabled: Boolean, private val taskActionsDisabled: Boolean) : BaseTasksRecyclerViewAdapter<BindableViewHolder<Task>>("", taskFilterHelper, layoutResource, newContext, userID) {
private val addItemSubject = PublishSubject.create<Task>()

View file

@ -47,10 +47,6 @@ abstract class BaseTasksRecyclerViewAdapter<VH : BindableViewHolder<Task>>(var t
if (item != null) {
holder.bind(item, position, "normal")
}
/*if (this.displayedChecklist != null && ChecklistedViewHolder.class.isAssignableFrom(holder.getClass())) {
ChecklistedViewHolder checklistedHolder = (ChecklistedViewHolder) holder;
checklistedHolder.setDisplayChecklist(this.displayedChecklist == position);
}*/
}
override fun getItemId(position: Int): Long {

View file

@ -19,11 +19,11 @@ import io.reactivex.Flowable
import io.reactivex.subjects.PublishSubject
import io.realm.OrderedRealmCollection
class RewardsRecyclerViewAdapter(private var customRewards: OrderedRealmCollection<Task>?, private val layoutResource: Int, private val user: User?, private val configManager: AppConfigManager) : RecyclerView.Adapter<RecyclerView.ViewHolder>(), TaskRecyclerViewAdapter {
class RewardsRecyclerViewAdapter(private var customRewards: OrderedRealmCollection<Task>?, private val layoutResource: Int, private val user: User?) : RecyclerView.Adapter<RecyclerView.ViewHolder>(), TaskRecyclerViewAdapter {
private var inAppRewards: OrderedRealmCollection<ShopItem>? = null
val errorButtonEventsSubject = PublishSubject.create<String>()
override val errorButtonEvents = errorButtonEventsSubject.toFlowable(BackpressureStrategy.DROP)
private val errorButtonEventsSubject = PublishSubject.create<String>()
override val errorButtonEvents: Flowable<String> = errorButtonEventsSubject.toFlowable(BackpressureStrategy.DROP)
private var taskScoreEventsSubject = PublishSubject.create<Pair<Task, TaskDirection>>()
override val taskScoreEvents: Flowable<Pair<Task, TaskDirection>> = taskScoreEventsSubject.toFlowable(BackpressureStrategy.LATEST)
private var checklistItemScoreSubject = PublishSubject.create<Pair<Task, ChecklistItem>>()
@ -137,7 +137,6 @@ class RewardsRecyclerViewAdapter(private var customRewards: OrderedRealmCollecti
companion object {
private const val VIEWTYPE_CUSTOM_REWARD = 0
private const val VIEWTYPE_HEADER = 1
private const val VIEWTYPE_IN_APP_REWARD = 2
}
}

View file

@ -1,53 +0,0 @@
package com.habitrpg.android.habitica.ui.adapter.tasks;
import android.content.Context;
import androidx.annotation.Nullable;
import com.habitrpg.android.habitica.helpers.TaskFilterHelper;
import com.habitrpg.android.habitica.models.tasks.Task;
import com.habitrpg.android.habitica.ui.helpers.ItemTouchHelperAdapter;
import com.habitrpg.android.habitica.ui.helpers.ItemTouchHelperDropCallback;
import com.habitrpg.android.habitica.ui.viewHolders.BindableViewHolder;
import java.util.Collections;
/**
* Created by ell on 7/21/16.
*/
public abstract class SortableTasksRecyclerViewAdapter<VH extends BindableViewHolder<Task>>
extends BaseTasksRecyclerViewAdapter<VH> implements ItemTouchHelperAdapter, ItemTouchHelperDropCallback {
private SortTasksCallback sortCallback;
public SortableTasksRecyclerViewAdapter(String taskType, TaskFilterHelper taskFilterHelper, int layoutResource,
Context newContext, String userID, @Nullable SortTasksCallback sortCallback) {
super(taskType, taskFilterHelper, layoutResource, newContext, userID);
this.sortCallback = sortCallback;
}
@Override
public void onItemMove(int fromPosition, int toPosition) {
if (getFilteredContent().size() <= fromPosition || getFilteredContent().size() <= toPosition) {
return;
}
Collections.swap(getFilteredContent(), fromPosition, toPosition);
notifyItemMoved(fromPosition, toPosition);
}
@Override
public void onItemDismiss(int position) {
//NO OP
}
@Override
public void onDrop(int from, int to) {
if (this.sortCallback != null && from != to) {
this.sortCallback.onMove(getFilteredContent().get(to), from, to);
}
}
public interface SortTasksCallback {
void onMove(Task task, int from, int to);
}
}

View file

@ -15,19 +15,16 @@ import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.components.UserComponent
import com.habitrpg.android.habitica.databinding.FragmentAboutBinding
import com.habitrpg.android.habitica.helpers.AppConfigManager
import com.habitrpg.android.habitica.helpers.DeviceName
import com.habitrpg.android.habitica.helpers.MainNavigationController
import com.habitrpg.android.habitica.modules.AppModule
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils
import com.plattysoft.leonids.ParticleSystem
import io.reactivex.Completable
import javax.inject.Inject
import javax.inject.Named
class AboutFragment : BaseMainFragment<FragmentAboutBinding>() {
private var deviceInfo: DeviceName.DeviceInfo? = null
@field:[Inject Named(AppModule.NAMED_USER_ID)]
lateinit var userId: String
@ -55,11 +52,6 @@ class AboutFragment : BaseMainFragment<FragmentAboutBinding>() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
this.hidesToolbar = true
compositeSubscription.add(Completable.fromAction {
deviceInfo = DeviceName.getDeviceInfo(context)
}.subscribe())
return super.onCreateView(inflater, container, savedInstanceState)
}

View file

@ -11,7 +11,6 @@ import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.components.UserComponent
import com.habitrpg.android.habitica.data.InventoryRepository
import com.habitrpg.android.habitica.data.SocialRepository
import com.habitrpg.android.habitica.data.UserRepository
import com.habitrpg.android.habitica.databinding.FragmentRecyclerviewBinding
import com.habitrpg.android.habitica.events.GearPurchasedEvent
import com.habitrpg.android.habitica.helpers.AppConfigManager
@ -22,7 +21,6 @@ import com.habitrpg.android.habitica.models.shops.ShopItem
import com.habitrpg.android.habitica.models.social.Group
import com.habitrpg.android.habitica.models.user.User
import com.habitrpg.android.habitica.ui.adapter.inventory.ShopRecyclerAdapter
import com.habitrpg.android.habitica.ui.fragments.BaseFragment
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment
import com.habitrpg.android.habitica.ui.helpers.SafeDefaultItemAnimator
import com.habitrpg.android.habitica.ui.views.CurrencyViews

View file

@ -70,9 +70,7 @@ class TimePreferenceDialogFragment : PreferenceDialogFragmentCompat() {
}
companion object {
val TAG = TimePreferenceDialogFragment::class.java.simpleName
fun newInstance(
preferenceFragment: PreferenceFragmentCompat, key: String): TimePreferenceDialogFragment {
val fragment = TimePreferenceDialogFragment()

View file

@ -361,18 +361,6 @@ class PartyDetailFragment : BaseFragment<FragmentPartyDetailBinding>() {
viewModel?.rejectQuest()
}
private fun onPartyInviteAccepted() {
viewModel?.getUserData()?.value?.invitations?.party?.id?.let {
viewModel?.joinGroup(it)
}
}
private fun onPartyInviteRejected() {
viewModel?.getUserData()?.value?.invitations?.party?.id?.let {
viewModel?.rejectGroupInvite(it)
}
}
private fun questDetailButtonClicked() {
viewModel?.getGroupData()?.value?.let { party ->
MainNavigationController.navigate(PartyFragmentDirections.openQuestDetail(party.id, party.quest?.key ?: ""))

View file

@ -47,7 +47,7 @@ class BugFixFragment: BaseMainFragment<FragmentSupportBugFixBinding>() {
super.onViewCreated(view, savedInstanceState)
compositeSubscription.add(Completable.fromAction {
deviceInfo = DeviceName.getDeviceInfo(context)
deviceInfo = context?.let { DeviceName.getDeviceInfo(it) }
}.subscribe())
binding?.reportBugButton?.setOnClickListener {
@ -75,7 +75,7 @@ class BugFixFragment: BaseMainFragment<FragmentSupportBugFixBinding>() {
private fun sendEmail(subject: String) {
val version = Build.VERSION.SDK_INT
val deviceName = deviceInfo?.name ?: DeviceName.getDeviceName()
val deviceName = deviceInfo?.name ?: DeviceName.deviceName
val manufacturer = deviceInfo?.manufacturer ?: Build.MANUFACTURER
var bodyOfEmail = Uri.encode("Device: $manufacturer $deviceName") +
"%0D%0A" + Uri.encode("Android Version: $version") +

View file

@ -59,7 +59,7 @@ class SupportMainFragment : BaseMainFragment<FragmentSupportMainBinding>() {
}
compositeSubscription.add(Completable.fromAction {
deviceInfo = DeviceName.getDeviceInfo(context)
deviceInfo = context?.let { DeviceName.getDeviceInfo(it) }
}.subscribe())
binding?.resetTutorialButton?.setOnClickListener {

View file

@ -93,7 +93,7 @@ open class TaskRecyclerViewFragment : BaseFragment<FragmentRefreshRecyclerviewBi
TodosRecyclerViewAdapter(null, true, R.layout.todo_item_card, taskFilterHelper)
}
Task.TYPE_REWARD -> {
RewardsRecyclerViewAdapter(null, R.layout.reward_item_card, user, configManager)
RewardsRecyclerViewAdapter(null, R.layout.reward_item_card, user)
}
else -> null
}
@ -260,7 +260,7 @@ open class TaskRecyclerViewFragment : BaseFragment<FragmentRefreshRecyclerviewBi
?.subscribeWithErrorHandler { scoreTask(it.first, it.second) }?.let { compositeSubscription.add(it) }
recyclerAdapter?.checklistItemScoreEvents
?.flatMap { taskRepository.scoreChecklistItem(it.first.id ?: "", it.second.id ?: "")
}?.subscribeWithErrorHandler({})?.let { compositeSubscription.add(it) }
}?.subscribeWithErrorHandler {}?.let { compositeSubscription.add(it) }
recyclerAdapter?.brokenTaskEvents?.subscribeWithErrorHandler { showBrokenChallengeDialog(it) }?.let { compositeSubscription.add(it) }
}
@ -364,7 +364,7 @@ open class TaskRecyclerViewFragment : BaseFragment<FragmentRefreshRecyclerviewBi
private fun scoreTask(task: Task, direction: TaskDirection) {
compositeSubscription.add(taskRepository.taskChecked(user, task, direction == TaskDirection.UP, false) { result ->
handleTaskResult(result, task.value.toInt())
}.subscribeWithErrorHandler({}))
}.subscribeWithErrorHandler {})
}
override fun onSaveInstanceState(outState: Bundle) {

View file

@ -8,8 +8,6 @@ import android.view.ViewGroup
import android.view.animation.Animation
import android.view.animation.Transformation
import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import androidx.core.net.toUri
import com.facebook.common.executors.CallerThreadExecutor

View file

@ -1,14 +0,0 @@
package com.habitrpg.android.habitica.ui.helpers;
import androidx.recyclerview.widget.RecyclerView;
/**
* Interface to notify a {@link RecyclerView.Adapter} of moving and dismissal event from a {@link
* androidx.recyclerview.widget.ItemTouchHelper.Callback}.
*
* @author Paul Burke (ipaulpro)
*/
public interface ItemTouchHelperAdapter {
void onItemMove(int fromPosition, int toPosition);
void onItemDismiss(int position);
}

View file

@ -1,8 +0,0 @@
package com.habitrpg.android.habitica.ui.helpers;
/**
* Created by ell on 3/30/16.
*/
public interface ItemTouchHelperDropCallback {
void onDrop(int from, int to);
}

View file

@ -1,25 +0,0 @@
package com.habitrpg.android.habitica.ui.helpers;
import androidx.recyclerview.widget.ItemTouchHelper;
/**
* Interface to notify an item ViewHolder of relevant callbacks from {@link
* androidx.recyclerview.widget.ItemTouchHelper.Callback}.
*
* @author Paul Burke (ipaulpro)
*/
public interface ItemTouchHelperViewHolder {
/**
* Called when the {@link ItemTouchHelper} first registers an item as being moved or swiped.
* Implementations should update the item view to indicate it's active state.
*/
void onItemSelected();
/**
* Called when the {@link ItemTouchHelper} has completed the move or swipe, and the active item
* state should be cleared.
*/
void onItemClear();
}

View file

@ -1,69 +0,0 @@
package com.habitrpg.android.habitica.ui.helpers;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.ItemTouchHelper;
/**
* An implementation of {@link ItemTouchHelper.Callback} that enables basic drag & drop and
* swipe-to-dismiss. Drag events are automatically started by an item long-press.<br/>
* </br/>
* Expects the <code>RecyclerView.Adapter</code> to react to {@link
* ItemTouchHelperAdapter} callbacks and the <code>RecyclerView.ViewHolder</code> to implement
* {@link ItemTouchHelperViewHolder}.
*
* @author Paul Burke (ipaulpro)
*/
public class SimpleItemTouchHelperCallback extends ItemTouchHelper.Callback {
private final ItemTouchHelperAdapter mAdapter;
public SimpleItemTouchHelperCallback(ItemTouchHelperAdapter adapter) {
mAdapter = adapter;
}
@Override
public boolean isLongPressDragEnabled() {
return true;
}
@Override
public boolean isItemViewSwipeEnabled() {
return false;
}
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
final int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
final int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;
return makeMovementFlags(dragFlags, swipeFlags);
}
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder source, RecyclerView.ViewHolder target) {
mAdapter.onItemMove(source.getAdapterPosition(), target.getAdapterPosition());
return true;
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int i) {
mAdapter.onItemDismiss(viewHolder.getAdapterPosition());
}
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) {
ItemTouchHelperViewHolder itemViewHolder = (ItemTouchHelperViewHolder) viewHolder;
itemViewHolder.onItemSelected();
}
super.onSelectedChanged(viewHolder, actionState);
}
@Override
public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
super.clearView(recyclerView, viewHolder);
ItemTouchHelperViewHolder itemViewHolder = (ItemTouchHelperViewHolder) viewHolder;
itemViewHolder.onItemClear();
}
}

View file

@ -18,12 +18,6 @@ class BottomSheetMenu(context: Context) : BottomSheetDialog(context), View.OnCli
this.runnable = runnable
}
fun addMenuItems(vararg menuItems: BottomSheetMenuItem) {
for (menuItem in menuItems) {
this.addMenuItem(menuItem)
}
}
override fun setTitle(title: CharSequence?) {
binding.titleView.text = title
binding.titleView.visibility = View.VISIBLE
@ -35,10 +29,6 @@ class BottomSheetMenu(context: Context) : BottomSheetDialog(context), View.OnCli
this.binding.menuItems.addView(item)
}
fun removeMenuItem(index: Int) {
this.binding.menuItems.removeViewAt(index)
}
override fun onClick(v: View) {
if (this.runnable != null) {
val index = this.binding.menuItems.indexOfChild(v)

View file

@ -23,8 +23,6 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
abstract class BaseTaskViewHolder constructor(itemView: View, var scoreTaskFunc: ((Task, TaskDirection) -> Unit), var openTaskFunc: ((Task) -> Unit), var brokenTaskFunc: ((Task) -> Unit)) : BindableViewHolder<Task>(itemView), View.OnClickListener {
var task: Task? = null
var movingFromPosition: Int? = null
var errorButtonClicked: Action? = null

View file

@ -169,15 +169,7 @@ abstract class ChecklistedViewHolder(itemView: View, scoreTaskFunc: ((Task, Task
return expandedChecklistRow != null && adapterPosition == expandedChecklistRow
}
private fun expandCheckboxTouchArea(expandedView: View?, checkboxView: View?) {
expandedView?.post {
val rect = Rect()
expandedView.getHitRect(rect)
expandedView.touchDelegate = TouchDelegate(rect, checkboxView)
}
}
fun onCheckedChanged(isChecked: Boolean) {
private fun onCheckedChanged(isChecked: Boolean) {
if (task?.isValid != true) {
return
}

View file

@ -7,7 +7,6 @@ import android.widget.FrameLayout
import android.widget.ImageView
import androidx.core.content.ContextCompat
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.extensions.isUsingNightModeResources
import com.habitrpg.android.habitica.models.responses.TaskDirection
import com.habitrpg.android.habitica.models.tasks.Task

View file

@ -51,7 +51,7 @@ open class GroupViewModel : BaseViewModel() {
}
protected val groupIDSubject = BehaviorSubject.create<Optional<String>>()
val groupIDFlowable = groupIDSubject.toFlowable(BackpressureStrategy.BUFFER)
val groupIDFlowable: Flowable<Optional<String>> = groupIDSubject.toFlowable(BackpressureStrategy.BUFFER)
var gotNewMessages: Boolean = false
init {

View file

@ -52,7 +52,7 @@ class InboxViewModel(recipientID: String?, recipientUsername: String?) : BaseVie
}
protected var memberIDSubject = BehaviorSubject.create<Optional<String>>()
val memberIDFlowable = memberIDSubject.toFlowable(BackpressureStrategy.BUFFER)
val memberIDFlowable: Flowable<Optional<String>> = memberIDSubject.toFlowable(BackpressureStrategy.BUFFER)
fun setMemberID(groupID: String) {
if (groupID == memberIDSubject.value?.value) return

View file

@ -123,20 +123,6 @@ class CurrencyView : androidx.appcompat.widget.AppCompatTextView {
}
}
var cantAfford = false
set(value) {
if (field != value) {
field = value
if (value) {
this.setTextColor(ContextCompat.getColor(context, R.color.red_50))
drawable?.alpha = 127
} else {
drawable?.alpha = 255
}
this.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
}
}
private fun updateVisibility() {
visibility = if (hideWhenEmpty) {
if ("0" == text) View.GONE else View.VISIBLE

View file

@ -3,7 +3,6 @@ package com.habitrpg.android.habitica.ui.views
import android.content.Context
import android.util.AttributeSet
import android.util.TypedValue
import android.view.View
import android.widget.LinearLayout
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.extensions.isUsingNightModeResources

View file

@ -9,7 +9,6 @@ import android.widget.*
import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat
import androidx.core.view.children
import androidx.core.widget.NestedScrollView
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.extensions.dpToPx
import com.habitrpg.android.habitica.extensions.inflate

View file

@ -21,6 +21,7 @@ import com.habitrpg.android.habitica.ui.views.CurrencyView
import io.reactivex.Flowable
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import java.util.*
class PetSuggestHatchDialog(context: Context) : HabiticaAlertDialog(context) {
@ -45,8 +46,8 @@ class PetSuggestHatchDialog(context: Context) : HabiticaAlertDialog(context) {
binding.eggView.alpha = if (hasEgg) 1.0f else 0.5f
binding.hatchingPotionView.alpha = if (hasPotion) 1.0f else 0.5f
val eggName = egg?.text ?: pet.animal.capitalize()
val potionName = potion?.text ?: pet.color.capitalize()
val eggName = egg?.text ?: pet.animal.capitalize(Locale.getDefault())
val potionName = potion?.text ?: pet.color.capitalize(Locale.getDefault())
if (hasEgg) {
binding.eggCountView.visibility = View.VISIBLE

View file

@ -56,8 +56,4 @@ class FixValuesEditText(context: Context, attrs: AttributeSet) : FrameLayout(con
"streak" -> binding.iconView.setImageResource(R.drawable.achievement_thermometer)
}
}
fun setIconBitmap(icon: Bitmap) {
binding.iconView.setImageBitmap(icon)
}
}

View file

@ -1,19 +1,15 @@
package com.habitrpg.android.habitica.ui.views.shops
import android.content.Context
import android.graphics.PorterDuff
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.view.LayoutInflater
import android.view.View
import android.widget.Button
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.toDrawable
import androidx.core.os.bundleOf
import com.google.android.material.button.MaterialButton
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.components.UserComponent
import com.habitrpg.android.habitica.data.InventoryRepository
@ -22,7 +18,6 @@ import com.habitrpg.android.habitica.events.GearPurchasedEvent
import com.habitrpg.android.habitica.events.ShowSnackbarEvent
import com.habitrpg.android.habitica.extensions.addCancelButton
import com.habitrpg.android.habitica.extensions.addCloseButton
import com.habitrpg.android.habitica.extensions.setTintWith
import com.habitrpg.android.habitica.helpers.AppConfigManager
import com.habitrpg.android.habitica.helpers.MainNavigationController
import com.habitrpg.android.habitica.helpers.RxErrorHandler

View file

@ -4,14 +4,12 @@ import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import android.widget.*
import androidx.annotation.IdRes
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.AppCompatCheckBox
import androidx.core.content.ContextCompat
import androidx.core.widget.CompoundButtonCompat
@ -333,9 +331,9 @@ class TaskFilterDialog(context: Context, component: UserComponent?) : HabiticaAl
private fun filtersChanged() {
clearButton.isEnabled = hasActiveFilters()
clearButton.setTextColor(if (clearButton.isEnabled) {
context.getThemeColor(R.color.colorAccent)
context.getThemeColor(R.attr.colorAccent)
} else {
context.getThemeColor(R.color.text_dimmed)
ContextCompat.getColor(context, R.color.text_dimmed)
})
}

View file

@ -6,11 +6,9 @@ import android.graphics.PorterDuff
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.CheckBox
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.data.TaskRepository
import com.habitrpg.android.habitica.data.UserRepository
@ -31,9 +29,6 @@ import kotlin.math.abs
class YesterdailyDialog private constructor(context: Context, private val userRepository: UserRepository, private val taskRepository: TaskRepository, private val tasks: List<Task>) : HabiticaAlertDialog(context) {
private lateinit var yesterdailiesList: LinearLayout
private val taskGray: Int = ContextCompat.getColor(context, R.color.disabled_background)
init {
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as? LayoutInflater
val view = inflater?.inflate(R.layout.dialog_yesterdaily, null)

View file

@ -11,12 +11,7 @@ public class RemindersManagerTest {
@Test
public void itCreatesRemindersItemFromDateString() {
// RemindersManager remindersManager = new RemindersManager("habits");
// RemindersItem remindersItem = remindersManager.createReminderFromDateString("dd MMMM yyyy HH:mm:ss")
// assert statements
assertEquals("10 x 0 must be 0", 0, 10 * 0 );
}
}

View file

@ -1,7 +1,6 @@
package com.habitrpg.android.habitica.helpers;
import com.habitrpg.android.habitica.R;
import com.habitrpg.android.habitica.models.HabitRpgClass;
import com.habitrpg.android.habitica.models.inventory.Equipment;
import com.habitrpg.android.habitica.models.members.Member;
import com.habitrpg.android.habitica.models.user.Stats;
@ -61,8 +60,8 @@ public class UserStatComputerTest {
@Test
public void shouldReturnClassBonusRowWhenClassMatches () {
user.getStats().setHabitClass(HabitRpgClass.rogue);
equipment.setKlass(HabitRpgClass.rogue.toString());
user.getStats().setHabitClass(Stats.ROGUE);
equipment.setKlass(Stats.ROGUE);
List<UserStatComputer.StatsRow> statsRows = userStatComputer.computeClassBonus(equipmentList, user);
UserStatComputer.AttributeRow attributeRow = (UserStatComputer.AttributeRow) statsRows.get(2);
@ -78,9 +77,9 @@ public class UserStatComputerTest {
@Test
public void ShouldReturnClassBonusRowWhenSpecialClassMatches () {
user.getStats().setHabitClass(HabitRpgClass.rogue);
user.getStats().setHabitClass(Stats.ROGUE);
equipment.setKlass("");
equipment.setSpecialClass(HabitRpgClass.rogue.toString());
equipment.setSpecialClass(Stats.ROGUE);
List<UserStatComputer.StatsRow> statsRows = userStatComputer.computeClassBonus(equipmentList, user);
UserStatComputer.AttributeRow attributeRow = (UserStatComputer.AttributeRow) statsRows.get(2);
@ -96,7 +95,7 @@ public class UserStatComputerTest {
@Test
public void shouldNotReturnClassBonusWhenClassDoesNotMatch () {
user.getStats().setHabitClass(HabitRpgClass.rogue);
user.getStats().setHabitClass(Stats.ROGUE);
equipment.setKlass("");
equipment.setSpecialClass("");

View file

@ -22,7 +22,7 @@ class MountTest {
mount.type = "drop"
`when`(mockContext.getString(R.string.standard)).thenReturn(FAKE_STANDARD)
val result: String = mount.getTranslatedType(mockContext)
val result = mount.getTranslatedType(mockContext)
assertThat(result).isEqualTo(FAKE_STANDARD)
}
@ -31,7 +31,7 @@ class MountTest {
fun testGetTranslatedStringReturnsPremiumWhenContextIsNull() {
mount.type = "premium"
val result: String = mount.getTranslatedType(null)
val result = mount.getTranslatedType(null)
assertThat(result).isEqualTo(FAKE_PREMIUM)
}

View file

@ -22,7 +22,7 @@ class PetTest {
pet.type = "drop"
`when`(mockContext.getString(R.string.standard)).thenReturn(FAKE_STANDARD)
val result: String = pet.getTranslatedType(mockContext)
val result = pet.getTranslatedType(mockContext)
assertThat(result).isEqualTo(FAKE_STANDARD)
}
@ -31,7 +31,7 @@ class PetTest {
fun testGetTranslatedStringReturnsPremiumWhenContextIsNull() {
pet.type = "premium"
val result: String = pet.getTranslatedType(null)
val result = pet.getTranslatedType(null)
assertThat(result).isEqualTo(FAKE_PREMIUM)
}