Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
TeamPrinterV2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Aleksandr
TeamPrinterV2
Commits
09ddf787
Commit
09ddf787
authored
Jun 28, 2024
by
Aleksandr Tamakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Request notification permission
parent
d88818dd
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
56 additions
and
14 deletions
+56
-14
app/src/main/AndroidManifest.xml
+1
-0
app/src/main/java/com/isidroid/c23/domain/use_case/ContentUseCase.kt
+14
-2
app/src/main/java/com/isidroid/c23/ext/ExtFunc.kt
+13
-2
app/src/main/java/com/isidroid/c23/ui/_component/TopAppBarComponent.kt
+1
-1
app/src/main/java/com/isidroid/c23/ui/screen/content/ContentContract.kt
+9
-6
app/src/main/java/com/isidroid/c23/ui/screen/content/ContentScreen.kt
+9
-0
app/src/main/java/com/isidroid/c23/ui/screen/content/ContentViewModel.kt
+6
-2
feature/job_sender/src/main/java/com/isidroid/job_sender/repository/JobSendRepositoryImpl.kt
+3
-1
No files found.
app/src/main/AndroidManifest.xml
View file @
09ddf787
...
...
@@ -7,6 +7,7 @@
android:required=
"false"
/>
<uses-permission
android:name=
"android.permission.CAMERA"
/>
<uses-permission
android:name=
"android.permission.POST_NOTIFICATIONS"
/>
<uses-permission
android:name=
"android.permission.ACCESS_FINE_LOCATION"
/>
<uses-permission
android:name=
"android.permission.ACCESS_COARSE_LOCATION"
/>
...
...
app/src/main/java/com/isidroid/c23/domain/use_case/ContentUseCase.kt
View file @
09ddf787
package
com.isidroid.c23.domain.use_case
import
android.content.Context
import
androidx.core.app.ActivityCompat
import
com.isidroid.c23.ext.hasNotificationPermission
import
com.isidroid.spot.model.RichSpot
import
com.isidroid.spot.repository.ActiveSpotRepository
import
dagger.hilt.android.qualifiers.ApplicationContext
import
kotlinx.coroutines.flow.flow
import
timber.log.Timber
import
javax.inject.Inject
import
javax.inject.Singleton
@Singleton
class
ContentUseCase
@Inject
constructor
(
private
val
activeSpotRepository
:
ActiveSpotRepository
)
{
class
ContentUseCase
@Inject
constructor
(
@ApplicationContext
private
val
context
:
Context
,
private
val
activeSpotRepository
:
ActiveSpotRepository
)
{
fun
create
()
=
flow
{
val
spot
=
activeSpotRepository
.
getDefaultSpot
()
emit
(
spot
)
val
hasNotificationPermission
=
context
.
hasNotificationPermission
.
takeIf
{
spot
!=
null
}
emit
(
Pair
(
spot
,
hasNotificationPermission
))
}
}
\ No newline at end of file
app/src/main/java/com/isidroid/c23/ext/ExtFunc.kt
View file @
09ddf787
package
com.isidroid.c23.ext
import
android.Manifest
import
android.content.Context
import
android.content.pm.PackageManager
import
android.os.Build
import
androidx.compose.ui.graphics.Color
import
androidx.core.content.ContextCompat
import
com.isidroid.c23.BuildConfig
import
com.isidroid.c23.constant.AppBuildType
import
com.isidroid.c23.data.source.settings.Settings
...
...
@@ -20,4 +25,10 @@ fun randomColor(): Color {
blue
=
random
.
nextFloat
(),
alpha
=
1.0f
)
}
\ No newline at end of file
}
val
Context
.
hasNotificationPermission
:
Boolean
get
()
{
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
TIRAMISU
)
return
true
return
ContextCompat
.
checkSelfPermission
(
this
,
Manifest
.
permission
.
POST_NOTIFICATIONS
)
==
PackageManager
.
PERMISSION_GRANTED
}
\ No newline at end of file
app/src/main/java/com/isidroid/c23/ui/_component/TopAppBarComponent.kt
View file @
09ddf787
...
...
@@ -30,7 +30,7 @@ internal fun TopAppBarComponent(
)
{
CenterAlignedTopAppBar
(
actions
=
actions
,
modifier
=
modifier
.
height
(
64
.
dp
)
,
modifier
=
modifier
,
title
=
{
Text
(
text
=
text
,
...
...
app/src/main/java/com/isidroid/c23/ui/screen/content/ContentContract.kt
View file @
09ddf787
...
...
@@ -11,24 +11,26 @@ class ContentContract {
data class
PickContent
(
val
photo
:
Boolean
=
false
,
val
documents
:
Boolean
=
false
,
val
word
:
Boolean
=
false
)
:
Event
data class
MultipleContents
(
val
uris
:
List
<
Uri
>)
:
Event
data class
OpenMap
(
val
lat
:
Double
?
=
null
,
val
lng
:
Double
?
=
null
,
val
spotCode
:
String
?
=
null
)
:
Event
data
object
GoBack
:
Event
data
object
ToPrintJobList
:
Event
data
object
GoBack
:
Event
data
object
ToPrintJobList
:
Event
data
object
CheckNotificationPermission
:
Event
}
sealed
interface
Effect
:
ViewSideEffect
{
sealed
interface
Navigation
:
Effect
{
data class
ToRenderPreview
(
val
uris
:
String
)
:
Navigation
data class
ToMap
(
val
lat
:
Double
?
=
null
,
val
lng
:
Double
?
=
null
,
val
spotId
:
String
?
=
null
)
:
Navigation
data
object
ToBack
:
Navigation
data
object
ToPrintJobList
:
Navigation
data
object
ToBack
:
Navigation
data
object
ToPrintJobList
:
Navigation
}
}
data class
State
(
val
hasNotificationPermission
:
Boolean
?
=
null
,
val
galleryHash
:
String
?
=
null
,
val
documentHash
:
String
?
=
null
,
val
wordHash
:
String
?
=
null
,
val
richSpot
:
RichSpot
?
=
null
val
richSpot
:
RichSpot
?
=
null
,
)
:
ViewState
)
:
ViewState
}
\ No newline at end of file
app/src/main/java/com/isidroid/c23/ui/screen/content/ContentScreen.kt
View file @
09ddf787
package
com.isidroid.c23.ui.screen.content
import
android.Manifest
import
android.os.Build
import
androidx.activity.compose.BackHandler
import
androidx.activity.compose.ManagedActivityResultLauncher
import
androidx.activity.compose.rememberLauncherForActivityResult
import
androidx.activity.result.contract.ActivityResultContracts
import
androidx.compose.foundation.Image
...
...
@@ -43,6 +46,7 @@ import com.isidroid.c23.ui._component.ShortOfficeInfoComponent
import
com.isidroid.c23.ui._component.TopAppBarComponent
import
com.isidroid.core.vm.SIDE_EFFECTS_KEY
import
kotlinx.coroutines.flow.Flow
import
timber.log.Timber
@OptIn
(
ExperimentalMaterial3Api
::
class
)
@Composable
...
...
@@ -57,6 +61,10 @@ fun ContentScreen(
onEventSent
(
ContentContract
.
Event
.
MultipleContents
(
uris
))
}
val
notificationLauncher
=
rememberLauncherForActivityResult
(
ActivityResultContracts
.
RequestPermission
())
{
onEventSent
(
ContentContract
.
Event
.
CheckNotificationPermission
)
}
BackHandler
{
onEventSent
(
ContentContract
.
Event
.
GoBack
)
}
...
...
@@ -64,6 +72,7 @@ fun ContentScreen(
LaunchedEffect
(
state
.
value
.
galleryHash
)
{
if
(
state
.
value
.
galleryHash
!=
null
)
launcher
.
launch
(
"image/*"
)
}
LaunchedEffect
(
state
.
value
.
documentHash
)
{
if
(
state
.
value
.
documentHash
!=
null
)
launcher
.
launch
(
"application/pdf"
)
}
LaunchedEffect
(
state
.
value
.
wordHash
)
{
if
(
state
.
value
.
wordHash
!=
null
)
launcher
.
launch
(
"application/msword"
)
}
LaunchedEffect
(
"not_perm_${state.value.hasNotificationPermission}"
)
{
if
(
state
.
value
.
hasNotificationPermission
==
false
)
notificationLauncher
.
launch
(
Manifest
.
permission
.
POST_NOTIFICATIONS
)
}
LaunchedEffect
(
SIDE_EFFECTS_KEY
)
{
...
...
app/src/main/java/com/isidroid/c23/ui/screen/content/ContentViewModel.kt
View file @
09ddf787
...
...
@@ -37,6 +37,7 @@ class ContentViewModel @Inject constructor(
is
ContentContract
.
Event
.
OpenMap
->
setEffect
{
ContentContract
.
Effect
.
Navigation
.
ToMap
(
event
.
lat
,
event
.
lng
,
event
.
spotCode
)
}
ContentContract
.
Event
.
GoBack
->
setEffect
{
ContentContract
.
Effect
.
Navigation
.
ToBack
}
ContentContract
.
Event
.
ToPrintJobList
->
setEffect
{
ContentContract
.
Effect
.
Navigation
.
ToPrintJobList
}
ContentContract
.
Event
.
CheckNotificationPermission
->
setState
{
copy
(
hasNotificationPermission
=
null
)
}
}
}
...
...
@@ -49,11 +50,13 @@ class ContentViewModel @Inject constructor(
}
private
suspend
fun
create
()
{
useCase
.
create
().
flowOn
(
Dispatchers
.
IO
).
collect
{
data
->
useCase
.
create
().
flowOn
(
Dispatchers
.
IO
).
collect
{
val
(
data
,
hasPermission
)
=
it
if
(
data
==
null
)
setEffect
{
ContentContract
.
Effect
.
Navigation
.
ToMap
()
}
else
setState
{
copy
(
richSpot
=
data
)
}
setState
{
copy
(
richSpot
=
data
,
hasNotificationPermission
=
hasPermission
)
}
}
}
}
\ No newline at end of file
feature/job_sender/src/main/java/com/isidroid/job_sender/repository/JobSendRepositoryImpl.kt
View file @
09ddf787
...
...
@@ -12,6 +12,7 @@ import com.isidroid.job_sender.ext.createRenderItems
import
com.isidroid.job_sender.ext.decreaseCounter
import
com.isidroid.rendering.repository.RenderRepository
import
com.isidroid.spot.repository.SpotRepository
import
kotlinx.coroutines.delay
import
timber.log.Timber
internal
class
JobSendRepositoryImpl
(
...
...
@@ -57,6 +58,8 @@ internal class JobSendRepositoryImpl(
for
((
index
,
item
)
in
items
.
withIndex
())
{
eventCollector
.
updateProgress
(
index
,
total
)
delay
(
10
_000
)
try
{
val
uploadResult
=
sendJobNetworkSource
.
uploadPage
(
jobId
=
item
.
printJobId
,
token
=
item
.
accessToken
,
filePath
=
item
.
sourceFile
)
if
(!
uploadResult
)
...
...
@@ -80,7 +83,6 @@ internal class JobSendRepositoryImpl(
printJobRepository
.
updateJobStatus
(
status
=
JobStatus
.
UPLOAD_ERROR
,
*
failedJobIds
.
toTypedArray
())
val
successJobs
=
printJobRepository
.
readLocalList
(
ids
=
successJobIds
.
toList
())
println
(
"failedJobIds=$failedJobIds"
)
val
failedJobs
=
printJobRepository
.
readLocalList
(
ids
=
failedJobIds
.
toList
())
// notify event emitters
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment