-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the new compose screen with its components and events
- Loading branch information
1 parent
2eb85bd
commit c3aa4e7
Showing
33 changed files
with
1,523 additions
and
6 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
27 changes: 27 additions & 0 deletions
27
app/src/main/java/org/schabi/newpipe/dependency_injection/AppModule.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,27 @@ | ||
package org.schabi.newpipe.dependency_injection | ||
|
||
import android.content.Context | ||
import android.content.SharedPreferences | ||
import androidx.preference.PreferenceManager | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import org.schabi.newpipe.error.usecases.OpenErrorActivity | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object AppModule { | ||
@Provides | ||
@Singleton | ||
fun provideSharedPreferences(@ApplicationContext context: Context): SharedPreferences = | ||
PreferenceManager.getDefaultSharedPreferences(context) | ||
|
||
@Provides | ||
@Singleton | ||
fun provideOpenActivity( | ||
@ApplicationContext context: Context, | ||
): OpenErrorActivity = OpenErrorActivity(context) | ||
} |
56 changes: 56 additions & 0 deletions
56
app/src/main/java/org/schabi/newpipe/dependency_injection/DatabaseModule.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,56 @@ | ||
package org.schabi.newpipe.dependency_injection | ||
|
||
import android.content.Context | ||
import androidx.room.Room | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import org.schabi.newpipe.database.AppDatabase | ||
import org.schabi.newpipe.database.AppDatabase.DATABASE_NAME | ||
import org.schabi.newpipe.database.Migrations.MIGRATION_1_2 | ||
import org.schabi.newpipe.database.Migrations.MIGRATION_2_3 | ||
import org.schabi.newpipe.database.Migrations.MIGRATION_3_4 | ||
import org.schabi.newpipe.database.Migrations.MIGRATION_4_5 | ||
import org.schabi.newpipe.database.Migrations.MIGRATION_5_6 | ||
import org.schabi.newpipe.database.Migrations.MIGRATION_6_7 | ||
import org.schabi.newpipe.database.Migrations.MIGRATION_7_8 | ||
import org.schabi.newpipe.database.Migrations.MIGRATION_8_9 | ||
import org.schabi.newpipe.database.history.dao.SearchHistoryDAO | ||
import org.schabi.newpipe.database.history.dao.StreamHistoryDAO | ||
import org.schabi.newpipe.database.stream.dao.StreamDAO | ||
import org.schabi.newpipe.database.stream.dao.StreamStateDAO | ||
import javax.inject.Singleton | ||
|
||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
class DatabaseModule { | ||
|
||
@Provides | ||
@Singleton | ||
fun provideAppDatabase(@ApplicationContext appContext: Context): AppDatabase = | ||
Room.databaseBuilder( | ||
appContext, | ||
AppDatabase::class.java, | ||
DATABASE_NAME | ||
).addMigrations( | ||
MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5, | ||
MIGRATION_5_6, MIGRATION_6_7, MIGRATION_7_8, MIGRATION_8_9 | ||
).build() | ||
|
||
@Provides | ||
fun provideStreamStateDao(appDatabase: AppDatabase): StreamStateDAO = | ||
appDatabase.streamStateDAO() | ||
|
||
@Provides | ||
fun providesStreamDao(appDatabase: AppDatabase): StreamDAO = appDatabase.streamDAO() | ||
|
||
@Provides | ||
fun provideStreamHistoryDao(appDatabase: AppDatabase): StreamHistoryDAO = | ||
appDatabase.streamHistoryDAO() | ||
|
||
@Provides | ||
fun provideSearchHistoryDao(appDatabase: AppDatabase): SearchHistoryDAO = | ||
appDatabase.searchHistoryDAO() | ||
} |
18 changes: 18 additions & 0 deletions
18
app/src/main/java/org/schabi/newpipe/error/usecases/OpenErrorActivity.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,18 @@ | ||
package org.schabi.newpipe.error.usecases | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import org.schabi.newpipe.error.ErrorActivity | ||
import org.schabi.newpipe.error.ErrorInfo | ||
|
||
class OpenErrorActivity( | ||
private val context: Context, | ||
) { | ||
operator fun invoke(errorInfo: ErrorInfo) { | ||
val intent = Intent(context, ErrorActivity::class.java) | ||
intent.putExtra(ErrorActivity.ERROR_INFO, errorInfo) | ||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
|
||
context.startActivity(intent) | ||
} | ||
} |
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
85 changes: 85 additions & 0 deletions
85
.../org/schabi/newpipe/settings/components/irreversible_preference/IrreversiblePreference.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,85 @@ | ||
package org.schabi.newpipe.settings.components.irreversible_preference | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.derivedStateOf | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.alpha | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import org.schabi.newpipe.ui.theme.AppTheme | ||
import org.schabi.newpipe.ui.theme.SizeTokens.SpacingExtraSmall | ||
import org.schabi.newpipe.ui.theme.SizeTokens.SpacingMedium | ||
|
||
@Composable | ||
fun IrreversiblePreferenceComponent( | ||
title: String, | ||
summary: String, | ||
onClick: () -> Unit, | ||
modifier: Modifier = Modifier, | ||
enabled: Boolean = true, | ||
) { | ||
val clickModifier = if (enabled) { | ||
Modifier.clickable { onClick() } | ||
} else { | ||
Modifier | ||
} | ||
Row( | ||
modifier = clickModifier.then(modifier), | ||
verticalAlignment = Alignment.CenterVertically, | ||
) { | ||
val alpha by remember { | ||
derivedStateOf { | ||
if (enabled) 1f else 0.38f | ||
} | ||
} | ||
Column( | ||
modifier = Modifier.padding(SpacingMedium) | ||
) { | ||
Text( | ||
text = title, | ||
modifier = Modifier.alpha(alpha), | ||
) | ||
Spacer(modifier = Modifier.padding(SpacingExtraSmall)) | ||
Text( | ||
text = summary, | ||
style = MaterialTheme.typography.labelSmall, | ||
modifier = Modifier.alpha(alpha * 0.6f), | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Preview(showBackground = true, backgroundColor = 0xFFFFFFFF) | ||
@Composable | ||
private fun IrreversiblePreferenceComponentPreview() { | ||
val title = "Wipe cached metadata" | ||
val summary = "Remove all cached webpage data" | ||
AppTheme { | ||
Column { | ||
|
||
IrreversiblePreferenceComponent( | ||
title = title, | ||
summary = summary, | ||
onClick = {}, | ||
modifier = Modifier.fillMaxWidth() | ||
) | ||
IrreversiblePreferenceComponent( | ||
title = title, | ||
summary = summary, | ||
onClick = {}, | ||
modifier = Modifier.fillMaxWidth(), | ||
enabled = false | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.