Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosFdez committed Nov 12, 2018
2 parents 9295066 + 0d5686c commit 4b2e413
Show file tree
Hide file tree
Showing 171 changed files with 5,527 additions and 4,928 deletions.
Expand Up @@ -391,7 +391,11 @@ private SQLiteDatabase createOrOpenDatabase(boolean force) throws SQLiteAssetExc
if (fileExists && force) {
Log.w(TAG, "forcing database upgrade!");
db = returnDatabase();
preCopyDatabase(db);
if (db != null) {
preCopyDatabase(db);
db.close();
}

copyDatabaseFromAssets();
db = returnDatabase();
postCopyDatabase(db);
Expand Down
12 changes: 10 additions & 2 deletions app/build.gradle
Expand Up @@ -25,8 +25,12 @@ android {
//2.0.2 Version Code:10 Released 9-??-2018
//2.1.0 Version Code:11 Released 9-??-2018
//2.1.1 Version Code:12 Released 9-??-2018
versionCode 12
versionName "2.1.1"
//2.2.0 Version Code:13 Released 10-08-2018
//2.2.1 Version Code:14 Released 10-14-2018
//2.3.0 Version Code:15 Released 11-07-2018
//2.3.1 Version Code:16 Released 11-07-2018
versionCode 16
versionName "2.3.1"

compileOptions {
// we'll still be able to target lower java versions because of desugar
Expand All @@ -42,6 +46,10 @@ android {
}
}

lintOptions {
disable 'MissingTranslation'
}

buildTypes {
release {
minifyEnabled true
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Expand Up @@ -117,7 +117,7 @@
android:label="@string/app_name"
android:screenOrientation="portrait" />
<activity
android:name="com.ghstudios.android.features.skills.SkillTreeDetailPagerActivity"
android:name="com.ghstudios.android.features.skills.detail.SkillTreeDetailPagerActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<meta-data
Expand Down
Binary file modified app/src/main/assets/databases/mhgu.db.zip
Binary file not shown.
78 changes: 70 additions & 8 deletions app/src/main/java/com/ghstudios/android/AppSettings.kt
Expand Up @@ -3,20 +3,46 @@ package com.ghstudios.android
import android.app.Application
import android.content.Context.MODE_PRIVATE
import android.content.SharedPreferences
import com.ghstudios.android.util.edit
import java.util.*

/**
* A list of language codes available for existing app translations
*/
val appLanguages = listOf("en", "de")

/** A list of all possible supported languages (across all sources)
* mapping code to name.
*/
val allLanguages = mapOf(
"en" to "English",
"es" to "Español",
"fr" to "Français",
"de" to "Deutsch",
"it" to "Italiano"
//"ja" to "日本語" // japanese data is incomplete
)

/**
* A static class used to manage shared preferences and application settings.
* Must be initialized via the AppSettings.bindApplication() function.
*/
class AppSettings {
companion object {
@JvmStatic
val SETTINGS_FILE_NAME = "MHGUDatabase.settings"

private var application : Application? = null
private var application: Application? = null

/**
* Initializes AppSettings. Use in the onCreate event of the application object.
*/
@JvmStatic
fun bindApplication(app : Application) {
fun bindApplication(app: Application) {
application = app
}

private val sharedPreferences : SharedPreferences
private val sharedPreferences: SharedPreferences
get() {
if (application == null) {
throw UninitializedPropertyAccessException("Application not initialized")
Expand All @@ -26,14 +52,50 @@ class AppSettings {

@JvmStatic
val isJapaneseEnabled
get() = sharedPreferences.getBoolean(JAPANESE_ENABLED, false)
get() = sharedPreferences.getBoolean(PROP_JAPANESE_ENABLED, false)

/**
* Setting to decide whether negative skill items should be shown or not.
* Changes are commited asynchronously, and may take a bit
*/
@JvmStatic
val dataLocale : String
get() = sharedPreferences.getString(DATA_LOCALE, "en")
var showSkillPenalties
get() = sharedPreferences.getBoolean("SHOW_NEGATIVE_SKILL_ITEMS", false)
set(value) {
sharedPreferences.edit {
putBoolean("SHOW_NEGATIVE_SKILL_ITEMS", value)
}
}

/**
* Returns the "true" data locale setting.
* This is used when resolving locales, queries should instead use the dataLocale property.
*/
@JvmStatic
val trueDataLocale: String
get() = sharedPreferences.getString(PROP_DATA_LOCALE, "")

/**
* Returns the data locale, with the empty locale resolving to the app language, or en if invalid.
*/
@JvmStatic
val dataLocale: String
get() {
val pref = trueDataLocale
if (pref.isNotBlank()) {
return pref
}

val locale = Locale.getDefault().language
return when (locale) {
in appLanguages -> locale
else -> "en"
}
}

// keys
private val JAPANESE_ENABLED = "JAPANESE_ENABLED"
private val DATA_LOCALE = "DATA_LOCALE"
private const val PROP_JAPANESE_ENABLED = "JAPANESE_ENABLED"
const val PROP_APP_LOCALE = "APP_LOCALE"
const val PROP_DATA_LOCALE = "DATA_LOCALE"
}
}
148 changes: 142 additions & 6 deletions app/src/main/java/com/ghstudios/android/AssetLoader.kt
Expand Up @@ -4,11 +4,12 @@ import android.app.Application
import android.graphics.PorterDuff
import android.graphics.drawable.Drawable
import android.support.v4.content.ContextCompat
import android.util.Log
import android.widget.ImageView
import com.ghstudios.android.data.classes.Gathering
import com.ghstudios.android.data.classes.QuestHub
import com.ghstudios.android.data.classes.*
import com.ghstudios.android.mhgendatabase.R
import com.ghstudios.android.util.MHUtils
import com.ghstudios.android.util.getDrawableCompat

/**
* A static class used to load icons for various database objects.
Expand All @@ -19,6 +20,8 @@ object AssetLoader {

private val ctx get() = application.applicationContext

private const val TAG = "MHAssetLoader"

fun bindApplication(app: Application) {
application = app
}
Expand Down Expand Up @@ -48,6 +51,16 @@ object AssetLoader {
}
}

/**
* Loads an icon for the given ElementStatus.
* todo: is it nonsensical to make an enum into an ITintedIcon?
*/
@JvmStatic
fun loadIconFor(element: ElementStatus): Drawable? {
val resId = ElementRegistry.get(element, default=R.color.transparent)
return ctx.getDrawableCompat(resId)
}

@JvmStatic
fun setIcon(iv: ImageView, item: ITintedIcon?) {
if (item == null) {
Expand All @@ -57,6 +70,43 @@ object AssetLoader {
}
}

/**
* Returns the rarity as a display string.
* Rarity of value 11 is turned into "X", everything else is just the string version
*/
@JvmStatic fun localizeRarity(rarity: Int) = when (rarity) {
11 -> "X"
else -> rarity.toString()
}

/**
* Returns the rarity label name, in the form of "Rare X".
* If rarity is 11, it is rendered as "Rare X"
*/
@JvmStatic fun localizeRarityLabel(rarity: Int)
= application.getString(R.string.value_rare, localizeRarity(rarity))

/**
* Returns a localized human readable weapon name for a weapon type
*/
@JvmStatic fun localizeWeaponType(type: String) = ctx.getString(when (type) {
Weapon.GREAT_SWORD -> R.string.type_weapon_greatsword
Weapon.LONG_SWORD -> R.string.type_weapon_longsword
Weapon.SWORD_AND_SHIELD -> R.string.type_weapon_swordandshield
Weapon.DUAL_BLADES -> R.string.type_weapon_dualblades
Weapon.HAMMER -> R.string.type_weapon_hammer
Weapon.HUNTING_HORN -> R.string.type_weapon_huntinghorn
Weapon.LANCE -> R.string.type_weapon_lance
Weapon.GUNLANCE -> R.string.type_weapon_gunlance
Weapon.SWITCH_AXE -> R.string.type_weapon_switchaxe
Weapon.CHARGE_BLADE -> R.string.type_weapon_chargeblade
Weapon.INSECT_GLAIVE -> R.string.type_weapon_insectglaive
Weapon.LIGHT_BOWGUN -> R.string.type_weapon_lightbowgun
Weapon.HEAVY_BOWGUN -> R.string.type_weapon_heavybowgun
Weapon.BOW -> R.string.type_weapon_bow
else -> R.string.type_weapon
})

/**
* Returns a localized string that represents the hub type,
* aka Village/Guild/Event/Permit
Expand All @@ -70,6 +120,30 @@ object AssetLoader {
null -> "NULL"
}

/**
* Returns a localized string of the gathering site for the given Gathering object.
*/
@JvmStatic fun localizeGatherSite(gather: Gathering): String {
val resId = when (gather.site) {
"Bug" -> R.string.gather_site_bug
"Fishing (Burst Bait)" -> R.string.gather_site_fishing_burst
"Fishing (Goldenfish Bait)" -> R.string.gather_site_fishing_goldenfish
"Fishing (Mega Fishing Fly)" -> R.string.gather_site_fishing_megafly
"Fishing (No Bait)" -> R.string.gather_site_fishing_none
"Fishing (Sushifish Bait)" -> R.string.gather_site_fishing_sushi
"Gather" -> R.string.gather_site_gather
"Mine" -> R.string.gather_site_mine
else -> 0
}

if (resId == 0) {
Log.e(TAG, "Unknown gathering site ${gather.site}, not localized")
return gather.site ?: ""
}

return ctx.getString(resId)
}

/**
* Returns a localized string that represents the gathering node's site modifier.
* For example, Fixed, Rare, Common
Expand All @@ -82,11 +156,73 @@ object AssetLoader {

/**
* Returns a localized string that represents the gathering type.
* For example, Mine [Fixed] and Gather [Rare].
* TODO: Localize the first part...
* For example, [Fixed] Mine and [Rare] Gather.
*/
@JvmStatic fun localizeGatherNodeFull(gather: Gathering): String {
val modifier = localizeGatherModifier(gather)
return ctx.getString(R.string.item_gather_full, gather.site, modifier)
if ("Fishing" in (gather.site ?: "")) {
return localizeGatherSite(gather)
} else {
val site = AssetLoader.localizeGatherSite(gather)
val modifier = localizeGatherModifier(gather)
return ctx.getString(R.string.item_gather_full, site, modifier)
}
}

@JvmStatic fun localizeRank(rank: Rank) = when (rank) {
Rank.LOW -> ctx.getString(R.string.rank_lr)
Rank.HIGH -> ctx.getString(R.string.rank_hr)
Rank.G -> ctx.getString(R.string.rank_g)
Rank.ANY -> ctx.getString(R.string.rank_any)
}

/**
* Localizes a gunlance's shelling type string
*/
@JvmStatic fun localizeWeaponShelling(type: String?): String {
if (type == null) return ""

val parts = type.split(' ')
val name = when(parts.firstOrNull()) {
"Wide" -> ctx.getString(R.string.shelling_wide)
"Normal" -> ctx.getString(R.string.shelling_normal)
"Long" -> ctx.getString(R.string.shelling_long)
else -> parts.firstOrNull() ?: ""
}

return name + " " + parts.subList(1, parts.size).joinToString(" ")
}

/**
* Localizes a weapon's phial type
*/
@JvmStatic fun localizeWeaponPhialType(type: String?) = when (type) {
"Power" -> ctx.getString(R.string.phial_power)
"Poison" -> ctx.getString(R.string.phial_poison)
"Paralysis" -> ctx.getString(R.string.phial_paralysis)
"Exhaust" -> ctx.getString(R.string.phial_exhaust)
"Dragon" -> ctx.getString(R.string.phial_dragon)
"Impact" -> ctx.getString(R.string.phial_impact)
"Element" -> ctx.getString(R.string.phial_element)
else -> type ?: ""
}

/**
* Localizes a bow's weapon charge level, returning a string in the form Rapid 2, with
* the name localized to the specific language.
*/
@JvmStatic fun localizeChargeLevel(level: WeaponChargeLevel): String {
val name = when (level.name) {
"Rapid" -> ctx.getString(R.string.bow_charge_rapid)
"Pierce" -> ctx.getString(R.string.bow_charge_pierce)
"Spread" -> ctx.getString(R.string.bow_charge_spread)
"Heavy" -> ctx.getString(R.string.bow_charge_heavy)
else -> level.name
}

return if (level.locked) {
ctx.getString(R.string.bow_charge_format_locked, name, level.level)
} else {
ctx.getString(R.string.bow_charge_format, name, level.level)
}
}
}

0 comments on commit 4b2e413

Please sign in to comment.