Fix issues with new design

This commit is contained in:
Phillip Thelen 2020-08-26 12:58:04 +02:00
parent 54fadb1e20
commit 31b8d68f9c
30 changed files with 261 additions and 67 deletions

View file

@ -162,7 +162,7 @@ android {
multiDexEnabled true
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 2514
versionCode 2515
versionName "2.8"
}

View file

@ -17,7 +17,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:theme="@style/Toolbar"
android:theme="@style/Toolbar.Modern"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/Theme.AppCompat.Light"/>

View file

@ -17,9 +17,9 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:theme="@style/Toolbar"
android:theme="@style/Toolbar.Modern"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"/>
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView

View file

@ -15,7 +15,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.activities.MainActivity">
<fragment
<androidx.fragment.app.FragmentContainerView
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
@ -33,6 +33,7 @@
android:layout_height="wrap_content"
app:titleEnabled="false"
app:contentScrim="?attr/headerBackgroundColor"
android:background="?attr/headerBackgroundColor"
app:expandedTitleMarginEnd="?attr/actionBarSize"
app:expandedTitleMarginStart="0dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
@ -43,6 +44,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?attr/actionBarSize"
android:layout_marginEnd="@dimen/header_border_spacing"
android:layout_marginStart="@dimen/header_border_spacing"
app:layout_collapseMode="parallax" />
<androidx.appcompat.widget.Toolbar
@ -67,6 +70,8 @@
android:ellipsize="end"
android:maxLines="1"
android:singleLine="true"
android:layout_toStartOf="@id/toolbar_accessory_container"
android:layout_alignParentStart="true"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
tools:text="Habitica"/>

View file

@ -17,9 +17,9 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:theme="@style/Toolbar"
android:theme="@style/Toolbar.Modern"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" />
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</com.google.android.material.appbar.AppBarLayout>

View file

@ -22,9 +22,9 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:theme="@style/Toolbar"
android:theme="@style/Toolbar.Modern"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"/>
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
</com.google.android.material.appbar.AppBarLayout>
@ -33,17 +33,17 @@
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
android:background="?attr/colorPrimary"
android:background="@color/gray_700"
android:elevation="0dp"
android:fillViewport="false"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:theme="@style/ThemeOverlay.AppCompat.Light"
app:layout_anchor="@+id/collapsing_toolbar"
app:layout_anchorGravity="bottom"
app:layout_collapseMode="pin"
app:tabGravity="fill"
app:tabIndicatorColor="@android:color/white"
app:tabIndicatorColor="?attr/colorPrimary"
app:tabMode="fixed" />
<androidx.viewpager.widget.ViewPager

View file

@ -17,7 +17,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:theme="@style/Toolbar"
android:theme="@style/Toolbar.Modern"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"/>

View file

@ -17,9 +17,9 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:theme="@style/Toolbar"
android:theme="@style/Toolbar.Modern"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"/>
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
</com.google.android.material.appbar.AppBarLayout>

View file

@ -17,9 +17,9 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:theme="@style/Toolbar"
android:theme="@style/Toolbar.Modern"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"/>
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
</com.google.android.material.appbar.AppBarLayout>

View file

@ -9,11 +9,7 @@
android:background="?attr/headerBackgroundColor"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:paddingEnd="@dimen/header_border_spacing"
android:paddingLeft="@dimen/header_border_spacing"
android:paddingRight="@dimen/header_border_spacing"
android:paddingStart="@dimen/header_border_spacing">
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"

View file

@ -16,6 +16,7 @@
android:textColor="#000"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingExtra="2sp"
android:textSize="15sp"
tools:text="Habit Title" />

View file

@ -276,7 +276,7 @@
<style name="Toolbar" parent="Base.ThemeOverlay.AppCompat.ActionBar">
<item name="android:textColorPrimary">?attr/toolbarContentColor</item>
<item name="textColorSecondary">?attr/toolbarContentColor</item>
<item name="background">?attr/colorPrimary</item>
<item name="background">?attr/headerBackgroundColor</item>
<item name="actionMenuTextColor">?attr/toolbarContentColor</item>
<item name="android:actionMenuTextColor">?attr/toolbarContentColor</item>
</style>

