1
+ package com.record.upload
2
+
3
+ import android.content.ContentUris
4
+ import android.content.Context
5
+ import android.database.Cursor
6
+ import android.net.Uri
7
+ import android.provider.MediaStore
8
+ import android.util.Log
9
+ import androidx.compose.foundation.background
10
+ import androidx.compose.foundation.layout.Box
11
+ import androidx.compose.foundation.layout.Column
12
+ import androidx.compose.foundation.layout.PaddingValues
13
+ import androidx.compose.foundation.layout.fillMaxSize
14
+ import androidx.compose.foundation.layout.fillMaxWidth
15
+ import androidx.compose.material3.Text
16
+ import androidx.compose.runtime.Composable
17
+ import androidx.compose.ui.Alignment
18
+ import androidx.compose.ui.Modifier
19
+ import androidx.compose.ui.platform.LocalContext
20
+ import androidx.compose.ui.text.intl.Locale
21
+ import androidx.compose.ui.text.style.TextAlign
22
+ import androidx.compose.ui.tooling.preview.Preview
23
+ import com.record.designsystem.component.button.RecordyButton
24
+ import com.record.designsystem.component.navbar.TopNavigationBar
25
+ import com.record.designsystem.theme.Background
26
+ import com.record.designsystem.theme.Gray03
27
+ import com.record.designsystem.theme.RecordyTheme
28
+
29
+ @Composable
30
+ fun SelectedVideoRoute (
31
+ paddingValues : PaddingValues ,
32
+ navigateDefinedContent : () -> Unit ,
33
+ ) {
34
+ SelectedVideoScreen (navigateDefinedContent = navigateDefinedContent)
35
+ }
36
+
37
+ @Composable
38
+ fun SelectedVideoScreen (
39
+ navigateDefinedContent : () -> Unit ,
40
+ ) { Log .d(" images" ," ${getAllVideos(10 , null , LocalContext .current)} " )
41
+ Box (
42
+ modifier = Modifier
43
+ .fillMaxSize()
44
+ .background(Background ),
45
+ ) {
46
+ Column (
47
+ modifier = Modifier
48
+ .align(Alignment .TopCenter ),
49
+ ) {
50
+ TopNavigationBar (title = " 영상 선택" , enableGradation = true )
51
+ Text (
52
+ text = " ⓘ 1080p 이하의 최대 15초 영상을 올려주세요." ,
53
+ color = Gray03 ,
54
+ style = RecordyTheme .typography.caption2,
55
+ maxLines = 1 ,
56
+ modifier = Modifier .fillMaxWidth(),
57
+ textAlign = TextAlign .Center ,
58
+ )
59
+ }
60
+ RecordyButton (
61
+ modifier = Modifier .align(Alignment .BottomCenter ),
62
+ text = " 다음" ,
63
+ enabled = true ,
64
+ onClick = {},
65
+ )
66
+ }
67
+
68
+ }
69
+ @Preview
70
+ @Composable
71
+ fun SelectedVideoScreenPreview () {
72
+ RecordyTheme {
73
+ VideoPickerScreen (navigateSelectedVideo = { /* TODO*/ })
74
+ }
75
+ }
76
+
77
+ fun getAllVideos (
78
+ loadSize : Int ,
79
+ currentLocation : String? ,
80
+ context : Context
81
+ ): MutableList <GalleryVideo > {
82
+ val galleryVideoList = mutableListOf<GalleryVideo >()
83
+ // 외장 메모리에 있는 비디오 파일의 URI를 받도록 함
84
+ val uriExternal: Uri = MediaStore .Video .Media .EXTERNAL_CONTENT_URI
85
+ // 커서에 가져올 정보에 대해서 지정한다.
86
+ val projection = arrayOf(
87
+ MediaStore .Video .VideoColumns .DATA ,
88
+ MediaStore .Video .VideoColumns .DISPLAY_NAME , // 이름
89
+ MediaStore .Video .VideoColumns .SIZE , // 크기
90
+ MediaStore .Video .VideoColumns .DATE_TAKEN ,
91
+ MediaStore .Video .VideoColumns .DATE_ADDED , // 추가된 날짜
92
+ MediaStore .Video .VideoColumns ._ID
93
+ )
94
+ val resolver = context.contentResolver
95
+
96
+ var selection: String? = null
97
+ var selectionArgs: Array <String >? = null
98
+
99
+ val query = resolver.query(
100
+ uriExternal,
101
+ projection,
102
+ selection,
103
+ selectionArgs,
104
+ " ${MediaStore .Video .VideoColumns .DATE_ADDED } DESC"
105
+ )
106
+
107
+ query?.use { cursor ->
108
+ Log .d(" gallery cursor" , " Cursor count: ${cursor.count} ." )
109
+
110
+ if (cursor.moveToFirst()) {
111
+ val idColumn = cursor.getColumnIndexOrThrow(MediaStore .Video .VideoColumns ._ID )
112
+ val nameColumn = cursor.getColumnIndexOrThrow(MediaStore .Video .VideoColumns .DISPLAY_NAME )
113
+ val filePathColumn = cursor.getColumnIndexOrThrow(MediaStore .Video .VideoColumns .DATA )
114
+ val sizeColumn = cursor.getColumnIndexOrThrow(MediaStore .Video .VideoColumns .SIZE )
115
+ val dateColumn = cursor.getColumnIndexOrThrow(MediaStore .Video .VideoColumns .DATE_TAKEN )
116
+
117
+ do {
118
+ val id = cursor.getLong(idColumn)
119
+ val filepath = cursor.getString(filePathColumn)
120
+ val name = cursor.getString(nameColumn)
121
+ val size = cursor.getInt(sizeColumn)
122
+ val date = cursor.getString(dateColumn)
123
+
124
+ val contentUri = ContentUris .withAppendedId(uriExternal, id)
125
+ Log .d(" gallery contentUri" , " $contentUri " )
126
+ galleryVideoList.add(
127
+ GalleryVideo (
128
+ id,
129
+ filepath = filepath,
130
+ uri = contentUri,
131
+ name = name,
132
+ date = date ? : " " ,
133
+ size = size
134
+ )
135
+ )
136
+ } while (cursor.moveToNext())
137
+ }
138
+ }
139
+
140
+ return galleryVideoList
141
+ }
142
+
143
+ data class GalleryVideo (
144
+ val id : Long ,
145
+ val filepath : String ,
146
+ val uri : Uri ,
147
+ val name : String ,
148
+ val date : String ,
149
+ val size : Int
150
+ )
0 commit comments