mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-27 17:08:34 +03:00
Color list headers
Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
parent
a8e99862f1
commit
5ec18780ff
9 changed files with 49 additions and 26 deletions
|
@ -27,6 +27,7 @@ import android.view.View;
|
|||
|
||||
import com.nextcloud.talk.R;
|
||||
import com.nextcloud.talk.databinding.RvItemTitleHeaderBinding;
|
||||
import com.nextcloud.talk.ui.theme.ViewThemeUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -39,12 +40,14 @@ public class GenericTextHeaderItem extends AbstractHeaderItem<GenericTextHeaderI
|
|||
private static final String TAG = "GenericTextHeaderItem";
|
||||
|
||||
private final String title;
|
||||
private final ViewThemeUtils viewThemeUtils;
|
||||
|
||||
public GenericTextHeaderItem(String title) {
|
||||
public GenericTextHeaderItem(String title, ViewThemeUtils viewThemeUtils) {
|
||||
super();
|
||||
setHidden(false);
|
||||
setSelectable(false);
|
||||
this.title = title;
|
||||
this.viewThemeUtils = viewThemeUtils;
|
||||
}
|
||||
|
||||
public String getModel() {
|
||||
|
@ -71,6 +74,7 @@ public class GenericTextHeaderItem extends AbstractHeaderItem<GenericTextHeaderI
|
|||
Log.d(TAG, "We have payloads, so ignoring!");
|
||||
} else {
|
||||
holder.binding.titleTextView.setText(title);
|
||||
viewThemeUtils.colorTextView(holder.binding.titleTextView);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ import com.nextcloud.talk.R
|
|||
import com.nextcloud.talk.data.user.model.User
|
||||
import com.nextcloud.talk.databinding.RvItemSearchMessageBinding
|
||||
import com.nextcloud.talk.models.domain.SearchMessageEntry
|
||||
import com.nextcloud.talk.ui.theme.ViewThemeUtils
|
||||
import com.nextcloud.talk.utils.DisplayUtils
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
||||
|
@ -42,7 +43,8 @@ data class MessageResultItem constructor(
|
|||
private val context: Context,
|
||||
private val currentUser: User,
|
||||
val messageEntry: SearchMessageEntry,
|
||||
private val showHeader: Boolean = false
|
||||
private val showHeader: Boolean = false,
|
||||
private val viewThemeUtils: ViewThemeUtils
|
||||
) :
|
||||
AbstractFlexibleItem<MessageResultItem.ViewHolder>(),
|
||||
IFilterable<String>,
|
||||
|
@ -104,7 +106,7 @@ data class MessageResultItem constructor(
|
|||
const val VIEW_TYPE: Int = R.layout.rv_item_search_message
|
||||
}
|
||||
|
||||
override fun getHeader(): GenericTextHeaderItem = MessagesTextHeaderItem(context)
|
||||
override fun getHeader(): GenericTextHeaderItem = MessagesTextHeaderItem(context, viewThemeUtils)
|
||||
.apply {
|
||||
isHidden = showHeader // FlexibleAdapter needs this hack for some reason
|
||||
}
|
||||
|
|
|
@ -23,8 +23,10 @@ package com.nextcloud.talk.adapters.items
|
|||
|
||||
import android.content.Context
|
||||
import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.ui.theme.ViewThemeUtils
|
||||
|
||||
class MessagesTextHeaderItem(context: Context) : GenericTextHeaderItem(context.getString(R.string.messages)) {
|
||||
class MessagesTextHeaderItem(context: Context, viewThemeUtils: ViewThemeUtils) :
|
||||
GenericTextHeaderItem(context.getString(R.string.messages), viewThemeUtils) {
|
||||
companion object {
|
||||
/**
|
||||
* "Random" value, just has to be different than other view types
|
||||
|
|
|
@ -65,6 +65,7 @@ import com.nextcloud.talk.models.json.converters.EnumActorTypeConverter
|
|||
import com.nextcloud.talk.models.json.participants.Participant
|
||||
import com.nextcloud.talk.ui.dialog.ContactsBottomDialog
|
||||
import com.nextcloud.talk.users.UserManager
|
||||
import com.nextcloud.talk.ui.theme.ViewThemeUtils
|
||||
import com.nextcloud.talk.utils.ApiUtils
|
||||
import com.nextcloud.talk.utils.ConductorRemapping
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys
|
||||
|
@ -103,6 +104,9 @@ class ContactsController(args: Bundle) :
|
|||
@Inject
|
||||
lateinit var ncApi: NcApi
|
||||
|
||||
@Inject
|
||||
lateinit var viewThemeUtils: ViewThemeUtils
|
||||
|
||||
private var credentials: String? = null
|
||||
private var currentUser: User? = null
|
||||
private var contactsQueryDisposable: Disposable? = null
|
||||
|
@ -492,7 +496,7 @@ class ContactsController(args: Bundle) :
|
|||
val headerTitle = getHeaderTitle(participant)
|
||||
var genericTextHeaderItem: GenericTextHeaderItem
|
||||
if (!userHeaderItems.containsKey(headerTitle)) {
|
||||
genericTextHeaderItem = GenericTextHeaderItem(headerTitle)
|
||||
genericTextHeaderItem = GenericTextHeaderItem(headerTitle, viewThemeUtils)
|
||||
userHeaderItems.put(headerTitle, genericTextHeaderItem)
|
||||
}
|
||||
val newContactItem = ContactItem(
|
||||
|
|
|
@ -92,8 +92,6 @@ import com.nextcloud.talk.models.json.statuses.StatusesOverall;
|
|||
import com.nextcloud.talk.repositories.unifiedsearch.UnifiedSearchRepository;
|
||||
import com.nextcloud.talk.ui.dialog.ChooseAccountDialogFragment;
|
||||
import com.nextcloud.talk.ui.dialog.ConversationsListBottomDialog;
|
||||
import com.nextcloud.talk.ui.theme.ServerTheme;
|
||||
import com.nextcloud.talk.ui.theme.ServerThemeProvider;
|
||||
import com.nextcloud.talk.ui.theme.ViewThemeUtils;
|
||||
import com.nextcloud.talk.users.UserManager;
|
||||
import com.nextcloud.talk.utils.ApiUtils;
|
||||
|
@ -185,7 +183,7 @@ public class ConversationsListController extends BaseController implements Flexi
|
|||
UnifiedSearchRepository unifiedSearchRepository;
|
||||
|
||||
@Inject
|
||||
ServerTheme serverTheme;
|
||||
ViewThemeUtils viewThemeUtils;
|
||||
|
||||
@BindView(R.id.recycler_view)
|
||||
RecyclerView recyclerView;
|
||||
|
@ -624,7 +622,7 @@ public class ConversationsListController extends BaseController implements Flexi
|
|||
|
||||
GenericTextHeaderItem genericTextHeaderItem;
|
||||
if (!callHeaderItems.containsKey(headerTitle)) {
|
||||
genericTextHeaderItem = new GenericTextHeaderItem(headerTitle);
|
||||
genericTextHeaderItem = new GenericTextHeaderItem(headerTitle, viewThemeUtils);
|
||||
callHeaderItems.put(headerTitle, genericTextHeaderItem);
|
||||
}
|
||||
|
||||
|
@ -705,7 +703,7 @@ public class ConversationsListController extends BaseController implements Flexi
|
|||
|
||||
GenericTextHeaderItem genericTextHeaderItem;
|
||||
if (!callHeaderItems.containsKey(headerTitle)) {
|
||||
genericTextHeaderItem = new GenericTextHeaderItem(headerTitle);
|
||||
genericTextHeaderItem = new GenericTextHeaderItem(headerTitle, viewThemeUtils);
|
||||
callHeaderItems.put(headerTitle, genericTextHeaderItem);
|
||||
}
|
||||
|
||||
|
@ -790,7 +788,8 @@ public class ConversationsListController extends BaseController implements Flexi
|
|||
ContactAddressBookWorker.Companion.run(context);
|
||||
showNewConversationsScreen();
|
||||
});
|
||||
new ViewThemeUtils(serverTheme).themeFAB(floatingActionButton);
|
||||
|
||||
viewThemeUtils.themeFAB(floatingActionButton);
|
||||
|
||||
if (getActivity() != null && getActivity() instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) getActivity();
|
||||
|
@ -1416,7 +1415,7 @@ public class ConversationsListController extends BaseController implements Flexi
|
|||
List<AbstractFlexibleItem> adapterItems = new ArrayList<>(entries.size() + 1);
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
final boolean showHeader = i == 0;
|
||||
adapterItems.add(new MessageResultItem(context, currentUser, entries.get(i), showHeader));
|
||||
adapterItems.add(new MessageResultItem(context, currentUser, entries.get(i), showHeader, viewThemeUtils));
|
||||
}
|
||||
if (results.getHasMore()) {
|
||||
adapterItems.add(LoadMoreResultsItem.INSTANCE);
|
||||
|
|
|
@ -41,6 +41,7 @@ import com.nextcloud.talk.application.NextcloudTalkApplication
|
|||
import com.nextcloud.talk.controllers.ConversationsListController
|
||||
import com.nextcloud.talk.data.user.model.User
|
||||
import com.nextcloud.talk.databinding.ActivityMessageSearchBinding
|
||||
import com.nextcloud.talk.ui.theme.ViewThemeUtils
|
||||
import com.nextcloud.talk.utils.DisplayUtils
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys
|
||||
import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew
|
||||
|
@ -64,6 +65,9 @@ class MessageSearchActivity : BaseActivity() {
|
|||
@Inject
|
||||
lateinit var userProvider: CurrentUserProviderNew
|
||||
|
||||
@Inject
|
||||
lateinit var viewThemeUtils: ViewThemeUtils
|
||||
|
||||
private lateinit var binding: ActivityMessageSearchBinding
|
||||
private lateinit var searchView: SearchView
|
||||
|
||||
|
@ -105,7 +109,9 @@ class MessageSearchActivity : BaseActivity() {
|
|||
DisplayUtils.applyColorToStatusBar(
|
||||
this,
|
||||
ResourcesCompat.getColor(
|
||||
resources, R.color.appbar, null
|
||||
resources,
|
||||
R.color.appbar,
|
||||
null
|
||||
)
|
||||
)
|
||||
DisplayUtils.applyColorToNavigationBar(
|
||||
|
@ -154,7 +160,7 @@ class MessageSearchActivity : BaseActivity() {
|
|||
emptyList()
|
||||
}
|
||||
val newItems =
|
||||
state.results.map { MessageResultItem(this, user, it) } + loadMoreItems
|
||||
state.results.map { MessageResultItem(this, user, it, false, viewThemeUtils) } + loadMoreItems
|
||||
|
||||
if (adapter != null) {
|
||||
adapter!!.updateDataSet(newItems)
|
||||
|
|
|
@ -26,9 +26,10 @@ import android.content.Context
|
|||
import com.nextcloud.talk.data.user.model.User
|
||||
import com.nextcloud.talk.models.json.capabilities.Capabilities
|
||||
import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew
|
||||
import javax.inject.Inject
|
||||
|
||||
// TODO cache theme, keyed by server url
|
||||
internal class ServerThemeProviderImpl(
|
||||
internal class ServerThemeProviderImpl @Inject constructor(
|
||||
private val context: Context,
|
||||
private val userProvider: CurrentUserProviderNew
|
||||
) :
|
||||
|
|
|
@ -21,25 +21,24 @@
|
|||
|
||||
package com.nextcloud.talk.ui.theme
|
||||
|
||||
import android.content.Context
|
||||
import com.nextcloud.talk.dagger.modules.ContextModule
|
||||
import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew
|
||||
import com.nextcloud.talk.utils.database.user.UserModule
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.Reusable
|
||||
|
||||
@Module(includes = [ContextModule::class, UserModule::class])
|
||||
class ThemeModule {
|
||||
internal abstract class ThemeModule {
|
||||
|
||||
@Provides
|
||||
@Binds
|
||||
@Reusable
|
||||
fun provideServerThemeProvider(context: Context, userProvider: CurrentUserProviderNew): ServerThemeProvider {
|
||||
return ServerThemeProviderImpl(context, userProvider)
|
||||
}
|
||||
abstract fun bindServerThemeProvider(provider: ServerThemeProviderImpl): ServerThemeProvider
|
||||
|
||||
companion object {
|
||||
@Provides
|
||||
fun provideCurrentServerTheme(themeProvider: ServerThemeProvider): ServerTheme {
|
||||
return themeProvider.getServerThemeForCurrentUser()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,9 +24,11 @@ package com.nextcloud.talk.ui.theme
|
|||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.content.res.Configuration
|
||||
import android.widget.TextView
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import javax.inject.Inject
|
||||
|
||||
class ViewThemeUtils(val theme: ServerTheme) {
|
||||
class ViewThemeUtils @Inject constructor(val theme: ServerTheme) {
|
||||
|
||||
private fun isDarkMode(context: Context): Boolean = when (
|
||||
context.resources.configuration.uiMode and
|
||||
|
@ -45,4 +47,8 @@ class ViewThemeUtils(val theme: ServerTheme) {
|
|||
fab.backgroundTintList = ColorStateList.valueOf(getElementColor(fab.context))
|
||||
fab.imageTintList = ColorStateList.valueOf(theme.colorText)
|
||||
}
|
||||
|
||||
fun colorTextView(titleTextView: TextView) {
|
||||
titleTextView.setTextColor(getElementColor(titleTextView.context))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue