Skip to content

Commit

Permalink
Remove DayNight workaround and change ToastController scope, change t…
Browse files Browse the repository at this point in the history
…odo comments
  • Loading branch information
G00fY2 committed Jul 4, 2021
1 parent 7853e0f commit 7a74221
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ class StorageDirsControllerImpl @Inject constructor() : StorageDirsController {
@Named(ACTIVITY)
lateinit var activity: BaseActivity

/**
* Return all storage directories.
* Inspired by AOSP (API 18) and the Amaze File Manager sourcecode
*/
// return all storage directories (inspired by AOSP API 18 and the Amaze File Manager sourcecode)
override fun getStorageDirectories(): Collection<File> {
return mutableSetOf<File>().apply {
if (VERSION.SDK_INT < VERSION_CODES.M) {
Expand All @@ -37,7 +34,9 @@ class StorageDirsControllerImpl @Inject constructor() : StorageDirsController {
}

@Suppress("DEPRECATION")
// TODO replace getExternalStorageDirectory calls when target API > 29
// TODO getExternalStorageDirectory and requestLegacyExternalStorage only work with targetSdk <= 29
// If we want to raise the targetSdk we would have to switch to Androids Scoped storage API, which doesn not
// offer access to all folders
private fun getExtSdCardPathsDeprecated(): Collection<File> {
val dirs = mutableListOf<File>()
val rawExternalStorage = System.getenv("EXTERNAL_STORAGE")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.os.Build.VERSION
import android.os.Build.VERSION_CODES
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.edit
import com.g00fy2.developerwidget.R
import com.g00fy2.developerwidget.di.annotations.APPLICATION
import com.g00fy2.developerwidget.receiver.widget.WidgetProviderImpl
import javax.inject.Inject
Expand All @@ -18,9 +17,6 @@ class DayNightControllerImpl @Inject constructor() : DayNightController {
@Named(APPLICATION)
lateinit var context: Context

@Inject
lateinit var toastController: ToastController

private val defaultMode =
if (VERSION.SDK_INT >= VERSION_CODES.P) AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM else AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY
private val sharedPreference by lazy {
Expand All @@ -39,8 +35,6 @@ class DayNightControllerImpl @Inject constructor() : DayNightController {
AppCompatDelegate.MODE_NIGHT_NO -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
else -> AppCompatDelegate.MODE_NIGHT_YES
}.let {
// TODO remove if https://issuetracker.google.com/issues/131851825 is fixed
if (VERSION.SDK_INT <= VERSION_CODES.M) toastController.showToast(R.string.day_night_issue)
saveCustomDefaultMode(it)
applyMode(it)
updateWidgetTheme()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,13 @@ import com.g00fy2.developerwidget.di.annotations.ActivityScope
import dagger.Binds
import dagger.Module
import dagger.Reusable
import javax.inject.Singleton

@Module
abstract class GlobalControllerModule {

@Binds
@Reusable
abstract fun providesDayNightController(dayNightControllerImpl: DayNightControllerImpl): DayNightController

@Binds
@Singleton
abstract fun provideToastController(toastControllerImpl: ToastControllerImpl): ToastController
}

@Module
Expand All @@ -54,4 +49,8 @@ abstract class ActivityControllerModule {
@Binds
@ActivityScope
abstract fun providePreferenceController(preferenceControllerImpl: PreferenceControllerImpl): PreferenceController

@Binds
@ActivityScope
abstract fun provideToastController(toastControllerImpl: ToastControllerImpl): ToastController
}
1 change: 0 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
<string name="show_all_apps">Show all %s apps</string>
<string name="show_all">Show all</string>
<string name="manually_add_widget">You have to manually add a new widget using your launcher.</string>
<string name="day_night_issue">You may need to restart the app to fully take effect.</string>
<string name="share_device_data">Share device data</string>
<string name="apk_warning_title">Potentially harmful app</string>
<string name="apk_warning_description">This app contains code that attempts to bypass Android\'s security protections.</string>
Expand Down

0 comments on commit 7a74221

Please sign in to comment.