-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started the migration of the image optimizer to compose
- Loading branch information
1 parent
6002ccd
commit 20fdd91
Showing
11 changed files
with
176 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 0 additions & 68 deletions
68
app/src/main/kotlin/com/d4rk/cleaner/ui/imageoptimizer/ImagePickerActivity.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ner/ui/imageoptimizer/FileSizeFragment.kt → ...r/imageoptimizer/tabs/FileSizeFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...r/ui/imageoptimizer/ManualModeFragment.kt → ...imageoptimizer/tabs/ManualModeFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...i/imageoptimizer/QuickCompressFragment.kt → ...geoptimizer/tabs/QuickCompressFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
app/src/main/kotlin/com/d4rk/cleaner/ui/imageoptimizer/imagepicker/ImagePickerActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.d4rk.cleaner.ui.imageoptimizer.imagepicker | ||
|
||
import android.app.Activity | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.activity.compose.setContent | ||
import androidx.activity.enableEdgeToEdge | ||
import androidx.activity.result.contract.ActivityResultContracts | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.ui.Modifier | ||
import androidx.lifecycle.ViewModelProvider | ||
import com.d4rk.cleaner.R | ||
import com.d4rk.cleaner.ui.settings.display.theme.style.AppTheme | ||
|
||
class ImagePickerActivity : AppCompatActivity() { | ||
private lateinit var viewModel: ImagePickerViewModel | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
viewModel = ViewModelProvider(this)[ImagePickerViewModel::class.java] | ||
|
||
enableEdgeToEdge() | ||
setContent { | ||
AppTheme { | ||
Surface( | ||
modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background | ||
) { | ||
ImagePickerComposable(this, viewModel) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private val launcher = | ||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> | ||
if (result.resultCode == Activity.RESULT_OK && result.data != null) { | ||
val selectedImageUri = result.data?.data | ||
viewModel.setSelectedImageUri(selectedImageUri) | ||
} | ||
} | ||
|
||
fun selectImage() { | ||
val intent = Intent(Intent.ACTION_PICK) | ||
intent.type = "image/*" | ||
val chooser = Intent.createChooser(intent, getString(R.string.select_image)) | ||
launcher.launch(chooser) | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
app/src/main/kotlin/com/d4rk/cleaner/ui/imageoptimizer/imagepicker/ImagePickerComposable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.d4rk.cleaner.ui.imageoptimizer.imagepicker | ||
|
||
import android.content.Intent | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.automirrored.filled.ArrowBack | ||
import androidx.compose.material.icons.outlined.ImageSearch | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.ExtendedFloatingActionButton | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.material3.LargeTopAppBar | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TopAppBarDefaults | ||
import androidx.compose.material3.rememberTopAppBarState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.input.nestedscroll.nestedScroll | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import androidx.constraintlayout.compose.ConstraintLayout | ||
import com.d4rk.cleaner.R | ||
import com.d4rk.cleaner.ads.BannerAdsComposable | ||
import com.d4rk.cleaner.data.datastore.DataStore | ||
import com.d4rk.cleaner.ui.imageoptimizer.imageoptimizer.ImageOptimizerActivity | ||
import com.d4rk.cleaner.utils.compose.bounceClick | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun ImagePickerComposable( | ||
activity: ImagePickerActivity, | ||
viewModel: ImagePickerViewModel | ||
) { | ||
val context = LocalContext.current | ||
val dataStore = DataStore.getInstance(context) | ||
val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior(rememberTopAppBarState()) | ||
Scaffold(modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), topBar = { | ||
LargeTopAppBar( | ||
title = { Text(stringResource(R.string.image_optimizer)) }, | ||
navigationIcon = { | ||
IconButton(onClick = { | ||
activity.finish() | ||
}) { | ||
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = null) | ||
} | ||
}, | ||
scrollBehavior = scrollBehavior | ||
) | ||
}) { paddingValues -> | ||
ConstraintLayout( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(paddingValues) | ||
) { | ||
val (fab, adView) = createRefs() | ||
|
||
ExtendedFloatingActionButton( | ||
modifier = Modifier | ||
.padding(16.dp) | ||
.bounceClick() | ||
.constrainAs(fab) { | ||
end.linkTo(parent.end) | ||
bottom.linkTo(adView.top) | ||
}, | ||
text = { Text(stringResource(R.string.choose_image)) }, | ||
onClick = { | ||
activity.selectImage() | ||
}, | ||
icon = { | ||
Icon( | ||
Icons.Outlined.ImageSearch, contentDescription = null | ||
) | ||
} | ||
) | ||
|
||
BannerAdsComposable( | ||
modifier = Modifier | ||
.constrainAs(adView) { | ||
bottom.linkTo(parent.bottom) | ||
start.linkTo(parent.start) | ||
end.linkTo(parent.end) | ||
}, | ||
dataStore = dataStore | ||
) | ||
} | ||
} | ||
|
||
viewModel.selectedImageUri?.let { uri -> | ||
val intent = Intent(context, ImageOptimizerActivity::class.java) | ||
intent.putExtra("imageUri", uri.toString()) | ||
activity.startActivity(intent) | ||
viewModel.setSelectedImageUri(null) | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/kotlin/com/d4rk/cleaner/ui/imageoptimizer/imagepicker/ImagePickerViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.d4rk.cleaner.ui.imageoptimizer.imagepicker | ||
|
||
import android.net.Uri | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.lifecycle.ViewModel | ||
|
||
class ImagePickerViewModel : ViewModel() { | ||
private val _selectedImageUri = mutableStateOf<Uri?>(null) | ||
val selectedImageUri: Uri? get() = _selectedImageUri.value | ||
|
||
fun setSelectedImageUri(uri: Uri?) { | ||
_selectedImageUri.value = uri | ||
} | ||
} |