View file

@ -14,7 +14,7 @@ import java.util.*
interface SocialRepository : BaseRepository {
fun getPublicGuilds(): Flowable<RealmResults<Group>>
fun getUserGroups(): Flowable<RealmResults<Group>>
fun getUserGroups(type: String?): Flowable<RealmResults<Group>>
fun retrieveGroupChat(groupId: String): Single<List<ChatMessage>>
fun getGroupChat(groupId: String): Flowable<RealmResults<ChatMessage>>

View file

@ -273,7 +273,7 @@ class SocialRepositoryImpl(localRepository: SocialLocalRepository, apiClient: Ap
}
}
override fun getUserGroups(): Flowable<RealmResults<Group>> = localRepository.getUserGroups(userID)
override fun getUserGroups(type: String?): Flowable<RealmResults<Group>> = localRepository.getUserGroups(userID, type)
override fun acceptQuest(user: User?, partyId: String): Flowable<Void> {
return apiClient.acceptQuest(partyId)

View file

@ -12,7 +12,7 @@ import io.realm.RealmResults
interface SocialLocalRepository : BaseLocalRepository {
fun getPublicGuilds(): Flowable<RealmResults<Group>>
fun getUserGroups(userID: String): Flowable<RealmResults<Group>>
fun getUserGroups(userID: String, type: String?): Flowable<RealmResults<Group>>
fun getGroups(type: String): Flowable<RealmResults<Group>>
fun getGroup(id: String): Flowable<Group>

View file

@ -106,14 +106,14 @@ class RealmSocialLocalRepository(realm: Realm) : RealmBaseLocalRepository(realm)
.asFlowable()
.filter { it.isLoaded }
override fun getUserGroups(userID: String): Flowable<RealmResults<Group>> = realm.where(GroupMembership::class.java)
override fun getUserGroups(userID: String, type: String?): Flowable<RealmResults<Group>> = realm.where(GroupMembership::class.java)
.equalTo("userID", userID)
.findAll()
.asFlowable()
.filter { it.isLoaded }
.flatMap {memberships ->
realm.where(Group::class.java)
.equalTo("type", "guild")
.equalTo("type", type ?: "guild")
.notEqualTo("id", Group.TAVERN_ID)
.`in`("id", memberships.map {
return@map it.groupID

View file

@ -2,8 +2,30 @@ package com.habitrpg.android.habitica.extensions
import android.content.Context
import android.view.View
import android.view.ViewTreeObserver
fun View.setScaledPadding(context: Context?, left: Int, top: Int, right: Int, bottom: Int) {
this.setPadding(left.dpToPx(context), top.dpToPx(context), right.dpToPx(context), bottom.dpToPx(context))
}
inline fun View.waitForLayout(crossinline f: View.() -> Unit) = with(viewTreeObserver) {
addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
viewTreeObserver.removeOnGlobalLayoutListener(this)
f()
}
})
}
inline fun View.afterMeasured(crossinline f: View.() -> Unit) {
viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
if (measuredWidth > 0 && measuredHeight > 0) {
viewTreeObserver.removeOnGlobalLayoutListener(this)
f()
}
}
})
}

View file

@ -1,14 +1,22 @@
package com.habitrpg.android.habitica.ui.activities
import android.app.Activity
import android.content.Context
import android.content.SharedPreferences
import android.content.res.Configuration
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.Menu
import android.view.View
import android.view.ViewGroup
import android.view.ViewTreeObserver.OnGlobalLayoutListener
import android.widget.ImageButton
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.view.menu.ActionMenuItemView
import androidx.appcompat.widget.Toolbar
import androidx.preference.PreferenceManager
import com.habitrpg.android.habitica.HabiticaApplication
@ -18,6 +26,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.helpers.LanguageHelper
import com.habitrpg.android.habitica.ui.helpers.ToolbarColorHelper
import com.habitrpg.android.habitica.ui.views.dialogs.HabiticaAlertDialog
import io.reactivex.disposables.CompositeDisposable
import org.greenrobot.eventbus.EventBus
@ -31,6 +40,8 @@ abstract class BaseActivity : AppCompatActivity() {
internal var forcedTheme: String? = null
private var destroyed: Boolean = false
open var overrideModernHeader: Boolean? = null
protected abstract fun getLayoutResId(): Int
open fun getContentView(): View {
@ -94,29 +105,29 @@ abstract class BaseActivity : AppCompatActivity() {
} else {
sharedPreferences.getString("theme_name", "purple")
}
val modernHeaderStyle = sharedPreferences.getBoolean("modern_header_style", true)
if (theme == currentTheme) return
setTheme(when (theme) {
"maroon" -> R.style.MainAppTheme_Maroon
"red" -> R.style.MainAppTheme_Red
"orange" -> R.style.MainAppTheme_Orange
"yellow" -> R.style.MainAppTheme_Yellow
"green" -> R.style.MainAppTheme_Green
"teal" -> R.style.MainAppTheme_Teal
"blue" -> R.style.MainAppTheme_Blue
else -> R.style.MainAppTheme
})
window.navigationBarColor = getThemeColor(R.attr.colorPrimaryDark)
window.statusBarColor = if (modernHeaderStyle && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
getThemeColor(R.attr.headerBackgroundColor)
} else {
getThemeColor(R.attr.colorPrimaryDark)
val modernHeaderStyle = overrideModernHeader ?: sharedPreferences.getBoolean("modern_header_style", true)
if (theme != currentTheme) {
setTheme(when (theme) {
"maroon" -> R.style.MainAppTheme_Maroon
"red" -> R.style.MainAppTheme_Red
"orange" -> R.style.MainAppTheme_Orange
"yellow" -> R.style.MainAppTheme_Yellow
"green" -> R.style.MainAppTheme_Green
"teal" -> R.style.MainAppTheme_Teal
"blue" -> R.style.MainAppTheme_Blue
else -> R.style.MainAppTheme
})
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
window.navigationBarColor = getThemeColor(R.attr.colorPrimaryDark)
if (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
} else {
window.statusBarColor = getThemeColor(R.attr.colorPrimaryDark)
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
}
if (currentTheme != null) {
if (currentTheme != null && theme != currentTheme) {
reload()
} else {
currentTheme = theme
@ -138,6 +149,7 @@ abstract class BaseActivity : AppCompatActivity() {
actionBar.setHomeButtonEnabled(true)
}
}
toolbar?.let { ToolbarColorHelper.colorizeToolbar(it, this, overrideModernHeader) }
}
override fun onDestroy() {

View file

@ -25,11 +25,13 @@ import com.habitrpg.android.habitica.models.tasks.Task
import com.habitrpg.android.habitica.models.user.User
import com.habitrpg.android.habitica.modules.AppModule
import com.habitrpg.android.habitica.ui.adapter.social.challenges.ChallengeTasksRecyclerViewAdapter
import com.habitrpg.android.habitica.ui.helpers.ToolbarColorHelper
import com.habitrpg.android.habitica.ui.helpers.bindView
import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper
import com.habitrpg.android.habitica.ui.views.dialogs.HabiticaAlertDialog
import io.reactivex.Flowable
import io.reactivex.functions.Consumer
import io.reactivex.rxkotlin.zipWith
import java.util.*
import javax.inject.Inject
import javax.inject.Named
@ -71,6 +73,7 @@ class ChallengeFormActivity : BaseActivity() {
private val updatedTasks = HashMap<String, Task>()
private val removedTasks = HashMap<String, Task>()
override var overrideModernHeader: Boolean? = true
// Add {*} Items
private var addHabit: Task? = null
private var addDaily: Task? = null
@ -117,6 +120,7 @@ class ChallengeFormActivity : BaseActivity() {
override fun onCreateOptionsMenu(menu: Menu): Boolean {
val inflater = menuInflater
inflater.inflate(R.menu.menu_create_challenge, menu)
findViewById<Toolbar>(R.id.toolbar).let { ToolbarColorHelper.colorizeToolbar(it, this, overrideModernHeader) }
return true
}
@ -319,15 +323,21 @@ class ChallengeFormActivity : BaseActivity() {
}
locationAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
compositeSubscription.add(socialRepository.getGroups("guild").subscribe(Consumer { groups ->
val mutableGroups = groups.toMutableList()
if (groups.firstOrNull { it.id == "00000000-0000-4000-A000-000000000000" } == null) {
compositeSubscription.add(socialRepository.getUserGroups("guild").zipWith(userRepository.getUser()
.map { it.party?.id ?: "" }
.distinctUntilChanged()
.flatMap { socialRepository.getGroup(it) })
.subscribe(Consumer { groups ->
val mutableGroups = groups.first.toMutableList()
if (groups.first.firstOrNull { it.id == "00000000-0000-4000-A000-000000000000" } == null) {
val tavern = Group()
tavern.id = "00000000-0000-4000-A000-000000000000"
tavern.name = getString(R.string.public_challenge)
mutableGroups.add(0, tavern)
}
if (groups.second != null) {
mutableGroups.add(groups.second)
}
locationAdapter.clear()
locationAdapter.addAll(mutableGroups)
}, RxErrorHandler.handleEmptyError()))

View file

@ -33,10 +33,7 @@ import com.habitrpg.android.habitica.models.user.Stats
import com.habitrpg.android.habitica.ui.AvatarView
import com.habitrpg.android.habitica.ui.AvatarWithBarsViewModel
import com.habitrpg.android.habitica.ui.adapter.social.AchievementProfileAdapter
import com.habitrpg.android.habitica.ui.helpers.bindView
import com.habitrpg.android.habitica.ui.helpers.dismissKeyboard
import com.habitrpg.android.habitica.ui.helpers.loadImage
import com.habitrpg.android.habitica.ui.helpers.setMarkdown
import com.habitrpg.android.habitica.ui.helpers.*
import com.habitrpg.android.habitica.ui.views.HabiticaSnackbar
import com.habitrpg.android.habitica.ui.views.HabiticaSnackbar.SnackbarDisplayType
import com.habitrpg.android.habitica.ui.views.dialogs.HabiticaAlertDialog
@ -141,6 +138,7 @@ class FullProfileActivity : BaseActivity() {
} else {
item?.title = getString(R.string.block)
}
findViewById<Toolbar>(R.id.toolbar).let { ToolbarColorHelper.colorizeToolbar(it, this, overrideModernHeader) }
return super.onCreateOptionsMenu(menu)
}

View file

@ -6,6 +6,7 @@ import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import androidx.viewpager.widget.ViewPager
@ -19,6 +20,7 @@ import com.habitrpg.android.habitica.helpers.RxErrorHandler
import com.habitrpg.android.habitica.models.user.User
import com.habitrpg.android.habitica.modules.AppModule
import com.habitrpg.android.habitica.ui.fragments.social.party.PartyInviteFragment
import com.habitrpg.android.habitica.ui.helpers.ToolbarColorHelper
import com.habitrpg.android.habitica.ui.helpers.bindView
import com.habitrpg.android.habitica.ui.helpers.dismissKeyboard
import com.habitrpg.android.habitica.ui.views.HabiticaSnackbar
@ -66,7 +68,6 @@ class GroupInviteActivity : BaseActivity() {
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.menu_party_invite, menu)
return true
}

View file

@ -26,6 +26,7 @@ import androidx.lifecycle.ViewModelProviders
import androidx.navigation.NavController
import androidx.navigation.NavDestination
import androidx.navigation.findNavController
import androidx.navigation.fragment.NavHostFragment
import com.facebook.drawee.view.SimpleDraweeView
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.perf.FirebasePerformance
@ -195,7 +196,7 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
.get(NotificationsViewModel::class.java)
notificationsViewModel = viewModel
val drawerLayout = findViewById<androidx.drawerlayout.widget.DrawerLayout>(R.id.drawer_layout)
val drawerLayout = findViewById<DrawerLayout>(R.id.drawer_layout)
drawerFragment = supportFragmentManager.findFragmentById(R.id.navigation_drawer) as? NavigationDrawerFragment
@ -216,11 +217,11 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
override fun onDrawerSlide(drawerView: View, slideOffset: Float) {
val modernHeaderStyle = sharedPreferences.getBoolean("modern_header_style", true)
if (modernHeaderStyle && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (slideOffset < 0.1f && isOpeningDrawer == null) {
if (slideOffset < 0.5f && isOpeningDrawer == null) {
window.statusBarColor = getThemeColor(R.attr.colorPrimaryDark)
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
isOpeningDrawer = true
} else if (slideOffset > 0.9f && isOpeningDrawer == null) {
} else if (slideOffset > 0.5f && isOpeningDrawer == null) {
window.statusBarColor = getThemeColor(R.attr.headerBackgroundColor)
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
isOpeningDrawer = false
@ -229,23 +230,34 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
}
override fun onDrawerOpened(drawerView: View) {
val modernHeaderStyle = sharedPreferences.getBoolean("modern_header_style", true)
if (modernHeaderStyle && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
window.statusBarColor = getThemeColor(R.attr.colorPrimaryDark)
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
}
isOpeningDrawer = null
}
override fun onDrawerClosed(drawerView: View) {
val modernHeaderStyle = sharedPreferences.getBoolean("modern_header_style", true)
if (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
}
isOpeningDrawer = null
}
override fun onDrawerStateChanged(newState: Int) {
}
})
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setHomeButtonEnabled(true)
val navigationController = findNavController(R.id.nav_host_fragment)
val navHostFragment = supportFragmentManager
.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
val navigationController = navHostFragment.navController
navigationController.addOnDestinationChangedListener { _, destination, arguments ->
updateToolbarTitle(destination, arguments)
}

View file

@ -96,8 +96,9 @@ class TaskFormActivity : BaseActivity() {
private val tagsTitleView: TextView by bindView(R.id.tags_title)
private val tagsWrapper: LinearLayout by bindView(R.id.tags_wrapper)
private val challengeNameView: TextView by bindView(R.id.challenge_name_view)
override var overrideModernHeader: Boolean? = false
private val challengeNameView: TextView by bindView(R.id.challenge_name_view)
private var challenge: Challenge? = null
private var isCreating = true
@ -527,7 +528,7 @@ class TaskFormActivity : BaseActivity() {
val alert = HabiticaAlertDialog(this)
alert.setTitle(getString(R.string.delete_challenge_task_title))
alert.setMessage(getString(R.string.delete_challenge_task_description, taskCount, challenge?.name ?: ""))
alert.addButton(R.string.leave_delete_task, true, true) { _, _ ->
alert.addButton(R.string.leave_delete_task, isPrimary = true, isDestructive = true) { _, _ ->
challenge?.let {
compositeSubscription.add(challengeRepository.leaveChallenge(it, "keep-all")
.flatMap { taskRepository.deleteTask(task?.id ?: "") }
@ -537,7 +538,7 @@ class TaskFormActivity : BaseActivity() {
}, RxErrorHandler.handleEmptyError()))
}
}
alert.addButton(getString(R.string.leave_delete_x_tasks, taskCount), false, true) { _, _ ->
alert.addButton(getString(R.string.leave_delete_x_tasks, taskCount), isPrimary = false, isDestructive = true) { _, _ ->
challenge?.let {
compositeSubscription.add(challengeRepository.leaveChallenge(it, "remove-all")
.flatMap { userRepository.retrieveUser(true) }
@ -558,7 +559,7 @@ class TaskFormActivity : BaseActivity() {
}
companion object {
val SELECTED_TAGS_KEY = "selectedTags"
const val SELECTED_TAGS_KEY = "selectedTags"
const val TASK_ID_KEY = "taskId"
const val TASK_VALUE_KEY = "taskValue"
const val USER_ID_KEY = "userId"

View file

@ -3,6 +3,7 @@ package com.habitrpg.android.habitica.ui.fragments
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.*
import androidx.appcompat.widget.Toolbar
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
@ -14,6 +15,7 @@ import com.habitrpg.android.habitica.extensions.subscribeWithErrorHandler
import com.habitrpg.android.habitica.helpers.RxErrorHandler
import com.habitrpg.android.habitica.models.Achievement
import com.habitrpg.android.habitica.ui.adapter.AchievementsAdapter
import com.habitrpg.android.habitica.ui.helpers.ToolbarColorHelper
import com.habitrpg.android.habitica.ui.helpers.bindView
import com.habitrpg.android.habitica.ui.helpers.resetViews
import io.reactivex.functions.Action
@ -139,6 +141,9 @@ class AchievementsFragment: BaseMainFragment(), SwipeRefreshLayout.OnRefreshList
menuItem?.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)
menuItem?.setIcon(R.drawable.ic_round_view_module_24px)
}
activity?.findViewById<Toolbar>(R.id.toolbar)?.let {
ToolbarColorHelper.colorizeToolbar(it, activity, false)
}
super.onCreateOptionsMenu(menu, inflater)
}

View file

@ -1,6 +1,7 @@
package com.habitrpg.android.habitica.ui.fragments
import android.content.Context
import android.graphics.PorterDuff
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.LayoutInflater
@ -13,6 +14,7 @@ import com.google.android.material.tabs.TabLayout
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.data.ApiClient
import com.habitrpg.android.habitica.data.UserRepository
import com.habitrpg.android.habitica.extensions.getThemeColor
import com.habitrpg.android.habitica.helpers.RxErrorHandler
import com.habitrpg.android.habitica.helpers.SoundManager
import com.habitrpg.android.habitica.models.user.User
@ -113,4 +115,12 @@ abstract class BaseMainFragment : BaseFragment() {
val params = collapsingToolbar?.layoutParams as? AppBarLayout.LayoutParams
params?.scrollFlags = AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL or AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED
}
protected fun tintMenuIcon(item: MenuItem?) {
context?.getThemeColor(R.attr.headerTextColor)?.let {
item?.icon?.setTint(it)
item?.icon?.setTintMode(PorterDuff.Mode.MULTIPLY)
}
}
}

View file

@ -53,7 +53,7 @@ class GuildsOverviewFragment : BaseMainFragment(), androidx.swiperefreshlayout.w
binding?.publicGuildsButton?.setOnClickListener {
MainNavigationController.navigate(GuildsOverviewFragmentDirections.openPublicGuilds())
}
compositeSubscription.add(socialRepository.getUserGroups().subscribe(Consumer { this.setGuilds(it) }, RxErrorHandler.handleEmptyError()))
compositeSubscription.add(socialRepository.getUserGroups("guild").subscribe(Consumer { this.setGuilds(it) }, RxErrorHandler.handleEmptyError()))
}
override fun onDestroy() {
socialRepository.close()

View file

@ -89,7 +89,7 @@ class ChallengeListFragment : BaseFragment(), androidx.swiperefreshlayout.widget
this.recyclerView?.setBackgroundResource(R.color.white)
}
compositeSubscription.add(socialRepository.getGroup(Group.TAVERN_ID).combineLatest(socialRepository.getUserGroups()).subscribe(Consumer {
compositeSubscription.add(socialRepository.getGroup(Group.TAVERN_ID).combineLatest(socialRepository.getUserGroups("guild")).subscribe(Consumer {
this.filterGroups = mutableListOf()
filterGroups?.add(it.first)
filterGroups?.addAll(it.second)

View file

@ -116,6 +116,7 @@ class TasksFragment : BaseMainFragment(), SearchView.OnQueryTextListener {
updateFilterIcon()
val item = menu.findItem(R.id.action_search)
tintMenuIcon(item)
val sv = item.actionView as? SearchView
sv?.setOnQueryTextListener(this)
sv?.setIconifiedByDefault(false)

View file

@ -0,0 +1,119 @@
/*
Copyright 2015 Michal Pawlowski
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.
*/
package com.habitrpg.android.habitica.ui.helpers
import android.app.Activity
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.os.Build
import android.view.View
import android.view.ViewGroup
import android.view.ViewTreeObserver
import android.view.ViewTreeObserver.OnGlobalLayoutListener
import android.widget.ImageButton
import androidx.appcompat.view.menu.ActionMenuItemView
import androidx.appcompat.widget.ActionMenuView
import androidx.appcompat.widget.Toolbar
import androidx.preference.PreferenceManager
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.extensions.getThemeColor
import com.habitrpg.android.habitica.extensions.waitForLayout
import java.util.*
/**
* Helper class that iterates through Toolbar views, and sets dynamically icons and texts color
* Created by chomi3 on 2015-01-19.
*/
object ToolbarColorHelper {
/**
* Use this method to colorize toolbar icons to the desired target color
* @param toolbarView toolbar view being colored
* @param toolbarIconsColor the target color of toolbar icons
* @param activity reference to activity needed to register observers
*/
fun colorizeToolbar(toolbar: Toolbar, activity: Activity?, overrideModernHeader: Boolean? = null) {
if (activity == null) return
val modernHeaderStyle = overrideModernHeader ?: PreferenceManager.getDefaultSharedPreferences(activity).getBoolean("modern_header_style", true)
val toolbarIconsColor = if (modernHeaderStyle && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
toolbar.setBackgroundColor(activity.getThemeColor(R.attr.headerBackgroundColor))
activity.getThemeColor(R.attr.headerTextColor)
} else {
toolbar.setBackgroundColor(activity.getThemeColor(R.attr.colorPrimary))
activity.getThemeColor(R.attr.toolbarContentColor)
}
val colorFilter = PorterDuffColorFilter(toolbarIconsColor, PorterDuff.Mode.MULTIPLY)
for (i in 0 until toolbar.childCount) {
val v = toolbar.getChildAt(i)
//Step 1 : Changing the color of back button (or open drawer button).
if (v is ImageButton) {
//Action Bar back button
v.drawable.colorFilter = colorFilter
}
if (v is ActionMenuView) {
for (j in 0 until v.childCount) {
//Step 2: Changing the color of any ActionMenuViews - icons that are not back button, nor text, nor overflow menu icon.
//Colorize the ActionViews -> all icons that are NOT: back button | overflow menu
val innerView = v.getChildAt(j)
if (innerView is ActionMenuItemView) {
innerView.setTextColor(toolbarIconsColor)
for (k in innerView.compoundDrawables.indices) {
if (innerView.compoundDrawables[k] != null) {
//Important to set the color filter in seperate thread, by adding it to the message queue
//Won't work otherwise.
innerView.post { innerView.compoundDrawables[k].colorFilter = colorFilter }
}
}
}
}
}
}
//Step 3: Changing the color of title and subtitle.
toolbar.setTitleTextColor(toolbarIconsColor)
toolbar.setSubtitleTextColor(toolbarIconsColor)
//Step 4: Changing the color of the Overflow Menu icon.
setOverflowButtonColor(activity, toolbarIconsColor)
}
/**
* It's important to set overflowDescription atribute in styles, so we can grab the reference
* to the overflow icon. Check: res/values/styles.xml
* @param activity
* @param color
*/
private fun setOverflowButtonColor(activity: Activity, color: Int) {
val overflowDescription = activity.getString(R.string.abc_action_menu_overflow_description)
activity.window.decorView .waitForLayout {
val outViews = ArrayList<View>()
findViewsWithText(outViews, overflowDescription,
View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION)
if (outViews.isEmpty()) {
return@waitForLayout
}
val overflowViewParent = outViews[0].parent as ActionMenuView
overflowViewParent.overflowIcon?.setTint(color)
overflowViewParent.overflowIcon?.setTintMode(PorterDuff.Mode.SRC_ATOP)
}
}
private fun removeOnGlobalLayoutListener(v: View, listener: OnGlobalLayoutListener) {
v.viewTreeObserver.removeOnGlobalLayoutListener(listener)
}
}

View file

@ -78,5 +78,6 @@ class RewardViewHolder(itemView: View, scoreTaskFunc: ((Task, TaskDirection) ->
priceLabel.setTextColor(ContextCompat.getColor(context, R.color.gray_300))
buyButton.setBackgroundColor(ColorUtils.setAlphaComponent(ContextCompat.getColor(context, R.color.gray_600), 127))
}
streakTextView.visibility = View.GONE
}
}