Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Linus <[email protected]>
  • Loading branch information
rapterjet2004 committed Aug 18, 2023
1 parent a386a08 commit 6e3837c
Show file tree
Hide file tree
Showing 15 changed files with 529 additions and 2 deletions.
15 changes: 15 additions & 0 deletions app/src/main/java/com/nextcloud/talk/api/NcApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.nextcloud.talk.models.json.participants.ParticipantsOverall;
import com.nextcloud.talk.models.json.push.PushRegistrationOverall;
import com.nextcloud.talk.models.json.reactions.ReactionsOverall;
import com.nextcloud.talk.models.json.reminder.ReminderOverall;
import com.nextcloud.talk.models.json.search.ContactsByNumberOverall;
import com.nextcloud.talk.models.json.signaling.SignalingOverall;
import com.nextcloud.talk.models.json.signaling.settings.SignalingSettingsOverall;
Expand Down Expand Up @@ -671,4 +672,18 @@ Observable<TranslationsOverall> translateMessage(@Header("Authorization") String
@Query("text") String text,
@Query("toLanguage") String toLanguage,
@Nullable @Query("fromLanguage") String fromLanguage);

@GET
Observable<ReminderOverall> getReminder(@Header("Authorization") String authorization,
@Url String url);

@DELETE
Observable<GenericOverall> deleteReminder(@Header("Authorization") String authorization,
@Url String url);

@FormUrlEncoded
@POST
Observable<ReminderOverall> setReminder(@Header("Authorization") String authorization,
@Url String url,
@Field("timestamp") int timestamp);
}
8 changes: 8 additions & 0 deletions app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ import androidx.core.text.bold
import androidx.core.widget.doAfterTextChanged
import androidx.emoji2.text.EmojiCompat
import androidx.emoji2.widget.EmojiTextView
import androidx.fragment.app.DialogFragment
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
Expand Down Expand Up @@ -183,6 +184,7 @@ import com.nextcloud.talk.ui.MicInputCloud
import com.nextcloud.talk.ui.StatusDrawable
import com.nextcloud.talk.ui.bottom.sheet.ProfileBottomSheet
import com.nextcloud.talk.ui.dialog.AttachmentDialog
import com.nextcloud.talk.ui.dialog.DateTimePickerFragment
import com.nextcloud.talk.ui.dialog.MessageActionsDialog
import com.nextcloud.talk.ui.dialog.ShowReactionsDialog
import com.nextcloud.talk.ui.recyclerview.MessageSwipeActions
Expand Down Expand Up @@ -3833,6 +3835,12 @@ class ChatActivity :
startActivity(intent)
}

fun remindMeLater(message: ChatMessage?) {
Log.d(TAG, "remindMeLater called")
val newFragment: DialogFragment = DateTimePickerFragment.newInstance()
newFragment.show(supportFragmentManager, DateTimePickerFragment.TAG)
}

