mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-22 13:48:55 +00:00
Widget fixes
This commit is contained in:
parent
164fefe228
commit
b146895a52
16 changed files with 73 additions and 35 deletions
|
|
@ -50,6 +50,7 @@ dependencies {
|
|||
implementation 'com.google.dagger:dagger:2.39.1'
|
||||
kapt 'com.google.dagger:dagger-compiler:2.39.1'
|
||||
compileOnly 'javax.annotation:javax.annotation-api:1.3.2'
|
||||
compileOnly 'com.github.pengrad:jdk9-deps:1.0'
|
||||
//App Compatibility and Material Design
|
||||
implementation 'androidx.appcompat:appcompat:1.4.0'
|
||||
implementation 'com.google.android.material:material:1.4.0'
|
||||
|
|
@ -151,7 +152,7 @@ android {
|
|||
buildConfigField "String", "TESTING_LEVEL", "\"production\""
|
||||
resConfigs "en", "bg", "de", "en-rGB", "es", "fr", "hr-rHR", "in", "it", "iw", "ja", "ko", "lt", "nl", "pl", "pt-rBR", "pt-rPT", "ru", "tr", "zh", "zh-rTW"
|
||||
|
||||
versionCode 3102
|
||||
versionCode 3109
|
||||
versionName "3.4.2"
|
||||
|
||||
targetSdkVersion 31
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@
|
|||
<shape
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@color/widget_background" />
|
||||
<corners android:radius="12dp" />
|
||||
<solid android:color="?android:attr/colorBackground" />
|
||||
<corners android:radius="?attr/widgetBackgroundRadius" />
|
||||
</shape>
|
||||
|
|
@ -2,15 +2,17 @@
|
|||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/widget_main_view"
|
||||
android:id="@android:id/background"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:focusable="true"
|
||||
android:focusableInTouchMode="true"
|
||||
android:background="@drawable/widget_background"
|
||||
android:padding="8dp"
|
||||
android:paddingVertical="8dp"
|
||||
android:paddingHorizontal="?widgetBackgroundRadius"
|
||||
android:elevation="2dp"
|
||||
android:orientation="vertical">
|
||||
android:orientation="vertical"
|
||||
android:theme="@style/MyWidgetTheme">
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
|
|
@ -64,7 +66,7 @@
|
|||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textColor="@color/text_primary"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="11sp"/>
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
|
|
@ -72,7 +74,7 @@
|
|||
android:gravity="center|end"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/HP_default"
|
||||
android:textColor="@color/text_primary"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="11sp"/>
|
||||
</LinearLayout></LinearLayout>
|
||||
</LinearLayout>
|
||||
|
|
@ -109,7 +111,7 @@
|
|||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textColor="@color/text_primary"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="11sp"/>
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
|
|
@ -117,7 +119,7 @@
|
|||
android:gravity="center|end"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/XP_default"
|
||||
android:textColor="@color/text_primary"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="11sp"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
|
@ -158,7 +160,7 @@
|
|||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textColor="@color/text_primary"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="11sp"/>
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
|
|
@ -166,7 +168,7 @@
|
|||
android:gravity="center|end"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/MP_default"
|
||||
android:textColor="@color/text_primary"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="11sp"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout></LinearLayout>
|
||||
|
|
@ -184,7 +186,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/text_secondary" />
|
||||
android:textColor="?android:attr/textColorSecondary" />
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
|
|
@ -202,7 +204,7 @@
|
|||
android:id="@+id/hourglasses_tv"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/text_secondary"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
style="@style/CurrencyTextView"
|
||||
/>
|
||||
|
||||
|
|
@ -216,7 +218,7 @@
|
|||
android:id="@+id/gems_tv"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/text_secondary"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
style="@style/CurrencyTextView"
|
||||
/>
|
||||
|
||||
|
|
@ -230,7 +232,7 @@
|
|||
android:id="@+id/gold_tv"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/text_secondary"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
style="@style/CurrencyTextView"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/white">
|
||||
android:background="@color/content_background">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/checkbox_background"
|
||||
|
|
@ -30,7 +30,7 @@
|
|||
android:paddingEnd="@dimen/task_text_padding"
|
||||
android:paddingStart="@dimen/task_text_padding"
|
||||
android:paddingTop="@dimen/task_top_bottom_compact_padding"
|
||||
android:textColor="@color/primary_text_light" />
|
||||
android:textColor="@color/text_primary" />
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/widget_background"
|
||||
android:theme="@style/MyWidgetTheme"
|
||||
android:id="@+id/widget"
|
||||
android:clipChildren="true"
|
||||
android:clipToPadding="true">
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@
|
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
android:orientation="vertical"
|
||||
android:theme="@style/MyWidgetTheme">
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
|||
|
|
@ -2,12 +2,13 @@
|
|||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/widget_list_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/MyWidgetTheme">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/white">
|
||||
android:background="@color/content_background">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/checkbox_background"
|
||||
|
|
@ -30,7 +31,7 @@
|
|||
android:paddingEnd="@dimen/task_text_padding"
|
||||
android:paddingStart="@dimen/task_text_padding"
|
||||
android:paddingTop="@dimen/task_top_bottom_compact_padding"
|
||||
android:textColor="@color/primary_text_light" />
|
||||
android:textColor="@color/text_primary" />
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
|
|
|
|||
6
Habitica/res/values-v31/styles.xml
Normal file
6
Habitica/res/values-v31/styles.xml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<style name="MyWidgetTheme" parent="@android:style/Theme.DeviceDefault.DayNight">
|
||||
<item name="widgetBackgroundRadius">@android:dimen/system_app_widget_background_radius</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
|
@ -26,6 +26,7 @@
|
|||
<attr name="headerBackgroundColor" format="color" />
|
||||
<attr name="headerOffsetColor" format="color" />
|
||||
<attr name="headerTextColor" format="color" />
|
||||
<attr name="widgetBackgroundRadius" format="dimension" />
|
||||
<declare-styleable name="AvatarView">
|
||||
<attr name="showBackground" format="boolean" />
|
||||
<attr name="showMount" format="boolean" />
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@
|
|||
<color name="btn_success">@color/green_10</color>
|
||||
<color name="btn_danger">@color/red_10</color>
|
||||
|
||||
<color name="widget_background">@color/gray_700</color>
|
||||
<color name="widget_background">@color/white</color>
|
||||
<color name="widget_bar_background">@color/offset_background</color>
|
||||
|
||||
<color name="gem_view_background">@color/window_background</color>
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@
|
|||
<dimen name="row_title_size">16sp</dimen>
|
||||
<dimen name="row_text_size">14sp</dimen>
|
||||
<dimen name="row_title_bottommargin">2dp</dimen>
|
||||
<dimen name="pet_width">88dp</dimen>
|
||||
<dimen name="pet_width">92dp</dimen>
|
||||
<dimen name="mount_width">120dp</dimen>
|
||||
<dimen name="bottom_menu_padding">20dp</dimen>
|
||||
<dimen name="pet_image_width">68dp</dimen>
|
||||
|
|
|
|||
|
|
@ -253,6 +253,13 @@
|
|||
<item name="toolbarContentColor">@color/blue_100</item>
|
||||
</style>
|
||||
|
||||
<style name="MyWidgetTheme">
|
||||
<item name="widgetBackgroundRadius">@dimen/my_background_radius_dimen</item>
|
||||
<item name="android:textColorPrimary">@color/text_primary</item>
|
||||
<item name="android:textColorSecondary">@color/text_secondary</item>
|
||||
<item name="android:colorBackground">@color/widget_background</item>
|
||||
</style>
|
||||
|
||||
<style name="BottomSheetTheme" parent="Theme.AppCompat.NoActionBar">
|
||||
<item name="android:windowIsTranslucent">false</item>
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
|
|
@ -832,4 +839,6 @@
|
|||
<item name="android:textSize">12sp</item>
|
||||
<item name="android:textStyle">bold</item>
|
||||
</style>
|
||||
|
||||
<dimen name="my_background_radius_dimen">12dp</dimen>
|
||||
</resources>
|
||||
|
|
@ -108,7 +108,6 @@ import com.habitrpg.android.habitica.ui.views.shops.PurchaseDialog;
|
|||
import com.habitrpg.android.habitica.ui.views.social.ChatBarView;
|
||||
import com.habitrpg.android.habitica.ui.views.stats.BulkAllocateStatsDialog;
|
||||
import com.habitrpg.android.habitica.ui.views.tasks.TaskFilterDialog;
|
||||
import com.habitrpg.android.habitica.widget.AvatarStatsWidgetFactory;
|
||||
import com.habitrpg.android.habitica.widget.AvatarStatsWidgetProvider;
|
||||
import com.habitrpg.android.habitica.widget.BaseWidgetProvider;
|
||||
import com.habitrpg.android.habitica.widget.DailiesWidgetProvider;
|
||||
|
|
@ -344,7 +343,6 @@ public interface UserComponent {
|
|||
|
||||
void inject(@NotNull EquipmentOverviewViewModel equipmentOverviewViewModel);
|
||||
|
||||
void inject(@NotNull AvatarStatsWidgetFactory avatarStatsWidgetFactory);
|
||||
void inject(@NotNull AccountPreferenceFragment accountPreferenceFragment);
|
||||
|
||||
void inject(@NotNull AuthenticationViewModel authenticationViewModel);
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ class AccountPreferenceFragment: BasePreferencesFragment(),
|
|||
|
||||
val passwordPref = findPreference<ExtraLabelPreference>("password")
|
||||
if (user.authentication?.hasPassword == true) {
|
||||
passwordPref?.summary = "✴✴✴✴✴✴✴✴✴✴✴"
|
||||
passwordPref?.summary = "···········"
|
||||
passwordPref?.extraText = getString(R.string.change_password)
|
||||
} else {
|
||||
passwordPref?.summary = getString(R.string.not_set)
|
||||
|
|
@ -350,8 +350,8 @@ class AccountPreferenceFragment: BasePreferencesFragment(),
|
|||
dialog.setTitle(R.string.change_email)
|
||||
dialog.addButton(R.string.change, true, false, false) { dialog, _ ->
|
||||
KeyboardUtil.dismissKeyboard(activity)
|
||||
if (passwordEditText?.isValid != true || emailEditText?.isValid != true) return@addButton
|
||||
userRepository.updateEmail(emailEditText.text.toString(), passwordEditText.text.toString())
|
||||
if (emailEditText?.isValid != true) return@addButton
|
||||
userRepository.updateEmail(emailEditText.text.toString(), passwordEditText?.text.toString())
|
||||
.flatMap { userRepository.retrieveUser(true, true) }
|
||||
.subscribe(
|
||||
{
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class ValidatingEditText @JvmOverloads constructor(
|
|||
var validator: ((String?) -> Boolean)? = null
|
||||
|
||||
val isValid: Boolean
|
||||
get() = validator?.invoke(text) == true
|
||||
get() = validator?.invoke(text) != false
|
||||
|
||||
init {
|
||||
orientation = VERTICAL
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import android.widget.RemoteViews
|
|||
import com.habitrpg.android.habitica.HabiticaBaseApplication
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.extensions.dpToPx
|
||||
import com.habitrpg.android.habitica.extensions.withImmutableFlag
|
||||
import com.habitrpg.android.habitica.helpers.HealthFormatter
|
||||
import com.habitrpg.android.habitica.helpers.NumberAbbreviator
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
|
|
@ -21,6 +22,7 @@ import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper
|
|||
|
||||
class AvatarStatsWidgetProvider : BaseWidgetProvider() {
|
||||
|
||||
private var user: User? = null
|
||||
private var appWidgetManager: AppWidgetManager? = null
|
||||
|
||||
private var showManaBar: Boolean = true
|
||||
|
|
@ -37,13 +39,28 @@ class AvatarStatsWidgetProvider : BaseWidgetProvider() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onEnabled(context: Context) {
|
||||
super.onEnabled(context)
|
||||
userRepository.getUser().subscribe({
|
||||
user = it
|
||||
updateData()
|
||||
}, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
|
||||
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
|
||||
super.onUpdate(context, appWidgetManager, appWidgetIds)
|
||||
this.setUp()
|
||||
this.appWidgetManager = appWidgetManager
|
||||
this.context = context
|
||||
|
||||
userRepository.getUser().firstElement()?.subscribe({ this.updateData(it) }, RxErrorHandler.handleEmptyError())
|
||||
if (user == null) {
|
||||
userRepository.getUser().firstElement()?.subscribe({
|
||||
user = it
|
||||
updateData(appWidgetIds)
|
||||
}, RxErrorHandler.handleEmptyError())
|
||||
} else {
|
||||
updateData()
|
||||
}
|
||||
}
|
||||
|
||||
override fun configureRemoteViews(remoteViews: RemoteViews, widgetId: Int, columns: Int, rows: Int): RemoteViews {
|
||||
|
|
@ -64,15 +81,16 @@ class AvatarStatsWidgetProvider : BaseWidgetProvider() {
|
|||
return remoteViews
|
||||
}
|
||||
|
||||
private fun updateData(user: User?) {
|
||||
private fun updateData(widgetIds: IntArray? = null) {
|
||||
val context = context
|
||||
val appWidgetManager = appWidgetManager
|
||||
val user = user
|
||||
val stats = user?.stats
|
||||
if (user == null || stats == null || context == null || appWidgetManager == null) {
|
||||
return
|
||||
}
|
||||
val thisWidget = ComponentName(context, AvatarStatsWidgetProvider::class.java)
|
||||
val allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget)
|
||||
val allWidgetIds = widgetIds ?: appWidgetManager.getAppWidgetIds(thisWidget)
|
||||
val currentHealth = HealthFormatter.format(stats.hp ?: 0.0)
|
||||
val currentHealthString = HealthFormatter.formatToString(stats.hp ?: 0.0)
|
||||
val healthValueString = currentHealthString + "/" + stats.maxHealth
|
||||
|
|
@ -125,8 +143,8 @@ class AvatarStatsWidgetProvider : BaseWidgetProvider() {
|
|||
}
|
||||
|
||||
val openAppIntent = Intent(context.applicationContext, MainActivity::class.java)
|
||||
val openApp = PendingIntent.getActivity(context, 0, openAppIntent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
remoteViews.setOnClickPendingIntent(R.id.widget_main_view, openApp)
|
||||
val openApp = PendingIntent.getActivity(context, 0, openAppIntent, withImmutableFlag(PendingIntent.FLAG_UPDATE_CURRENT))
|
||||
remoteViews.setOnClickPendingIntent(android.R.id.background, openApp)
|
||||
|
||||
val options = appWidgetManager.getAppWidgetOptions(widgetId)
|
||||
remoteViews = sizeRemoteViews(context, options, widgetId)
|
||||
|
|
|
|||
Loading…
Reference in a new issue