Skip to content

Commit 4b749c5

Browse files
committed
Update
1 parent d5d2d27 commit 4b749c5

File tree

22 files changed

+494
-55
lines changed

22 files changed

+494
-55
lines changed

.idea/deploymentTargetDropDown.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,66 @@ android {
3232
kotlinOptions {
3333
jvmTarget = "1.8"
3434
}
35+
composeOptions {
36+
kotlinCompilerExtensionVersion "1.4.6"
37+
}
3538
buildFeatures {
3639
viewBinding true
40+
compose true
3741
}
3842
sourceSets {
3943
main {
4044
res {
41-
srcDirs 'src/main/res','src/main/res/layout/chats', 'src/main/res/layout/core'
45+
srcDirs 'src/main/res','src/main/res/layout/chats', 'src/main/res/layout/core', 'src/main/res/gallery', 'src/main/res/layout/gallery'
4246
}
4347
}
4448
}
4549
}
4650

4751
dependencies {
52+
def composeBom = platform('androidx.compose:compose-bom:2023.05.01')
53+
implementation composeBom
54+
androidTestImplementation composeBom
55+
56+
// Choose one of the following:
57+
// Material Design 3
58+
implementation 'androidx.compose.material3:material3'
59+
// or Material Design 2
60+
implementation 'androidx.compose.material:material'
61+
// or skip Material Design and build directly on top of foundational components
62+
implementation 'androidx.compose.foundation:foundation'
63+
// or only import the main APIs for the underlying toolkit systems,
64+
// such as input and measurement/layout
65+
implementation 'androidx.compose.ui:ui'
66+
67+
// Android Studio Preview support
68+
implementation 'androidx.compose.ui:ui-tooling-preview'
69+
debugImplementation 'androidx.compose.ui:ui-tooling'
70+
71+
// UI Tests
72+
androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
73+
debugImplementation 'androidx.compose.ui:ui-test-manifest'
74+
75+
// Optional - Included automatically by material, only add when you need
76+
// the icons but not the material library (e.g. when using Material3 or a
77+
// custom design system based on Foundation)
78+
implementation 'androidx.compose.material:material-icons-core'
79+
// Optional - Add full set of material icons
80+
implementation 'androidx.compose.material:material-icons-extended'
81+
// Optional - Add window size utils
82+
implementation 'androidx.compose.material3:material3-window-size-class'
83+
84+
// Optional - Integration with activities
85+
implementation 'androidx.activity:activity-compose:1.7.2'
86+
// Optional - Integration with ViewModels
87+
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.6.1'
88+
// Optional - Integration with LiveData
89+
implementation 'androidx.compose.runtime:runtime-livedata'
90+
// Optional - Integration with RxJava
91+
implementation 'androidx.compose.runtime:runtime-rxjava2'
92+
93+
implementation "com.github.bumptech.glide:compose:1.0.0-alpha.1"
94+
4895
implementation "com.android.support:multidex:1.0.3"
4996
implementation "androidx.core:core-ktx:1.10.1"
5097
implementation "androidx.appcompat:appcompat:1.6.1"

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

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

3+
import android.app.Activity
34
import android.app.NotificationChannel
45
import android.app.NotificationManager
56
import android.content.Intent
@@ -12,6 +13,7 @@ import androidx.navigation.findNavController
1213
import androidx.navigation.ui.AppBarConfiguration
1314
import androidx.navigation.ui.setupActionBarWithNavController
1415
import androidx.navigation.ui.setupWithNavController
16+
import com.troplo.privateuploader.api.SessionManager
1517
import com.troplo.privateuploader.api.SocketHandler
1618
import com.troplo.privateuploader.api.TpuApi
1719
import com.troplo.privateuploader.api.TpuConfig
@@ -24,24 +26,22 @@ class MainActivity : AppCompatActivity() {
2426
private lateinit var binding: ActivityMainBinding
2527

2628
override fun onCreate(savedInstanceState: Bundle?) {
27-
val sharedPref : SharedPreferences = applicationContext.getSharedPreferences("TpuConfig", MODE_PRIVATE)
28-
val config = TpuConfig(sharedPref)
29-
30-
// run getUser to check if user is logged in
31-
if(config.token != null) {
32-
TpuApi.retrofitService.getUser(config.token!!).enqueue(object : retrofit2.Callback<User> {
29+
val token = SessionManager(this).fetchAuthToken()
30+
var user: User? = null
31+
if(token != null) {
32+
TpuApi.retrofitService.getUser(token).enqueue(object : retrofit2.Callback<User> {
3333
override fun onResponse(call: retrofit2.Call<User>, response: retrofit2.Response<User>) {
3434
if (response.body()?.username != null) {
35-
println("com.troplo.privateuploader.data.model.User is logged in")
36-
setContentView(R.layout.activity_main)
35+
println("User is logged in")
36+
user = response.body()!!
3737
} else {
38-
println("com.troplo.privateuploader.data.model.User is not logged in")
38+
println("User is not logged in")
3939
val intent = Intent(this@MainActivity, LoginActivity::class.java)
4040
startActivity(intent)
4141
}
4242
}
4343
override fun onFailure(call: retrofit2.Call<User>, t: Throwable) {
44-
println("com.troplo.privateuploader.data.model.User is not logged in")
44+
println("User is not logged in")
4545
val intent = Intent(this@MainActivity, LoginActivity::class.java)
4646
startActivity(intent)
4747
}
@@ -51,7 +51,7 @@ class MainActivity : AppCompatActivity() {
5151
startActivity(intent)
5252
}
5353

54-
SocketHandler.setSocket(config.token)
54+
SocketHandler.setSocket(token)
5555
SocketHandler.establishConnection()
5656
val tpuSocket = SocketHandler.getSocket()
5757
println(tpuSocket.connected())
@@ -93,6 +93,10 @@ class MainActivity : AppCompatActivity() {
9393
R.id.navigation_home, R.id.navigation_gallery, R.id.navigation_collections, R.id.navigation_settings))
9494
setupActionBarWithNavController(navController, appBarConfiguration)
9595
navView.setupWithNavController(navController)
96+
// set navigation_settings to user profile picture
97+
if(user != null) {
98+
// set the
99+
}
96100
}
97101

98102
}

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

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

33
import com.troplo.privateuploader.data.model.Chat
4+
import com.troplo.privateuploader.data.model.Gallery
45
import com.troplo.privateuploader.data.model.LoginRequest
56
import com.troplo.privateuploader.data.model.LoginResponse
67
import com.troplo.privateuploader.data.model.User
@@ -13,6 +14,7 @@ import retrofit2.http.Body
1314
import retrofit2.http.GET
1415
import retrofit2.http.Header
1516
import retrofit2.http.POST
17+
import retrofit2.http.Query
1618

1719
private const val BASE_URL = "http://192.168.0.12:34582/api/v3/"
1820
val client = OkHttpClient.Builder()
@@ -43,6 +45,16 @@ interface TpuApiService {
4345
fun getUser(
4446
@Header("Authorization") token: String
4547
): Call<User>
48+
49+
@GET("gallery")
50+
fun getGallery(
51+
@Header("Authorization") token: String,
52+
@Query("page") page: Int = 1,
53+
@Query("search") search: String = "",
54+
@Query("textMetadata") textMetadata: Boolean = true,
55+
@Query("filter") filter: String = "all",
56+
@Query("sort") sort: String = "\"newest\""
57+
): Call<Gallery>
4658
}
4759

4860
object TpuApi {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.troplo.privateuploader.data.model
2+
3+
import com.squareup.moshi.Json
4+
import com.squareup.moshi.JsonClass
5+
6+
@JsonClass(generateAdapter = true)
7+
data class Collection (
8+
@Json(name = "id") val id: Int,
9+
@Json(name = "name") val name: String,
10+
@Json(name = "CollectionItem") val collectionItem: CollectionItem
11+
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.troplo.privateuploader.data.model
2+
3+
import com.squareup.moshi.Json
4+
import com.squareup.moshi.JsonClass
5+
6+
@JsonClass(generateAdapter = true)
7+
data class CollectionItem(
8+
@Json(name = "id") val id: Int,
9+
@Json(name = "collectionId") val collectionId: Int,
10+
@Json(name = "attachmentId") val attachmentId: Int,
11+
@Json(name = "userId") val userId: Int,
12+
@Json(name = "identifier") val identifier: String,
13+
@Json(name = "pinned") val pinned: Boolean,
14+
@Json(name = "createdAt") val createdAt: String,
15+
@Json(name = "updatedAt") val updatedAt: String
16+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.troplo.privateuploader.data.model
2+
3+
import com.squareup.moshi.Json
4+
import com.squareup.moshi.JsonClass
5+
6+
@JsonClass(generateAdapter = true)
7+
data class Gallery(
8+
@field:Json(name = "gallery") val gallery: List<Upload>,
9+
@field:Json(name = "pager") val pager: Pager
10+
)
11+
12+
@JsonClass(generateAdapter = true)
13+
data class Pager(
14+
@field:Json(name = "page") val page: Int,
15+
@field:Json(name = "total") val total: Int,
16+
@field:Json(name = "limit") val limit: Int
17+
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.troplo.privateuploader.data.model
2+
3+
import com.squareup.moshi.Json
4+
import com.squareup.moshi.JsonClass
5+
6+
@JsonClass(generateAdapter = true)
7+
data class Upload(
8+
@Json(name = "id") val id: Int,
9+
@Json(name = "attachment") val attachment: String,
10+
@Json(name = "userId") val userId: Int,
11+
@Json(name = "name") val name: String,
12+
@Json(name = "originalFilename") val originalFilename: String,
13+
@Json(name = "type") val type: String,
14+
@Json(name = "urlRedirect") val urlRedirect: String?,
15+
@Json(name = "fileSize") val fileSize: Int,
16+
@Json(name = "deletable") val deletable: Boolean,
17+
@Json(name = "data") val data: Any?,
18+
@Json(name = "textMetadata") val textMetadata: String,
19+
@Json(name = "createdAt") val createdAt: String,
20+
@Json(name = "updatedAt") val updatedAt: String,
21+
@Json(name = "starred") val starred: Any?,
22+
@Json(name = "collections") val collections: List<Collection>,
23+
@Json(name = "user") val user: User
24+
)

0 commit comments

Comments
 (0)