fun markAsUnread(message: IMessage?) {
val chatMessage = message as ChatMessage?
if (chatMessage!!.previousMessageId > NO_PREVIOUS_MESSAGE_ID) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ package com.nextcloud.talk.chat.data

import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.models.domain.ConversationModel

import com.nextcloud.talk.models.json.reminder.Reminder
import io.reactivex.Observable

interface ChatRepository {
fun getRoom(user: User, roomToken: String): Observable<ConversationModel>
fun joinRoom(user: User, roomToken: String, roomPassword: String): Observable<ConversationModel>
fun setReminder(user: User, roomToken: String, messageId: String, timeStamp: Int): Observable<Reminder>
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package com.nextcloud.talk.chat.data
import com.nextcloud.talk.api.NcApi
import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.models.domain.ConversationModel
import com.nextcloud.talk.models.json.reminder.Reminder
import com.nextcloud.talk.utils.ApiUtils
import io.reactivex.Observable

Expand Down Expand Up @@ -54,4 +55,11 @@ class ChatRepositoryImpl(private val ncApi: NcApi) : ChatRepository {
roomPassword
).map { ConversationModel.mapToConversationModel(it.ocs?.data!!) }
}

override fun setReminder(user: User, roomToken: String, messageId: String, timestamp: Int): Observable<Reminder> {
val credentials: String = ApiUtils.getCredentials(user.username, user.token)
val apiVersion = ApiUtils.getConversationApiVersion(user, intArrayOf(ApiUtils.APIv4, 1))
val url = ApiUtils.getUrlForChatMessage(apiVersion, user.baseUrl, roomToken, messageId)
return ncApi.setReminder(credentials, "$url/reminder", timestamp).map { it.ocs!!.data }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.lifecycle.ViewModel
import com.nextcloud.talk.chat.data.ChatRepository
import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.models.domain.ConversationModel
import com.nextcloud.talk.models.json.reminder.Reminder
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
Expand Down Expand Up @@ -71,6 +72,13 @@ class ChatViewModel @Inject constructor(private val repository: ChatRepository)
?.subscribe(JoinRoomObserver())
}

fun setReminder(user: User, roomToken: String, messageId: String, timestamp: Int) {
repository.setReminder(user, roomToken, messageId, timestamp)
.subscribeOn(Schedulers.io())
?.observeOn(AndroidSchedulers.mainThread())
?.subscribe(ReminderObserver())
}

inner class GetRoomObserver : Observer<ConversationModel> {
override fun onSubscribe(d: Disposable) {
// unused atm
Expand Down Expand Up @@ -109,6 +117,24 @@ class ChatViewModel @Inject constructor(private val repository: ChatRepository)
}
}

inner class ReminderObserver : Observer<Reminder> {
override fun onSubscribe(d: Disposable) {
// unused atm
}

override fun onNext(reminder: Reminder) {
// unused atm
}

override fun onError(e: Throwable) {
Log.e(TAG, "Error when sending reminder, $e")
}

override fun onComplete() {
// unused atm
}
}

companion object {
private val TAG = ChatViewModel::class.simpleName
const val JOIN_ROOM_RETRY_COUNT: Long = 3
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Nextcloud Talk application
*
* @author Julius Linus
* Copyright (C) 2023 Julius Linus <[email protected]>
*
* 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.models.json.reminder

import android.os.Parcelable
import com.bluelinelabs.logansquare.annotation.JsonField
import com.bluelinelabs.logansquare.annotation.JsonObject
import kotlinx.parcelize.Parcelize

@Parcelize
@JsonObject
data class Reminder(
@JsonField(name = ["userid"])
var userid: String? = null,
@JsonField(name = ["token"])
var token: String? = null,
@JsonField(name = ["messageId"])
var messageId: Int? = null,
@JsonField(name = ["timestamp"])
var timestamp: Int? = null
) : Parcelable {
// This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
constructor() : this(null, null, null, null)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Nextcloud Talk application
*
* @author Julius Linus
* Copyright (C) 2023 Julius Linus <[email protected]>
*
* 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.models.json.reminder

import android.os.Parcelable
import com.bluelinelabs.logansquare.annotation.JsonField
import com.bluelinelabs.logansquare.annotation.JsonObject
import com.nextcloud.talk.models.json.generic.GenericMeta
import kotlinx.parcelize.Parcelize

@Parcelize
@JsonObject
data class ReminderOCS(
@JsonField(name = ["meta"])
var meta: GenericMeta? = null,
@JsonField(name = ["data"])
var data: Reminder? = null
) : Parcelable {
// This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
constructor() : this(null, null)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Nextcloud Talk application
*
* @author Julius Linus
* Copyright (C) 2023 Julius Linus <[email protected]>
*
* 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.models.json.reminder

import android.os.Parcelable
import com.bluelinelabs.logansquare.annotation.JsonField
import com.bluelinelabs.logansquare.annotation.JsonObject
import kotlinx.parcelize.Parcelize

@Parcelize
@JsonObject
data class ReminderOverall(
@JsonField(name = ["ocs"])
var ocs: ReminderOCS? = null
) : Parcelable {
// This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
constructor() : this(null)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.nextcloud.talk.ui.dialog

import android.app.DatePickerDialog
import android.app.Dialog
import android.os.Bundle
import android.text.format.DateUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.timepicker.MaterialTimePicker
import com.nextcloud.talk.R
import com.nextcloud.talk.databinding.DialogDateTimePickerBinding
import java.util.Calendar

class DateTimePickerFragment : DialogFragment() {
lateinit var binding: DialogDateTimePickerBinding
private var dialogView: View? = null

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
binding = DialogDateTimePickerBinding.inflate(LayoutInflater.from(context))
dialogView = binding.root
// TODO theme all this too
setListeners()
return MaterialAlertDialogBuilder(requireContext()).setView(dialogView).create()
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.dialog_date_time_picker, container, false)
}

private fun setUpDefaults() {
// TODO set up date's, and hide or show them depending on current time
}

private fun setListeners() {
binding.dateTimePickerCustom.setOnClickListener {
val datePicker = DatePickerDialog(requireContext())

datePicker.setOnDateSetListener { _, year, month, day ->

val timePicker = MaterialTimePicker
.Builder()
.setTitleText(R.string.nc_remind)
.build()

timePicker.addOnPositiveButtonClickListener {
val calendar: Calendar = Calendar.getInstance()
calendar.set(Calendar.YEAR, year)
calendar.set(Calendar.MONTH, month)
calendar.set(Calendar.DAY_OF_MONTH, day)
calendar.set(Calendar.HOUR_OF_DAY, timePicker.hour)
calendar.set(Calendar.MINUTE, timePicker.minute)
calendar.set(Calendar.SECOND, 0)
val timestamp = calendar.timeInMillis
binding.dateTimePickerTimestamp.text = DateUtils.formatDateTime(
requireContext(), timestamp,
DateUtils.FORMAT_SHOW_DATE
) + ", " + DateUtils.formatDateTime(
requireContext(), timestamp,
DateUtils.FORMAT_SHOW_TIME
)
}

this.fragmentManager?.let { it1 -> timePicker.show(it1, TAG) }
}
datePicker.show()
}

binding.buttonClose.setOnClickListener { dismiss() }
binding.buttonSet.setOnClickListener {
//TODO set reminder here but call Marcel first to figure out how notifications work
dismiss()
}
}

companion object {
val TAG = DateTimePickerFragment::class.simpleName

@JvmStatic
fun newInstance() = DateTimePickerFragment()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class MessageActionsDialog(
ChatMessage.MessageType.REGULAR_TEXT_MESSAGE == message.getCalculateMessageType() &&
!(message.isDeletedCommentMessage || message.isDeleted)
)
initMenuRemindMessage(!message.isDeleted && CapabilitiesUtilNew.isRemindSupported(user))
initMenuMarkAsUnread(
message.previousMessageId > NO_PREVIOUS_MESSAGE_ID &&
ChatMessage.MessageType.SYSTEM_MESSAGE != message.getCalculateMessageType()
Expand Down Expand Up @@ -264,6 +265,17 @@ class MessageActionsDialog(
dialogMessageActionsBinding.menuForwardMessage.visibility = getVisibility(visible)
}

private fun initMenuRemindMessage(visible: Boolean) {
if (visible) {
dialogMessageActionsBinding.menuNotifyMessage.setOnClickListener {
chatActivity.remindMeLater(message)
dismiss()
}
}

dialogMessageActionsBinding.menuNotifyMessage.visibility = getVisibility(visible)
}

private fun initMenuDeleteMessage(visible: Boolean) {
if (visible) {
dialogMessageActionsBinding.menuDeleteMessage.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ object CapabilitiesUtilNew {
}

@JvmStatic
fun getAttachmentFolder(user: User): String? {
fun getAttachmentFolder(user: User): String {
if (user.capabilities?.spreedCapability?.config?.containsKey("attachments") == true) {
val map = user.capabilities!!.spreedCapability!!.config!!["attachments"]
if (map?.containsKey("folder") == true) {
Expand Down Expand Up @@ -241,5 +241,14 @@ object CapabilitiesUtilNew {
}
}

fun isRemindSupported(user: User?): Boolean {
if (user?.capabilities != null) {
val capabilities = user.capabilities
return capabilities?.spreedCapability?.features?.contains("remind-me-later") == true
}

return false
}

const val DEFAULT_CHAT_SIZE = 1000
}
Loading

0 comments on commit 6e3837c

Please sign in to comment.