-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat]: moved apps chooser to another module and refactored to compose
- Loading branch information
Showing
30 changed files
with
585 additions
and
380 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
49 changes: 49 additions & 0 deletions
49
app/src/main/kotlin/com/f0x1d/logfox/coil/AppIconFetcher.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,49 @@ | ||
package com.f0x1d.logfox.coil | ||
|
||
import android.content.Context | ||
import coil.ImageLoader | ||
import coil.decode.DataSource | ||
import coil.fetch.DrawableResult | ||
import coil.fetch.FetchResult | ||
import coil.fetch.Fetcher | ||
import coil.request.Options | ||
import com.f0x1d.logfox.arch.di.IODispatcher | ||
import com.f0x1d.logfox.model.InstalledApp | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.withContext | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
class AppIconFetcher( | ||
private val context: Context, | ||
private val app: InstalledApp, | ||
private val ioDispatcher: CoroutineDispatcher, | ||
) : Fetcher { | ||
|
||
override suspend fun fetch(): FetchResult = withContext(ioDispatcher) { | ||
val appDrawable = context.packageManager.getApplicationIcon(app.packageName) | ||
|
||
DrawableResult( | ||
drawable = appDrawable, | ||
isSampled = true, | ||
dataSource = DataSource.DISK, | ||
) | ||
} | ||
|
||
@Singleton | ||
class Factory @Inject constructor( | ||
@ApplicationContext private val context: Context, | ||
@IODispatcher private val ioDispatcher: CoroutineDispatcher, | ||
) : Fetcher.Factory<InstalledApp> { | ||
override fun create( | ||
data: InstalledApp, | ||
options: Options, | ||
imageLoader: ImageLoader, | ||
): Fetcher = AppIconFetcher( | ||
context = context, | ||
app = data, | ||
ioDispatcher = ioDispatcher, | ||
) | ||
} | ||
} |
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,27 @@ | ||
package com.f0x1d.logfox.di | ||
|
||
import android.content.Context | ||
import coil.ImageLoader | ||
import com.f0x1d.logfox.coil.AppIconFetcher | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object CoilModule { | ||
|
||
@Provides | ||
@Singleton | ||
fun provideImageLoader( | ||
@ApplicationContext context: Context, | ||
appIconFetcherFactory: AppIconFetcher.Factory, | ||
): ImageLoader = ImageLoader.Builder(context) | ||
.components { | ||
add(appIconFetcherFactory) | ||
} | ||
.build() | ||
} |
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
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
32 changes: 32 additions & 0 deletions
32
...pose/src/main/kotlin/com/f0x1d/logfox/ui/compose/component/button/NavigationBackButton.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,32 @@ | ||
package com.f0x1d.logfox.ui.compose.component.button | ||
|
||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.painterResource | ||
import com.f0x1d.logfox.ui.Icons | ||
import com.f0x1d.logfox.ui.compose.preview.DayNightPreview | ||
import com.f0x1d.logfox.ui.compose.theme.LogFoxTheme | ||
|
||
@Composable | ||
fun NavigationBackButton( | ||
onClick: () -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
IconButton( | ||
modifier = modifier, | ||
onClick = onClick, | ||
) { | ||
Icon( | ||
painter = painterResource(id = Icons.ic_arrow_back), | ||
contentDescription = null, | ||
) | ||
} | ||
} | ||
|
||
@DayNightPreview | ||
@Composable | ||
private fun Preview() = LogFoxTheme { | ||
NavigationBackButton(onClick = { }) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
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,9 @@ | ||
plugins { | ||
id("logfox.android.feature.compose") | ||
} | ||
|
||
android.namespace = "com.f0x1d.logfox.feature.apps.picker" | ||
|
||
dependencies { | ||
implementation(libs.coil.compose) | ||
} |
49 changes: 49 additions & 0 deletions
49
...main/kotlin/com/f0x1d/logfox/feature/apps/picker/ui/fragment/picker/AppsPickerFragment.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,49 @@ | ||
package com.f0x1d.logfox.feature.apps.picker.ui.fragment.picker | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.fragment.app.viewModels | ||
import androidx.navigation.fragment.findNavController | ||
import com.f0x1d.logfox.arch.ui.fragment.compose.BaseComposeViewModelFragment | ||
import com.f0x1d.logfox.feature.apps.picker.ui.fragment.picker.compose.AppsPickerScreenContent | ||
import com.f0x1d.logfox.feature.apps.picker.ui.fragment.picker.compose.AppsPickerScreenListener | ||
import com.f0x1d.logfox.feature.apps.picker.viewmodel.AppsPickerViewModel | ||
import com.f0x1d.logfox.feature.apps.picker.viewmodel.resultHandler | ||
import com.f0x1d.logfox.ui.compose.theme.LogFoxTheme | ||
import dagger.hilt.android.AndroidEntryPoint | ||
|
||
@AndroidEntryPoint | ||
class AppsPickerFragment: BaseComposeViewModelFragment<AppsPickerViewModel>() { | ||
|
||
override val viewModel by viewModels<AppsPickerViewModel>() | ||
|
||
private val resultHandler by resultHandler() | ||
|
||
private val listener by lazy { | ||
AppsPickerScreenListener( | ||
onBackClicked = { | ||
viewModel.performBackAction(findNavController()::popBackStack) | ||
}, | ||
onAppClicked = { | ||
if (resultHandler?.onAppSelected(it) == true) { | ||
findNavController().popBackStack() | ||
} | ||
}, | ||
onSearchActiveChanged = viewModel::changeSearchActive, | ||
onQueryChanged = viewModel::updateQuery, | ||
) | ||
} | ||
|
||
@Composable | ||
override fun Content() { | ||
LogFoxTheme { | ||
val state by viewModel.uiState.collectAsState() | ||
|
||
AppsPickerScreenContent( | ||
state = state, | ||
listener = listener, | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.