mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-23 05:29:54 +01:00
Squashed commit of the following + refactoring/improvements
commit 96caa85f50c192174b63079d5dec86c0463d61a0 Author: Thomas Ebert <thomas.ebert@te-online.net> Date: Wed Dec 18 22:37:13 2019 +0100 Clean up / WIP – Add intent for opening specific conversation. commit 8cc03814fdc19e6230c15fb528f3f7e86394685e Author: Nextcloud bot <bot@nextcloud.com> Date: Mon Dec 16 03:59:18 2019 +0000 [tx-robot] updated from transifex commit 8db14fae8850da65a7c80e3b469ae0dec01bd567 Author: Nextcloud bot <bot@nextcloud.com> Date: Sun Dec 15 03:59:16 2019 +0000 [tx-robot] updated from transifex commit 34909d469f1cd6161aff6af1c7a0fc81414ee263 Author: Nextcloud bot <bot@nextcloud.com> Date: Thu Dec 12 03:59:17 2019 +0000 [tx-robot] updated from transifex commit 6ea1f13b520b230df76b53520c36d1041f1fa62d Author: Nextcloud bot <bot@nextcloud.com> Date: Wed Dec 11 03:17:05 2019 +0000 [tx-robot] updated from transifex commit addd5721784f73ebc18434646bbb348426bc8268 Author: Nextcloud bot <bot@nextcloud.com> Date: Tue Dec 10 03:21:10 2019 +0000 [tx-robot] updated from transifex commit 9abf63c0ca61808f13f05e9c11650c03d2315321 Author: Nextcloud bot <bot@nextcloud.com> Date: Sun Dec 8 03:18:59 2019 +0000 [tx-robot] updated from transifex commit a80da49ea994feabe524eb66d506814963820976 Author: Nextcloud bot <bot@nextcloud.com> Date: Sat Dec 7 03:19:17 2019 +0000 [tx-robot] updated from transifex commit cd4d5ae79e28071bcf066ccbf4ae64e575dc322c Author: Nextcloud bot <bot@nextcloud.com> Date: Fri Dec 6 03:19:17 2019 +0000 [tx-robot] updated from transifex commit 610d05b42dd998df5aafc1330b04adcfd3788792 Author: Nextcloud bot <bot@nextcloud.com> Date: Sat Nov 30 03:15:59 2019 +0000 [tx-robot] updated from transifex commit 46ac1d7b90aea9220bc8226ff90603b29e41f9b4 Author: Nextcloud bot <bot@nextcloud.com> Date: Fri Nov 29 03:15:32 2019 +0000 [tx-robot] updated from transifex commit 4b45db6a38416b0d1df53cdb254cb38932a678cb Author: Nextcloud bot <bot@nextcloud.com> Date: Thu Nov 28 03:18:15 2019 +0000 [tx-robot] updated from transifex commit 7533237f78eba0d912e5eff4b82f571da8b173ae Author: Nextcloud bot <bot@nextcloud.com> Date: Wed Nov 27 03:13:45 2019 +0000 [tx-robot] updated from transifex commit 267e635a8a5d03f9268a3fb554ae3c752508beb5 Author: Nextcloud bot <bot@nextcloud.com> Date: Tue Nov 26 03:13:41 2019 +0000 [tx-robot] updated from transifex commit 6da60f88bec5c20cf2011fed4515f3502a90dd62 Author: Nextcloud bot <bot@nextcloud.com> Date: Sun Nov 24 03:14:17 2019 +0000 [tx-robot] updated from transifex commit 640abdb3d0a0fb5ed3d87ea42a48254043d0c026 Author: Nextcloud bot <bot@nextcloud.com> Date: Fri Nov 22 03:14:00 2019 +0000 [tx-robot] updated from transifex commit 786a2170a006ef0c5cd0a1feff06c5b93b4f23c8 Author: Nextcloud bot <bot@nextcloud.com> Date: Thu Nov 21 03:13:31 2019 +0000 [tx-robot] updated from transifex commit 6853e51a08f220e8abfb63421edce2df343dcf7a Author: Nextcloud bot <bot@nextcloud.com> Date: Wed Nov 20 03:14:24 2019 +0000 [tx-robot] updated from transifex commit 9591fddd8c63e278a9d07127ab6ebbc46860a8e6 Author: Nextcloud bot <bot@nextcloud.com> Date: Tue Nov 19 03:14:15 2019 +0000 [tx-robot] updated from transifex commit 122b8fcf371f760871e3236b3b4cc43f18b74987 Author: Nextcloud bot <bot@nextcloud.com> Date: Fri Nov 15 03:14:34 2019 +0000 [tx-robot] updated from transifex commit 7afb0100d4391ada33b1a21d4e6f47f7d98fb446 Author: Nextcloud bot <bot@nextcloud.com> Date: Thu Nov 14 03:14:44 2019 +0000 [tx-robot] updated from transifex commit fbfc608710a8e4476b6543c73fbb910af1b9221f Author: nextcloud-android-bot <> Date: Wed Nov 13 08:42:57 2019 +0000 Drone: update Lint results to reflect reduced error/warning count [skip ci] commit f5662534b9eb7cf412c58d950fe166b106fdcb40 Author: tobiasKaminsky <tobias@kaminsky.me> Date: Tue Nov 12 14:04:04 2019 +0100 fix CI Signed-off-by: tobiasKaminsky <tobias@kaminsky.me> commit dffc6b15db1c245dfec0cda0954f2da5b1fb6b8a Author: Nextcloud bot <bot@nextcloud.com> Date: Tue Nov 12 03:16:19 2019 +0000 [tx-robot] updated from transifex commit 4786dccb17999e9bbdc1bba7daefb8b318011d39 Author: Thomas Ebert <thomas.ebert@te-online.net> Date: Mon Nov 11 23:39:41 2019 +0100 Shortcuts – Move initialization to ConversationListView, because it can successfully register the observer for conversations. commit 00ee1576699bada112e5cecfc5f160f73c644961 Author: Nextcloud bot <bot@nextcloud.com> Date: Sun Nov 10 03:18:55 2019 +0000 [tx-robot] updated from transifex commit 86ea8e74f7a0337e345f1053a2c65589a3bdc922 Author: Thomas Ebert <thomas.ebert@te-online.net> Date: Sat Nov 9 01:05:45 2019 +0100 WIP – Add more shortcut entries. Try to subscribe to conversation list. commit 2b8fbd11a01cff44b4cbc579ba0aecb9d756545f Author: Nextcloud bot <bot@nextcloud.com> Date: Thu Nov 7 03:12:48 2019 +0000 [tx-robot] updated from transifex commit e1a67b8c57dbc5e67035d2002ad2a7032e34d0b6 Author: Nextcloud bot <bot@nextcloud.com> Date: Wed Nov 6 03:14:48 2019 +0000 [tx-robot] updated from transifex commit f02e075cd57e2f358f61215b4143939e1cf619d6 Author: Nextcloud bot <bot@nextcloud.com> Date: Tue Nov 5 03:11:56 2019 +0000 [tx-robot] updated from transifex commit 95b1fefd77e40a2b57bb91d5165e549212dea36f Author: Nextcloud bot <bot@nextcloud.com> Date: Sun Nov 3 03:16:29 2019 +0000 [tx-robot] updated from transifex commit 515027bd4f9cad4442cb11f2a946cc7a4ed18aea Author: Nextcloud bot <bot@nextcloud.com> Date: Sat Nov 2 03:10:57 2019 +0000 [tx-robot] updated from transifex commit 08eb5137eb1280483c2a94ab9da414f5b526031a Author: Nextcloud bot <bot@nextcloud.com> Date: Fri Nov 1 03:03:45 2019 +0000 [tx-robot] updated from transifex commit 8ca70776ad971dcccf7d75029128fafdd2dfe8a4 Author: Joas Schilling <213943+nickvergessen@users.noreply.github.com> Date: Thu Oct 31 09:20:37 2019 +0100 Use server default value for autocomplete limit There is no real need to use a custom limit, when the server has a sane default as well as a setting to overwrite this. Signed-off-by: Joas Schilling <coding@schilljs.com> commit dfa1d9cacb7b09969b099a034cac512452de0209 Author: Nextcloud bot <bot@nextcloud.com> Date: Thu Oct 31 03:05:00 2019 +0000 [tx-robot] updated from transifex commit 258aa38fe70758e3a299cd5632d0271af5bfdbf2 Author: Thomas Ebert <thomas.ebert@te-online.net> Date: Thu Oct 31 00:54:36 2019 +0100 WIP – Add app shortcuts: Add `New conversation` shortcut.
This commit is contained in:
parent
25841af57c
commit
70de6a7f5a
@ -37,6 +37,7 @@ import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler
|
|||||||
import com.google.android.material.appbar.MaterialToolbar
|
import com.google.android.material.appbar.MaterialToolbar
|
||||||
import com.nextcloud.talk.R
|
import com.nextcloud.talk.R
|
||||||
import com.nextcloud.talk.controllers.CallNotificationController
|
import com.nextcloud.talk.controllers.CallNotificationController
|
||||||
|
import com.nextcloud.talk.controllers.ContactsController
|
||||||
import com.nextcloud.talk.controllers.LockedController
|
import com.nextcloud.talk.controllers.LockedController
|
||||||
import com.nextcloud.talk.controllers.ServerSelectionController
|
import com.nextcloud.talk.controllers.ServerSelectionController
|
||||||
import com.nextcloud.talk.controllers.base.providers.ActionBarProvider
|
import com.nextcloud.talk.controllers.base.providers.ActionBarProvider
|
||||||
@ -152,7 +153,13 @@ class MainActivity : BaseActivity(), ActionBarProvider {
|
|||||||
override fun onNewIntent(intent: Intent) {
|
override fun onNewIntent(intent: Intent) {
|
||||||
super.onNewIntent(intent)
|
super.onNewIntent(intent)
|
||||||
|
|
||||||
if (intent.hasExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)) {
|
if (intent.action == BundleKeys.KEY_NEW_CONVERSATION) {
|
||||||
|
openNewConversationScreen()
|
||||||
|
} else if (intent.action == BundleKeys.KEY_OPEN_CONVERSATION) {
|
||||||
|
ConductorRemapping.remapChatController(
|
||||||
|
router!!, intent.getLongExtra(BundleKeys.KEY_INTERNAL_USER_ID, -1),
|
||||||
|
intent.getStringExtra(BundleKeys.KEY_ROOM_TOKEN)!!, intent.extras!!, false)
|
||||||
|
} else if (intent.hasExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)) {
|
||||||
if (intent.getBooleanExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL, false)) {
|
if (intent.getBooleanExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL, false)) {
|
||||||
router!!.pushController(
|
router!!.pushController(
|
||||||
RouterTransaction.with(CallNotificationController(intent.extras!!))
|
RouterTransaction.with(CallNotificationController(intent.extras!!))
|
||||||
@ -162,7 +169,7 @@ class MainActivity : BaseActivity(), ActionBarProvider {
|
|||||||
} else {
|
} else {
|
||||||
ConductorRemapping.remapChatController(
|
ConductorRemapping.remapChatController(
|
||||||
router!!, intent.getLongExtra(BundleKeys.KEY_INTERNAL_USER_ID, -1),
|
router!!, intent.getLongExtra(BundleKeys.KEY_INTERNAL_USER_ID, -1),
|
||||||
intent.getStringExtra(BundleKeys.KEY_ROOM_TOKEN), intent.extras!!, false
|
intent.getStringExtra(BundleKeys.KEY_ROOM_TOKEN)!!, intent.extras!!, false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,6 +185,17 @@ class MainActivity : BaseActivity(), ActionBarProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun openNewConversationScreen() {
|
||||||
|
val bundle = Bundle()
|
||||||
|
bundle.putBoolean(BundleKeys.KEY_NEW_CONVERSATION, true)
|
||||||
|
|
||||||
|
router?.pushController(
|
||||||
|
RouterTransaction.with(ContactsController(bundle))
|
||||||
|
.pushChangeHandler(HorizontalChangeHandler())
|
||||||
|
.popChangeHandler(HorizontalChangeHandler())
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val TAG = "MainActivity"
|
private val TAG = "MainActivity"
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ class NextcloudTalkApplication : Application(), LifecycleObserver {
|
|||||||
startKoin {
|
startKoin {
|
||||||
androidContext(this@NextcloudTalkApplication)
|
androidContext(this@NextcloudTalkApplication)
|
||||||
androidLogger()
|
androidLogger()
|
||||||
modules(listOf(CommunicationModule, StorageModule, NetworkModule, ConversationsModule, ConversationsListModule, ManagementModule))
|
modules(listOf(CommunicationModule, StorageModule, NetworkModule, ConversationsModule, ConversationsListModule, ServiceModule))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,6 +65,14 @@ class ConversationsRepositoryImpl(val conversationsDao: ConversationsDao) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getLastThreeActiveConversationsForUser(userId: Long): LiveData<List<Conversation>> {
|
||||||
|
return conversationsDao.getLastThreeConversationsForUser(userId).distinctUntilChanged().map { data ->
|
||||||
|
data.map {
|
||||||
|
it.toConversation()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun getConversationForUserWithToken(userId: Long, token: String): Conversation? {
|
override suspend fun getConversationForUserWithToken(userId: Long, token: String): Conversation? {
|
||||||
val conversationEntity = conversationsDao.getConversationForUserWithToken(userId, token)
|
val conversationEntity = conversationsDao.getConversationForUserWithToken(userId, token)
|
||||||
if (conversationEntity != null) {
|
if (conversationEntity != null) {
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
* Nextcloud Talk application
|
|
||||||
*
|
|
||||||
* @author Mario Danic
|
|
||||||
* Copyright (C) 2017-2019 Mario Danic <mario@lovelyhq.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.nextcloud.talk.newarch.di.module
|
|
||||||
|
|
||||||
import com.nextcloud.talk.newarch.domain.repository.offline.ConversationsRepository
|
|
||||||
import com.nextcloud.talk.newarch.domain.repository.offline.UsersRepository
|
|
||||||
import com.nextcloud.talk.newarch.domain.usecases.GetConversationUseCase
|
|
||||||
import com.nextcloud.talk.newarch.domain.usecases.JoinConversationUseCase
|
|
||||||
import com.nextcloud.talk.newarch.utils.ConversationService
|
|
||||||
import okhttp3.OkHttpClient
|
|
||||||
import org.koin.dsl.module
|
|
||||||
import java.net.CookieManager
|
|
||||||
|
|
||||||
val ManagementModule = module {
|
|
||||||
single { createConversationsManager(get(), get(), get(), get(), get(), get()) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun createConversationsManager(usersRepository: UsersRepository, cookieManager: CookieManager, okHttpClient: OkHttpClient, conversationsRepository: ConversationsRepository, getConversationUseCase: GetConversationUseCase, joinConversationUseCase: JoinConversationUseCase): ConversationService {
|
|
||||||
return ConversationService(usersRepository, cookieManager, okHttpClient, conversationsRepository, joinConversationUseCase, getConversationUseCase)
|
|
||||||
}
|
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.nextcloud.talk.newarch.di.module
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.pm.ShortcutManager
|
||||||
|
import com.nextcloud.talk.newarch.domain.repository.offline.ConversationsRepository
|
||||||
|
import com.nextcloud.talk.newarch.domain.repository.offline.UsersRepository
|
||||||
|
import com.nextcloud.talk.newarch.domain.usecases.GetConversationUseCase
|
||||||
|
import com.nextcloud.talk.newarch.domain.usecases.JoinConversationUseCase
|
||||||
|
import com.nextcloud.talk.newarch.utils.ConversationService
|
||||||
|
import com.nextcloud.talk.newarch.utils.ShortcutService
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import org.koin.dsl.module
|
||||||
|
import java.net.CookieManager
|
||||||
|
|
||||||
|
val ServiceModule = module {
|
||||||
|
single { createConversationsService(get(), get(), get(), get(), get(), get()) }
|
||||||
|
single { createShortcutService(get(), get(), get()) }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createConversationsService(usersRepository: UsersRepository, cookieManager: CookieManager,
|
||||||
|
okHttpClient: OkHttpClient, conversationsRepository: ConversationsRepository,
|
||||||
|
getConversationUseCase: GetConversationUseCase, joinConversationUseCase: JoinConversationUseCase): ConversationService {
|
||||||
|
return ConversationService(usersRepository, cookieManager, okHttpClient, conversationsRepository, joinConversationUseCase, getConversationUseCase)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createShortcutService(context: Context, conversationsRepository: ConversationsRepository, conversationsService: ConversationService): ShortcutService {
|
||||||
|
return ShortcutService(context, conversationsRepository, conversationsService)
|
||||||
|
}
|
@ -25,6 +25,8 @@ import com.nextcloud.talk.models.json.conversations.Conversation
|
|||||||
|
|
||||||
interface ConversationsRepository {
|
interface ConversationsRepository {
|
||||||
fun getConversationsForUser(userId: Long): LiveData<List<Conversation>>
|
fun getConversationsForUser(userId: Long): LiveData<List<Conversation>>
|
||||||
|
fun getLastThreeActiveConversationsForUser(userId: Long): LiveData<List<Conversation>>
|
||||||
|
|
||||||
suspend fun getConversationForUserWithToken(userId: Long, token: String): Conversation?
|
suspend fun getConversationForUserWithToken(userId: Long, token: String): Conversation?
|
||||||
suspend fun clearConversationsForUser(userId: Long)
|
suspend fun clearConversationsForUser(userId: Long)
|
||||||
suspend fun saveConversationsForUser(
|
suspend fun saveConversationsForUser(
|
||||||
|
@ -22,6 +22,7 @@ package com.nextcloud.talk.newarch.features.conversationsList
|
|||||||
|
|
||||||
import android.app.SearchManager
|
import android.app.SearchManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.pm.ShortcutManager
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@ -58,6 +59,7 @@ import com.nextcloud.talk.newarch.utils.Images
|
|||||||
import com.nextcloud.talk.utils.ApiUtils
|
import com.nextcloud.talk.utils.ApiUtils
|
||||||
import com.nextcloud.talk.utils.ConductorRemapping
|
import com.nextcloud.talk.utils.ConductorRemapping
|
||||||
import com.nextcloud.talk.utils.DisplayUtils
|
import com.nextcloud.talk.utils.DisplayUtils
|
||||||
|
import com.nextcloud.talk.newarch.utils.ShortcutService
|
||||||
import com.nextcloud.talk.utils.animations.SharedElementTransition
|
import com.nextcloud.talk.utils.animations.SharedElementTransition
|
||||||
import com.nextcloud.talk.utils.bundle.BundleKeys
|
import com.nextcloud.talk.utils.bundle.BundleKeys
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
@ -233,6 +235,7 @@ class ConversationsListView : BaseView(), OnQueryTextListener,
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
recyclerViewAdapter.updateDataSet(
|
recyclerViewAdapter.updateDataSet(
|
||||||
newConversations as
|
newConversations as
|
||||||
List<IFlexible<ViewHolder>>?, false
|
List<IFlexible<ViewHolder>>?, false
|
||||||
@ -244,6 +247,18 @@ class ConversationsListView : BaseView(), OnQueryTextListener,
|
|||||||
recyclerViewAdapter.filterItems(500)
|
recyclerViewAdapter.filterItems(500)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
=======
|
||||||
|
val shortcutService = ShortcutService(
|
||||||
|
context.getSystemService<ShortcutManager>(ShortcutManager::class.java),
|
||||||
|
context,
|
||||||
|
this
|
||||||
|
//this.offlineRepository
|
||||||
|
);
|
||||||
|
shortcutService.registerShortcuts()
|
||||||
|
|
||||||
|
return super.onCreateView(inflater, container)
|
||||||
|
}
|
||||||
|
>>>>>>> feature/app-shortcuts
|
||||||
|
|
||||||
viewState.observe(this@ConversationsListView, Observer { value ->
|
viewState.observe(this@ConversationsListView, Observer { value ->
|
||||||
when (value) {
|
when (value) {
|
||||||
|
@ -30,6 +30,9 @@ abstract class ConversationsDao {
|
|||||||
@Query("SELECT * FROM conversations WHERE user_id = :userId ORDER BY favorite DESC, last_activity DESC")
|
@Query("SELECT * FROM conversations WHERE user_id = :userId ORDER BY favorite DESC, last_activity DESC")
|
||||||
abstract fun getConversationsForUser(userId: Long): LiveData<List<ConversationEntity>>
|
abstract fun getConversationsForUser(userId: Long): LiveData<List<ConversationEntity>>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM conversations WHERE user_id = :userId ORDER BY last_activity DESC LIMIT 3")
|
||||||
|
abstract fun getLastThreeConversationsForUser(userId: Long): LiveData<List<ConversationEntity>>
|
||||||
|
|
||||||
@Query("DELETE FROM conversations WHERE user_id = :userId")
|
@Query("DELETE FROM conversations WHERE user_id = :userId")
|
||||||
abstract suspend fun clearConversationsForUser(userId: Long)
|
abstract suspend fun clearConversationsForUser(userId: Long)
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ class ConversationService constructor(usersRepository: UsersRepository,
|
|||||||
private val getConversationUseCase: GetConversationUseCase) : KoinComponent {
|
private val getConversationUseCase: GetConversationUseCase) : KoinComponent {
|
||||||
private val applicationScope = CoroutineScope(Dispatchers.Default)
|
private val applicationScope = CoroutineScope(Dispatchers.Default)
|
||||||
private val previousUser: UserNgEntity? = null
|
private val previousUser: UserNgEntity? = null
|
||||||
private val currentUserLiveData: LiveData<UserNgEntity> = usersRepository.getActiveUserLiveData()
|
val currentUserLiveData: LiveData<UserNgEntity> = usersRepository.getActiveUserLiveData()
|
||||||
private var currentConversation: Conversation? = null
|
private var currentConversation: Conversation? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
@ -0,0 +1,107 @@
|
|||||||
|
/*
|
||||||
|
* Nextcloud Talk application
|
||||||
|
*
|
||||||
|
* @author Thomas Ebert<thomas@thomasebert.net>
|
||||||
|
* @author Mario Danic
|
||||||
|
* Copyright (C) 2017-2019 Mario Danic <mario@lovelyhq.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.nextcloud.talk.newarch.utils
|
||||||
|
|
||||||
|
import android.annotation.TargetApi
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.pm.ShortcutInfo
|
||||||
|
import android.content.pm.ShortcutManager
|
||||||
|
import android.graphics.drawable.Icon
|
||||||
|
import android.os.Build
|
||||||
|
import androidx.annotation.RequiresApi
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import com.nextcloud.talk.R
|
||||||
|
import com.nextcloud.talk.activities.MainActivity
|
||||||
|
import com.nextcloud.talk.models.json.conversations.Conversation
|
||||||
|
import com.nextcloud.talk.newarch.domain.repository.offline.ConversationsRepository
|
||||||
|
import com.nextcloud.talk.newarch.local.models.UserNgEntity
|
||||||
|
import com.nextcloud.talk.utils.bundle.BundleKeys
|
||||||
|
|
||||||
|
class ShortcutService constructor(private val context: Context,
|
||||||
|
private val conversationsRepository: ConversationsRepository,
|
||||||
|
conversationsService: ConversationService
|
||||||
|
) {
|
||||||
|
private var lastThreeActiveConversations: LiveData<List<Conversation>> = MutableLiveData()
|
||||||
|
private var currentUser: UserNgEntity? = null
|
||||||
|
@RequiresApi(Build.VERSION_CODES.N_MR1)
|
||||||
|
private val shortcutManager = context.getSystemService(ShortcutManager::class.java)
|
||||||
|
|
||||||
|
init {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
|
conversationsService.currentUserLiveData.observeForever {
|
||||||
|
currentUser = it
|
||||||
|
it?.let {
|
||||||
|
lastThreeActiveConversations = conversationsRepository.getLastThreeActiveConversationsForUser(it.id!!)
|
||||||
|
} ?: run {
|
||||||
|
shortcutManager?.dynamicShortcuts = listOf()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lastThreeActiveConversations.observeForever {
|
||||||
|
registerShortcuts()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@TargetApi(Build.VERSION_CODES.P)
|
||||||
|
fun registerShortcuts() {
|
||||||
|
val openNewConversationIntent = Intent(context, MainActivity::class.java)
|
||||||
|
openNewConversationIntent.action = BundleKeys.KEY_NEW_CONVERSATION
|
||||||
|
|
||||||
|
val shortcuts: MutableList<ShortcutInfo> = mutableListOf()
|
||||||
|
val images = Images()
|
||||||
|
|
||||||
|
currentUser?.let { user ->
|
||||||
|
shortcuts.add(ShortcutInfo.Builder(context, "new")
|
||||||
|
.setShortLabel(context.resources.getString(R.string.nc_new_conversation_short))
|
||||||
|
.setLongLabel(context.resources.getString(R.string.nc_new_conversation))
|
||||||
|
.setIcon(Icon.createWithResource(context, R.drawable.ic_add_grey600_24px))
|
||||||
|
.setIntent(openNewConversationIntent)
|
||||||
|
.build())
|
||||||
|
|
||||||
|
lastThreeActiveConversations.value?.let { conversations ->
|
||||||
|
for ((index, conversation) in conversations.withIndex()) {
|
||||||
|
// Only do this for the first 3 conversations
|
||||||
|
if (index <= 3) continue
|
||||||
|
|
||||||
|
val intent = Intent(context, MainActivity::class.java)
|
||||||
|
intent.action = BundleKeys.KEY_OPEN_CONVERSATION
|
||||||
|
intent.putExtra(BundleKeys.KEY_INTERNAL_USER_ID, user.id)
|
||||||
|
intent.putExtra(BundleKeys.KEY_ROOM_TOKEN, conversation.token)
|
||||||
|
|
||||||
|
val icon = images.getImageForConversation(context, conversation)
|
||||||
|
shortcuts.add(ShortcutInfo.Builder(context, "current_conversation_" + (index + 1))
|
||||||
|
.setShortLabel(conversation.displayName as String)
|
||||||
|
.setLongLabel(conversation.displayName as String)
|
||||||
|
// @TODO: Use avatar as icon
|
||||||
|
.setIcon(Icon.createWithResource(context, R.drawable.ic_add_grey600_24px))
|
||||||
|
.setIntent(intent)
|
||||||
|
.build())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
shortcutManager?.dynamicShortcuts = shortcuts
|
||||||
|
}
|
||||||
|
}
|
@ -21,6 +21,7 @@
|
|||||||
package com.nextcloud.talk.utils.bundle
|
package com.nextcloud.talk.utils.bundle
|
||||||
|
|
||||||
object BundleKeys {
|
object BundleKeys {
|
||||||
|
val KEY_OPEN_CONVERSATION: String = "KEY_OPEN_CONVERSATION"
|
||||||
val KEY_SELECTED_USERS = "KEY_SELECTED_USERS"
|
val KEY_SELECTED_USERS = "KEY_SELECTED_USERS"
|
||||||
val KEY_SELECTED_GROUPS = "KEY_SELECTED_GROUPS"
|
val KEY_SELECTED_GROUPS = "KEY_SELECTED_GROUPS"
|
||||||
val KEY_USERNAME = "KEY_USERNAME"
|
val KEY_USERNAME = "KEY_USERNAME"
|
||||||
|
@ -167,6 +167,7 @@
|
|||||||
<string name="nc_delete_conversation_more">If you delete this conversation it will also be
|
<string name="nc_delete_conversation_more">If you delete this conversation it will also be
|
||||||
deleted for all other participants.</string>
|
deleted for all other participants.</string>
|
||||||
|
|
||||||
|
<string name="nc_new_conversation_short">New</string>
|
||||||
<string name="nc_new_conversation">New conversation</string>
|
<string name="nc_new_conversation">New conversation</string>
|
||||||
<string name="nc_join_via_link">Join with a link</string>
|
<string name="nc_join_via_link">Join with a link</string>
|
||||||
<string name="nc_join_via_web">Join via web</string>
|
<string name="nc_join_via_web">Join via web</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user