Skip to content

Commit 5025bee

Browse files
committed
Cleanup
1 parent f731b94 commit 5025bee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+510
-632
lines changed

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

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ import kotlinx.coroutines.launch
4343

4444

4545
class FirebaseChatService : FirebaseMessagingService() {
46-
private val messages = mutableMapOf<Int, MutableList<NotificationCompat.MessagingStyle.Message>>()
46+
private val messages =
47+
mutableMapOf<Int, MutableList<NotificationCompat.MessagingStyle.Message>>()
4748

4849
private fun isAppOnForeground(context: Context): Boolean {
4950
val activityManager = context.getSystemService(ACTIVITY_SERVICE) as ActivityManager
@@ -59,7 +60,7 @@ class FirebaseChatService : FirebaseMessagingService() {
5960

6061
override fun onMessageReceived(remoteMessage: RemoteMessage) {
6162
Log.d(TAG, "[NewChatService] Message received")
62-
if(isAppOnForeground(this)) {
63+
if (isAppOnForeground(this)) {
6364
Log.d(TAG, "[NewChatService] App is on foreground")
6465
return
6566
}
@@ -111,7 +112,7 @@ class FirebaseChatService : FirebaseMessagingService() {
111112
}
112113

113114
private fun sendRegistrationToServer(token: String?) {
114-
if(token != null) {
115+
if (token != null) {
115116
Log.d("$TAG.FCMToken", token)
116117
CoroutineScope(Dispatchers.IO).launch {
117118
TpuApi.retrofitService.registerFcmToken(FCMTokenRequest(token))
@@ -156,7 +157,8 @@ class FirebaseChatService : FirebaseMessagingService() {
156157
NotificationManager.IMPORTANCE_HIGH
157158
)
158159
notificationManager.createNotificationChannel(channel)
159-
if (messages[message.associationId] == null) messages[message.associationId] = mutableListOf()
160+
if (messages[message.associationId] == null) messages[message.associationId] =
161+
mutableListOf()
160162
messages[message.associationId]?.add(
161163
NotificationCompat.MessagingStyle.Message(
162164
message.content,
@@ -172,10 +174,15 @@ class FirebaseChatService : FirebaseMessagingService() {
172174
style.addMessage(msg)
173175
}
174176

175-
val rep = Intent(this, InlineNotificationActivity::class.java)
176-
rep.replaceExtras(Bundle())
177-
rep.putExtra("chatId", message.associationId)
178-
val replyPendingIntent = PendingIntent.getBroadcast(this, message.associationId, rep, PendingIntent.FLAG_MUTABLE)
177+
val rep = Intent(this, InlineNotificationActivity::class.java)
178+
rep.replaceExtras(Bundle())
179+
rep.putExtra("chatId", message.associationId)
180+
val replyPendingIntent = PendingIntent.getBroadcast(
181+
this,
182+
message.associationId,
183+
rep,
184+
PendingIntent.FLAG_MUTABLE
185+
)
179186

180187
val remoteInput = RemoteInput.Builder("content")
181188
.setLabel("Reply")
@@ -190,28 +197,32 @@ class FirebaseChatService : FirebaseMessagingService() {
190197
.setAllowGeneratedReplies(true)
191198
.build()
192199

193-
val builder: NotificationCompat.Builder = NotificationCompat.Builder(this, "communications")
194-
.addPerson(chatPartner)
195-
.setStyle(style)
196-
.setContentText(message.content)
197-
.setContentTitle(message.username)
198-
.setSmallIcon(R.drawable.tpu_logo)
199-
.setWhen(TpuFunctions.getDate(message.createdAt)?.time ?: 0)
200-
.addAction(replyAction)
201-
.setContentIntent(
202-
PendingIntent.getActivity(
203-
this,
204-
message.associationId,
205-
Intent(this, MainActivity::class.java).apply {
206-
putExtra("chatId", message.associationId)
207-
},
208-
PendingIntent.FLAG_MUTABLE
200+
val builder: NotificationCompat.Builder =
201+
NotificationCompat.Builder(this, "communications")
202+
.addPerson(chatPartner)
203+
.setStyle(style)
204+
.setContentText(message.content)
205+
.setContentTitle(message.username)
206+
.setSmallIcon(R.drawable.tpu_logo)
207+
.setWhen(TpuFunctions.getDate(message.createdAt)?.time ?: 0)
208+
.addAction(replyAction)
209+
.setContentIntent(
210+
PendingIntent.getActivity(
211+
this,
212+
message.associationId,
213+
Intent(this, MainActivity::class.java).apply {
214+
putExtra("chatId", message.associationId)
215+
},
216+
PendingIntent.FLAG_MUTABLE
217+
)
209218
)
210-
)
211219
val res = notificationManager.notify(message.associationId, builder.build())
212220
Log.d("TPU.Untagged", "[ChatService] Notification sent, $res")
213221
} catch (e: Exception) {
214-
Log.d("TPU.Untagged", "[ChatService] Error sending notification, ${e.printStackTrace()}")
222+
Log.d(
223+
"TPU.Untagged",
224+
"[ChatService] Error sending notification, ${e.printStackTrace()}"
225+
)
215226
}
216227
}
217228
}
@@ -220,7 +231,8 @@ class FirebaseChatService : FirebaseMessagingService() {
220231
private const val TAG = "FirebaseChatService"
221232
}
222233

223-
internal class MyWorker(appContext: Context, workerParams: WorkerParameters) : Worker(appContext, workerParams) {
234+
internal class MyWorker(appContext: Context, workerParams: WorkerParameters) :
235+
Worker(appContext, workerParams) {
224236
override fun doWork(): Result {
225237
// TODO(developer): add long running task here.
226238
return Result.success()

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
package com.troplo.privateuploader
22

3-
import android.app.NotificationManager
43
import android.content.BroadcastReceiver
54
import android.content.Context
65
import android.content.Intent
7-
import android.os.Build
86
import android.util.Log
9-
import androidx.core.app.NotificationCompat
10-
import androidx.core.app.Person
117
import androidx.core.app.RemoteInput
128
import com.troplo.privateuploader.api.SessionManager
139
import com.troplo.privateuploader.api.TpuApi
14-
import com.troplo.privateuploader.api.TpuFunctions
1510
import com.troplo.privateuploader.data.model.MessageRequest
1611
import kotlinx.coroutines.CoroutineScope
1712
import kotlinx.coroutines.Dispatchers
1813
import kotlinx.coroutines.launch
19-
import java.io.Serializable
2014

2115

22-
class InlineNotificationActivity: BroadcastReceiver() {
16+
class InlineNotificationActivity : BroadcastReceiver() {
2317
override fun onReceive(context: Context, intent: Intent) {
2418
try {
2519
Log.d(

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.troplo.privateuploader
22

3-
import android.content.Intent
3+
import android.Manifest
44
import android.content.pm.PackageManager
55
import android.os.Build
66
import android.os.Bundle
@@ -9,16 +9,13 @@ import androidx.activity.ComponentActivity
99
import androidx.activity.compose.setContent
1010
import androidx.activity.result.contract.ActivityResultContracts
1111
import androidx.core.content.ContextCompat
12+
import com.google.android.gms.common.GoogleApiAvailability
1213
import com.troplo.privateuploader.api.SessionManager
1314
import com.troplo.privateuploader.api.SocketHandler
1415
import com.troplo.privateuploader.api.SocketHandlerService
1516
import com.troplo.privateuploader.api.TpuApi
1617
import com.troplo.privateuploader.api.stores.UserStore
1718
import com.troplo.privateuploader.ui.theme.PrivateUploaderTheme
18-
import android.Manifest
19-
import android.content.Context
20-
import androidx.core.app.RemoteInput
21-
import com.google.android.gms.common.GoogleApiAvailability
2219

2320
class MainActivity : ComponentActivity() {
2421
override fun onResume() {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ import com.troplo.privateuploader.components.core.rememberOverlappingPanelsState
3838
import com.troplo.privateuploader.screens.HomeScreen
3939
import io.sentry.compose.SentryTraced
4040

41-
@OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class,
41+
@OptIn(
42+
ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class,
4243
ExperimentalMaterialApi::class
4344
)
4445

@@ -69,7 +70,7 @@ fun MainScreen() {
6970

7071
if (openPanel) {
7172
LaunchedEffect(Unit) {
72-
if(!panelState.isPanelsClosed) {
73+
if (!panelState.isPanelsClosed) {
7374
panelState.closePanels()
7475
} else {
7576
panelState.openStartPanel()
@@ -127,7 +128,7 @@ fun MainScreen() {
127128
NavGraph(
128129
modifier = Modifier.padding(
129130
top = paddingValues.calculateTopPadding(),
130-
bottom = if(navController.currentDestination?.route?.startsWith("chat/") == true) 0.dp else paddingValues.calculateBottomPadding()
131+
bottom = if (navController.currentDestination?.route?.startsWith("chat/") == true) 0.dp else paddingValues.calculateBottomPadding()
131132
),
132133
navController = navController,
133134
user = user.value,

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ object TpuApi {
7777
// replace BuildConfig.SERVER_URL with baseUrl for multiple TPU instances
7878
private val hostInterceptor = Interceptor { chain ->
7979
val url = URL(instance)
80-
val port = if(url.port == -1) url.defaultPort else url.port
80+
val port = if (url.port == -1) url.defaultPort else url.port
8181
val scheme = url.protocol
8282
val host = url.host
8383

@@ -103,7 +103,7 @@ object TpuApi {
103103
if (!response.isSuccessful) {
104104
val error: JSONObject = JSONObject(response.body?.string() ?: "{}")
105105
val errorType = error.getJSONArray("errors").getJSONObject(0).getString("name")
106-
if(errorType == "INVALID_TOKEN") {
106+
if (errorType == "INVALID_TOKEN") {
107107
UserStore.logout(context)
108108
} else {
109109
val errorMessage =
@@ -198,7 +198,7 @@ object TpuApi {
198198
@GET("chats/{id}/messages")
199199
fun getMessages(
200200
@Path("id") id: Int,
201-
@Query("offset") offset: Int? = null
201+
@Query("offset") offset: Int? = null,
202202
): Call<List<Message>>
203203

204204
@POST("chats/{id}/message")
@@ -226,7 +226,7 @@ object TpuApi {
226226

227227
@GET("user/profile/{username}")
228228
fun getUserProfile(
229-
@Path("username") username: String
229+
@Path("username") username: String,
230230
): Call<User>
231231

232232
@GET("user/friends")
@@ -236,12 +236,12 @@ object TpuApi {
236236
fun searchMessages(
237237
@Path("chatId") chatId: Int,
238238
@Query("query") query: String = "",
239-
@Query("page") page: Int = 1
239+
@Query("page") page: Int = 1,
240240
): Call<MessageSearchResponse>
241241

242242
@POST("chats")
243243
fun createChat(
244-
@Body members: ChatCreateRequest
244+
@Body members: ChatCreateRequest,
245245
): Call<Chat>
246246

247247
@GET("/api/v3/core")
@@ -250,23 +250,23 @@ object TpuApi {
250250
@POST("user/friends/username/{username}/{type}")
251251
fun addFriend(
252252
@Path("username") username: String,
253-
@Path("type") type: String
253+
@Path("type") type: String,
254254
): Call<Unit>
255255

256256
@POST("user/fcmToken")
257257
fun registerFcmToken(
258-
@Body token: FCMTokenRequest
258+
@Body token: FCMTokenRequest,
259259
): Call<Unit>
260260

261261
@PATCH("user")
262262
fun updateUser(
263-
@Body user: PatchUser
263+
@Body user: PatchUser,
264264
): Call<Unit>
265265

266266
@Multipart
267267
@POST("gallery")
268268
fun uploadFile(
269-
@Part attachment: MultipartBody.Part
269+
@Part attachment: MultipartBody.Part,
270270
): Call<UploadResponse>
271271
}
272272

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ import java.io.FileInputStream
1010
import java.io.FileOutputStream
1111
import java.text.DateFormat
1212
import java.text.SimpleDateFormat
13-
import java.time.Instant
1413
import java.time.LocalDate
1514
import java.time.ZoneId
1615
import java.time.ZoneOffset
1716
import java.time.ZonedDateTime
1817
import java.time.format.DateTimeFormatter
19-
import java.util.Calendar
2018
import java.util.Date
2119
import kotlin.math.ln
2220
import kotlin.math.pow

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
package com.troplo.privateuploader.api
22

3-
import android.content.ContentResolver
4-
import android.content.Context
5-
import android.net.Uri
63
import android.os.Handler
74
import android.os.Looper
8-
import android.util.Log
95
import okhttp3.MediaType
106
import okhttp3.MediaType.Companion.toMediaTypeOrNull
117
import okhttp3.RequestBody
128
import okio.BufferedSink
139
import java.io.File
1410
import java.io.FileInputStream
15-
import java.io.IOException
16-
import java.io.InputStream
17-
import java.lang.ref.WeakReference
1811

1912

2013
class RequestBodyWithProgress(
2114
private val file: File,
2215
private val contentType: ContentType,
23-
private val progressCallback:((progress: Float)->Unit)?
16+
private val progressCallback: ((progress: Float) -> Unit)?,
2417
) : RequestBody() {
2518

2619
override fun contentType(): MediaType? = contentType.description.toMediaTypeOrNull()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class SessionManager(context: Context) {
9696

9797
fun getTheme(): ThemeOption {
9898
val theme = prefs.getString("theme", ThemeOption.System.name)
99-
return if(theme == null) {
99+
return if (theme == null) {
100100
ThemeOption.System
101101
} else {
102102
ThemeOption.valueOf(theme)

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,28 @@ object SocketHandler {
3939
socket = IO.socket(baseUrl, options)
4040
if (socket != null) {
4141
socket?.open()
42-
if(platform !== "android_kotlin_background_service") {
42+
if (platform !== "android_kotlin_background_service") {
4343
socket?.on(Socket.EVENT_CONNECT) {
4444
this.connected.value = true
45-
Log.d("TPU.Untagged", "Socket connected ${socket?.isActive}, Connected: ${this.connected.value}")
45+
Log.d(
46+
"TPU.Untagged",
47+
"Socket connected ${socket?.isActive}, Connected: ${this.connected.value}"
48+
)
4649
}
4750
socket?.on(Socket.EVENT_DISCONNECT) {
4851
this.connected.value = false
49-
Log.d("TPU.Untagged", "Socket disconnected ${socket?.isActive}, Connected: ${this.connected.value}")
52+
Log.d(
53+
"TPU.Untagged",
54+
"Socket disconnected ${socket?.isActive}, Connected: ${this.connected.value}"
55+
)
5056
}
5157
socket?.on(Socket.EVENT_CONNECT_ERROR) {
5258
try {
5359
this.connected.value = false
54-
Log.d("TPU.Untagged", "Socket connect error ${socket?.isActive}, Connected: ${this.connected.value}, Error: ${it[0]}")
60+
Log.d(
61+
"TPU.Untagged",
62+
"Socket connect error ${socket?.isActive}, Connected: ${this.connected.value}, Error: ${it[0]}"
63+
)
5564
} catch (e: Exception) {
5665
//
5766
}

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
package com.troplo.privateuploader.api
22

33
import android.content.Context
4-
import android.content.Intent
54
import android.util.Log
65
import androidx.compose.runtime.mutableStateOf
76
import com.google.gson.Gson
87
import com.troplo.privateuploader.BuildConfig
9-
import com.troplo.privateuploader.data.model.MessageEvent
10-
import com.troplo.privateuploader.data.model.Typing
118
import io.socket.client.IO
129
import io.socket.client.Socket
13-
import kotlinx.coroutines.CoroutineScope
14-
import kotlinx.coroutines.Dispatchers
15-
import kotlinx.coroutines.launch
16-
import org.json.JSONObject
1710
import java.net.URISyntaxException
1811
import java.util.Collections
19-
import java.util.concurrent.Executors
2012

2113
object SocketHandlerService {
2214
private var socket: Socket? = null

0 commit comments

Comments
 (0)