Skip to content

Commit 925baf6

Browse files
committed
another update
1 parent f8407ee commit 925baf6

32 files changed

+182
-36
lines changed

app/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ android {
1010

1111
defaultConfig {
1212
applicationId = "com.troplo.privateuploader"
13-
minSdk = 24
13+
minSdk = 26
1414
targetSdk = 33
1515
versionCode = 1
1616
versionName = "1.0"

app/release/app-release.aab

12.2 MB
Binary file not shown.
10.4 KB
Loading

app/src/main/java/com/troplo/privateuploader/MainActivity.kt

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class MainActivity : ComponentActivity() {
2020
override fun onCreate(savedInstanceState: Bundle?) {
2121
val token = SessionManager(this).fetchAuthToken()
2222
var user: User? = null
23+
2324
if(token != null) {
2425
TpuApi.retrofitService.getUser(token).enqueue(object : retrofit2.Callback<User> {
2526
override fun onResponse(

app/src/main/java/com/troplo/privateuploader/MainScreen.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fun MainScreen(user: User?) {
2525
val context = LocalContext.current
2626
val token = SessionManager(context).fetchAuthToken()
2727
if (token != null) {
28-
SocketHandler.initializeSocket(token)
28+
SocketHandler.initializeSocket(token, context)
2929
UserHandler.initializeUser(token)
3030
}
3131
val navController = rememberNavController()

app/src/main/java/com/troplo/privateuploader/api/Functions.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ object TpuFunctions {
3232
}
3333

3434
fun formatDate(date: Date?): CharSequence? {
35-
return DateFormat.format("dd MMMM yyyy, h:mm a", date)
35+
if(DateFormat.format("dd MMMM yyyy", date) == DateFormat.format("dd MMMM yyyy", Date())) {
36+
return DateFormat.format("hh:mm:ss a", date)
37+
}
38+
return DateFormat.format("dd MMMM yyyy, hh:mm:ss a", date)
3639
}
3740
}

app/src/main/java/com/troplo/privateuploader/api/SocketHandler.kt

+70-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
package com.troplo.privateuploader.api
22

3+
import android.app.Notification
4+
import android.app.NotificationManager
5+
import android.app.PendingIntent
36
import android.content.Context
7+
import android.content.Intent
8+
import android.graphics.drawable.Icon
9+
import androidx.compose.material.icons.Icons
10+
import androidx.compose.material.icons.filled.Reply
11+
import androidx.core.app.NotificationCompat
12+
import androidx.core.app.NotificationManagerCompat
13+
import androidx.core.app.RemoteInput
14+
import androidx.core.content.ContextCompat.getSystemService
15+
import com.google.gson.Gson
16+
import com.troplo.privateuploader.R
17+
import com.troplo.privateuploader.data.model.MessageEvent
418
import io.socket.client.IO
5-
import io.socket.client.Manager
619
import io.socket.client.Socket
7-
import java.net.URI
20+
import org.json.JSONObject
821
import java.net.URISyntaxException
922
import java.util.Collections
1023

@@ -13,8 +26,9 @@ object SocketHandler {
1326
private const val SERVER_URL = "http://192.168.0.12:34582" // Replace with your Socket.io server URL
1427

1528
private var socket: Socket? = null
29+
private val gson = Gson()
1630

17-
fun initializeSocket(token: String) {
31+
fun initializeSocket(token: String, context: Context) {
1832
try {
1933
val options = IO.Options()
2034
options.forceNew = true
@@ -32,10 +46,51 @@ object SocketHandler {
3246
socket?.on(Socket.EVENT_CONNECT_ERROR) {
3347
println("Socket connect error ${socket?.isActive}")
3448
}
35-
// socket on any other events
36-
socket?.on("message") {
37-
println("Socket $it")
38-
}
49+
/*socket?.on("message") {
50+
val jsonArray = it[0] as JSONObject
51+
val payload = jsonArray.toString()
52+
val messageEvent = gson.fromJson(payload, MessageEvent::class.java)
53+
54+
val message = messageEvent.message
55+
56+
val notificationBuilder = NotificationCompat.Builder(context, "communications")
57+
.setSmallIcon(R.drawable.ic_launcher_foreground)
58+
.setContentTitle(message.user?.username)
59+
.setContentText(message.content)
60+
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
61+
.setContentIntent(null)
62+
63+
val remoteInput: RemoteInput = RemoteInput.Builder("reply").run {
64+
setLabel("Reply")
65+
build()
66+
}
67+
68+
/* val replyPendingIntent: PendingIntent =
69+
PendingIntent.getBroadcast(
70+
context,
71+
messageEvent.association.id,
72+
getMessageReplyIntent(messageEvent.association.id),
73+
PendingIntent.FLAG_MUTABLE
74+
)
75+
76+
val action: NotificationCompat.Action =
77+
NotificationCompat.Action.Builder(
78+
null,
79+
"Reply",
80+
replyPendingIntent
81+
)
82+
.addRemoteInput(remoteInput)
83+
.build()
84+
*/
85+
val newMessageNotification = Notification.Builder(context, "communications")
86+
.setSmallIcon(R.drawable.ic_launcher_foreground)
87+
.setContentTitle(message.user?.username)
88+
.setContentText(message.content)
89+
.build()
90+
val notificationManager: NotificationManager =
91+
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
92+
notificationManager.notify(message.id, newMessageNotification)
93+
}*/
3994
println("Socket connected ${socket?.isActive}")
4095
} else {
4196
println("Socket is null")
@@ -45,6 +100,14 @@ object SocketHandler {
45100
}
46101
}
47102

103+
private fun getMessageReplyIntent(associationId: Int): Intent {
104+
return Intent()
105+
.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
106+
.setAction("reply")
107+
.putExtra("associationId", associationId)
108+
}
109+
110+
48111
fun getSocket(): Socket? {
49112
return socket
50113
}

app/src/main/java/com/troplo/privateuploader/api/TpuConfig.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ class TpuConfig (private val sharedPref: SharedPreferences) {
77
get() = sharedPref.getString("token", null)
88
set(value) = sharedPref.edit().putString("token", value).apply()
99

10-
var instance: String? = "http://192.168.0.12:34582"
10+
var instance: String? = "https://privateuploader.com"
1111
}

app/src/main/java/com/troplo/privateuploader/components/chat/Message.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,16 @@ fun Message(@PreviewParameter(
8282
if (normal) {
8383
UserAvatar(
8484
avatar = message.user?.avatar,
85-
username = message.user?.username ?: "Deleted User"
85+
username = message.user?.username ?: "Deleted User",
86+
modifier = Modifier.align(Alignment.Top)
8687
)
8788
}
8889
if (!normal) {
8990
Spacer(modifier = Modifier.width(40.dp))
9091
}
9192
Column(modifier = Modifier.padding(start = 8.dp)) {
9293
if (normal) {
93-
Row(verticalAlignment = Alignment.CenterVertically) {
94+
Row {
9495
Text(
9596
text = message.user?.username ?: "Deleted User",
9697
style = MaterialTheme.typography.bodyMedium,

app/src/main/java/com/troplo/privateuploader/components/core/NavRoute.kt

+15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
package com.troplo.privateuploader.components.core
22

3+
import com.troplo.privateuploader.api.ChatStore
4+
import com.troplo.privateuploader.api.TpuFunctions
5+
import com.troplo.privateuploader.data.model.Chat
6+
7+
fun getCurrentRouteTitle(route: String): String {
8+
return when (route) {
9+
NavRoute.Home.path -> "Chat"
10+
NavRoute.Gallery.path -> "Gallery"
11+
NavRoute.Settings.path -> "Settings"
12+
NavRoute.SettingsUpload.path -> "Upload"
13+
NavRoute.Chat.path -> "Chat"
14+
else -> "PrivateUploader"
15+
}
16+
}
17+
318
sealed class NavRoute(val path: String) {
419
object Login: NavRoute("login")
520
object Home: NavRoute("home")

app/src/main/java/com/troplo/privateuploader/components/core/TopNav.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fun TopBarNav(navController: NavController, user: User?) {
5252
},
5353
title = {
5454
Text(
55-
"${navBackStackEntry?.destination?.route} (TPUvNATIVE)" ?: "PrivateUploader",
55+
text = getCurrentRouteTitle(currentRoute),
5656
maxLines = 1,
5757
overflow = TextOverflow.Ellipsis
5858
)

app/src/main/java/com/troplo/privateuploader/components/core/UserAvatar.kt

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.troplo.privateuploader.api.TpuFunctions
2222
fun UserAvatar(
2323
avatar: String?,
2424
username: String,
25+
modifier: Modifier = Modifier,
2526
) {
2627
if(avatar != null) {
2728
GlideImage(
@@ -30,6 +31,7 @@ fun UserAvatar(
3031
modifier = Modifier
3132
.size(40.dp)
3233
.clip(CircleShape)
34+
.then(modifier)
3335
)
3436
} else {
3537
Column(
@@ -39,6 +41,7 @@ fun UserAvatar(
3941
.size(40.dp)
4042
.background(MaterialTheme.colorScheme.primary, CircleShape)
4143
.clip(CircleShape)
44+
.then(modifier)
4245
) {
4346
Text(
4447
text = username.first().toString(),

app/src/main/java/com/troplo/privateuploader/data/model/Message.kt

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ data class Message(
1111
@field:Json(name = "userId") val userId: Int,
1212
@field:Json(name = "content") val content: String,
1313
@field:Json(name = "type") val type: String,
14-
@field:Json(name = "embeds") val embeds: List<Embed>,
14+
@field:Json(name = "embeds") var embeds: List<Embed>,
1515
@field:Json(name = "edited") val edited: Boolean,
1616
@field:Json(name = "editedAt") val editedAt: String?,
1717
@field:Json(name = "replyId") val replyId: Int?,
@@ -63,4 +63,9 @@ data class EmbedResolutionEvent(
6363
@field:Json(name = "chatId") val chatId: Int,
6464
@field:Json(name = "id") val id: Int,
6565
@field:Json(name = "embeds") val embeds: List<Embed>
66+
)
67+
68+
data class EmbedFail(
69+
val data: EmbedResolutionEvent,
70+
val retries: Int
6671
)

0 commit comments

Comments
 (0)