Skip to content

Commit

Permalink
Merge pull request #3 from Parabox-App/develop
Browse files Browse the repository at this point in the history
1.0.6-beta
  • Loading branch information
ojhdt authored Nov 13, 2022
2 parents fdd1b6a + 0e9d574 commit 8b3feb6
Show file tree
Hide file tree
Showing 24 changed files with 469 additions and 311 deletions.
12 changes: 6 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ android {
applicationId "com.ojhdtapp.parabox"
minSdk 26
targetSdk 33
versionCode 7
versionName "1.0.5-beta"
versionCode 8
versionName "1.0.6-beta"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -139,7 +139,7 @@ dependencies {
implementation "commons-io:commons-io:2.7"

// Development Kit
implementation 'com.ojhdt:parabox-development-kit:1.0.4'
implementation 'com.ojhdt:parabox-development-kit:1.0.5'

// Paging
def paging_version = "3.2.0-alpha03"
Expand All @@ -161,8 +161,8 @@ dependencies {

// Compose Destinations
// implementation 'io.github.raamcosta.compose-destinations:core:1.5.6-beta'
implementation 'io.github.raamcosta.compose-destinations:animations-core:1.7.15-beta'
ksp 'io.github.raamcosta.compose-destinations:ksp:1.7.15-beta'
implementation 'io.github.raamcosta.compose-destinations:animations-core:1.7.25-beta'
ksp 'io.github.raamcosta.compose-destinations:ksp:1.7.25-beta'

// DataStore
implementation "androidx.datastore:datastore-preferences:1.0.0"
Expand All @@ -176,7 +176,7 @@ dependencies {
implementation "com.google.accompanist:accompanist-placeholder-material:$acc_version"

// Navigation Compose
def nav_version = "2.5.2"
def nav_version = "2.6.0-alpha04"
implementation "androidx.navigation:navigation-compose:$nav_version"

// m3
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Parabox"
android:usesCleartextTraffic="true"
tools:targetApi="tiramisu">
android:usesCleartextTraffic="true">

<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/ojhdtapp/parabox/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,9 @@ class MainActivity : AppCompatActivity() {
startService(pluginServiceBinderIntent)
bindService(pluginServiceBinderIntent, pluginServiceConnection, BIND_AUTO_CREATE)

pluginService?.also {
it.reset()
}
}
}
super.onStart()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,33 @@ class NotificationUtil(
var shortcuts = contacts.map {
val icon = it.profile.avatar?.let { url ->
withContext(Dispatchers.IO) {
val loader = ImageLoader(context)
val request = ImageRequest.Builder(context)
.data(url)
.allowHardware(false) // Disable hardware bitmaps.
.build()
val result = (loader.execute(request) as SuccessResult).drawable
val bitmap = (result as BitmapDrawable).bitmap
Icon.createWithAdaptiveBitmap(bitmap)
try {
val loader = ImageLoader(context)
val request = ImageRequest.Builder(context)
.data(url)
.allowHardware(false) // Disable hardware bitmaps.
.build()
val result = (loader.execute(request) as SuccessResult).drawable
val bitmap = (result as BitmapDrawable).bitmap
Icon.createWithAdaptiveBitmap(bitmap)
} catch (e: Exception) {
e.printStackTrace()
null
}
}
}
} ?: it.profile.avatarUri?.let { uri ->
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
Icon.createWithAdaptiveBitmapContentUri(uri)
else Icon.createWithAdaptiveBitmap(
FileUtil.getBitmapFromUri(
context,
Uri.parse(uri)
)
)
} ?: Icon.createWithResource(
context,
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) R.drawable.avatar_dynamic else R.drawable.avatar
)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
ShortcutInfo.Builder(context, it.contactId.toString())
.setLocusId(LocusId(it.contactId.toString()))
Expand Down Expand Up @@ -166,16 +183,7 @@ class NotificationUtil(
.setIntent(Intent(context, MainActivity::class.java).apply {
action = Intent.ACTION_VIEW
data = Uri.parse("parabox://contact/${it.contactId}")
}).apply {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
setPerson(
Person.Builder()
.setName(it.profile.name)
.setIcon(icon)
.build()
)
}
}
})
.build()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ data class ContactProfileAndTagUpdate(
val name: String,
@ColumnInfo(name = "avatar")
val avatar: String?,
@ColumnInfo(name = "avatarUri")
val avatarUri: String?,
@ColumnInfo(name = "tags")
val tags: List<String>,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ data class MessageEntity(
val contentString: String,
@Embedded val profile: Profile,
val timestamp: Long,
@PrimaryKey val messageId: Long,
@PrimaryKey(autoGenerate = true) val messageId: Long,
val sentByMe: Boolean,
val verified : Boolean,
val sendType: Int? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.ojhdtapp.parabox.data.remote.dto

import android.content.Context
import android.media.MediaMetadataRetriever
import android.net.Uri
import com.ojhdtapp.parabox.core.util.FileUtil
import com.ojhdtapp.parabox.core.util.toDateAndTimeString
import com.ojhdtapp.parabox.data.local.entity.ContactEntity
Expand All @@ -15,9 +16,9 @@ import com.ojhdtapp.parabox.domain.model.message_content.*
import com.ojhdtapp.paraboxdevelopmentkit.messagedto.ReceiveMessageDto
import com.ojhdtapp.paraboxdevelopmentkit.messagedto.message_content.getContentString

fun ReceiveMessageDto.toContactEntity(): ContactEntity {
fun ReceiveMessageDto.toContactEntity(context: Context): ContactEntity {
return ContactEntity(
profile = subjectProfile.toProfile(),
profile = subjectProfile.toProfile(context),
latestMessage = LatestMessage(
sender = profile.name,
content = contents.getContentString(),
Expand All @@ -38,7 +39,7 @@ fun ReceiveMessageDto.toMessageEntity(context: Context): MessageEntity {
return MessageEntity(
contents = contents.toMessageContentList(context),
contentString = contents.getContentString(),
profile = profile.toProfile(),
profile = profile.toProfile(context),
timestamp = timestamp,
messageId = messageId ?: 0,
sentByMe = false,
Expand All @@ -49,17 +50,17 @@ fun ReceiveMessageDto.toMessageEntity(context: Context): MessageEntity {
fun ReceiveMessageDto.toMessage(context: Context, messageIdInDatabase: Long = 0): Message {
return Message(
contents = contents.toMessageContentList(context),
profile = profile.toProfile(),
profile = profile.toProfile(context),
timestamp = timestamp,
messageId = messageId ?: messageIdInDatabase,
sentByMe = false,
verified = true
)
}

fun ReceiveMessageDto.toContact(): Contact {
fun ReceiveMessageDto.toContact(context: Context): Contact {
return Contact(
profile = subjectProfile.toProfile(),
profile = subjectProfile.toProfile(context),
latestMessage = LatestMessage(
sender = profile.name,
content = contents.getContentString(),
Expand Down Expand Up @@ -106,8 +107,15 @@ fun ReceiveMessageDto.toContact(): Contact {
// )
//}

fun com.ojhdtapp.paraboxdevelopmentkit.messagedto.Profile.toProfile(): Profile {
return Profile(this.name, this.avatar, null, this.id)
fun com.ojhdtapp.paraboxdevelopmentkit.messagedto.Profile.toProfile(context: Context): Profile {
return Profile(this.name, this.avatar, this.avatarUri?.let {
FileUtil.getUriByCopyingFileToPath(
context,
context.getExternalFilesDir("chat")!!,
"Avatar_${this.name.replace("\\s+", "_")}.png",
it
)?.toString()
}, this.id)
}

fun List<com.ojhdtapp.paraboxdevelopmentkit.messagedto.message_content.MessageContent>.toMessageContentList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ class ReceiveMessageDtoJsonDeserializer : JsonDeserializer<ReceiveMessageDto> {
Profile(
profileObj.get("name").asString,
profileObj.get("avatar").asString,
profileObj.get("id").asLong
profileObj.get("id").asLong,
null
)
} else null
val subjectProfile = if (it.has("subjectProfile")) {
val profileObj = it.get("subjectProfile").asJsonObject
Profile(
profileObj.get("name").asString,
profileObj.get("avatar").asString,
profileObj.get("id").asLong
profileObj.get("id").asLong,
null
)
} else null
val timestamp = it.get("timestamp").asLong
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class MainRepositoryImpl @Inject constructor(
// dto.toContactEntityWithUnreadMessagesNumUpdate(
// database.contactDao
// )
dto.toContactEntity()
dto.toContactEntity(context)
)
}
val pluginConnectionDeferred = async<Long> {
Expand Down Expand Up @@ -89,7 +89,7 @@ class MainRepositoryImpl @Inject constructor(
database.contactDao.getPluginConnectionWithContacts(dto.pluginConnection.objectId).let {
database.contactDao.updateContact(it.contactList.map {
it.copy(
profile = if (it.senderId == it.contactId) dto.subjectProfile.toProfile() else it.profile,
profile = if (it.senderId == it.contactId) dto.subjectProfile.toProfile(context) else it.profile,
latestMessage =
if (it.latestMessage != null && it.latestMessage.timestamp < dto.timestamp) {
LatestMessage(
Expand Down Expand Up @@ -134,7 +134,7 @@ class MainRepositoryImpl @Inject constructor(
if ((allowForegroundNotification || MainActivity.inBackground) && it?.enableNotifications == true && !it.isArchived) {
notificationUtil.sendNewMessageNotification(
message = dto.toMessage(context, messageIdDeferred.await()),
contact = dto.toContact(),
contact = dto.toContact(context),
channelId = dto.pluginConnection.connectionType.toString()
)
}
Expand All @@ -152,7 +152,7 @@ class MainRepositoryImpl @Inject constructor(
if (allowForegroundNotification || MainActivity.inBackground) {
notificationUtil.sendNewMessageNotification(
message = dto.toMessage(context, messageIdDeferred.await()),
contact = dto.toContact(),
contact = dto.toContact(context),
channelId = dto.pluginConnection.connectionType.toString()
)
}
Expand Down Expand Up @@ -356,6 +356,7 @@ class MainRepositoryImpl @Inject constructor(
id,
profile.name,
profile.avatar,
profile.avatarUri,
tags
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ojhdtapp.parabox.domain.model

import android.net.Uri
import com.ojhdtapp.parabox.ui.message.GroupEditResource

data class GroupInfoPack(
Expand All @@ -13,6 +14,9 @@ data class GroupInfoPack(
}, avatar = contacts.fold(mutableListOf()) { acc, contact ->
contact.profile.avatar?.let { acc.add(it) }
acc
}, avatarUri = contacts.fold(mutableListOf()) { acc, contact ->
contact.profile.avatarUri?.let { acc.add(Uri.parse(it)) }
acc
}, pluginConnections = pluginConnectionsDistinct)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,12 @@ class PluginConnObj(
}
}

private fun coreSendCommand(timestamp: Long, key: String, command: Int, extra: Bundle = Bundle()) {
private fun coreSendCommand(
timestamp: Long,
key: String,
command: Int,
extra: Bundle = Bundle()
) {
if (!isConnected) {
deferredMap[key]?.complete(
ParaboxResult.Fail(
Expand Down Expand Up @@ -394,6 +399,8 @@ class PluginConnObj(
e.printStackTrace()
} catch (e: ClassNotFoundException) {
e.printStackTrace()
} catch (e: NullPointerException) {
e.printStackTrace()
}
}
}
Expand Down Expand Up @@ -424,30 +431,40 @@ class PluginConnObj(
}
Log.d("parabox", "try complete second deferred")
deferredMap[metadata.key]?.complete(result)
} catch (e: NullPointerException) {
} catch (e: RemoteException) {
e.printStackTrace()
} catch (e: ClassNotFoundException) {
e.printStackTrace()
} catch (e: NullPointerException) {
e.printStackTrace()
}
}

ParaboxKey.TYPE_NOTIFICATION -> {
val timestamp = obj.getLong("timestamp")
when (msg.what) {
ParaboxKey.NOTIFICATION_STATE_UPDATE -> {
val state = obj.getInt("state", ParaboxKey.STATE_ERROR)
val message = obj.getString("message", "")
Log.d("parabox", "service state changed:${state}")
runningStatus = when (state) {
ParaboxKey.STATE_ERROR -> AppModel.RUNNING_STATUS_ERROR
ParaboxKey.STATE_LOADING -> AppModel.RUNNING_STATUS_CHECKING
ParaboxKey.STATE_PAUSE -> AppModel.RUNNING_STATUS_CHECKING
ParaboxKey.STATE_STOP -> AppModel.RUNNING_STATUS_DISABLED
ParaboxKey.STATE_RUNNING -> AppModel.RUNNING_STATUS_RUNNING
else -> AppModel.RUNNING_STATUS_DISABLED
try {
val timestamp = obj.getLong("timestamp")
when (msg.what) {
ParaboxKey.NOTIFICATION_STATE_UPDATE -> {
val state = obj.getInt("state", ParaboxKey.STATE_ERROR)
val message = obj.getString("message", "")
Log.d("parabox", "service state changed:${state}")
runningStatus = when (state) {
ParaboxKey.STATE_ERROR -> AppModel.RUNNING_STATUS_ERROR
ParaboxKey.STATE_LOADING -> AppModel.RUNNING_STATUS_CHECKING
ParaboxKey.STATE_PAUSE -> AppModel.RUNNING_STATUS_CHECKING
ParaboxKey.STATE_STOP -> AppModel.RUNNING_STATUS_DISABLED
ParaboxKey.STATE_RUNNING -> AppModel.RUNNING_STATUS_RUNNING
else -> AppModel.RUNNING_STATUS_DISABLED
}
onRunningStatusChange(connectionType, runningStatus)
}
onRunningStatusChange(connectionType, runningStatus)
}
} catch (e: RemoteException) {
e.printStackTrace()
} catch (e: ClassNotFoundException) {
e.printStackTrace()
} catch (e: NullPointerException) {
e.printStackTrace()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1745,7 +1745,7 @@ fun MessageBlock(
MessageAvatar(
shouldDisplay = isFirst,
avatar = message.profile.avatar,
avatarUri = null,
avatarUri = message.profile.avatarUri,
onClick = {},
onLongClick = onAvatarLongClick,
)
Expand Down
Loading

0 comments on commit 8b3feb6

Please sign in to comment.