diff --git a/app/build.gradle b/app/build.gradle index 288b935..c69d09e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -26,22 +26,22 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'androidx.appcompat:appcompat:1.0.0-rc02' + implementation 'androidx.appcompat:appcompat:1.0.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2' - implementation 'com.google.android.material:material:1.0.0-rc02' - implementation 'androidx.recyclerview:recyclerview:1.0.0-rc02' - implementation 'androidx.gridlayout:gridlayout:1.0.0-rc02' + implementation 'com.google.android.material:material:1.0.0' + implementation 'androidx.recyclerview:recyclerview:1.0.0' + implementation 'androidx.gridlayout:gridlayout:1.0.0' api 'com.google.guava:guava:26.0-android' - implementation 'com.github.codekidX:storage-chooser:2.0.4.2' + api 'com.github.codekidX:storage-chooser:2.0.4.2' // implementation 'com.github.mjdev:libaums:0.5.5' implementation project(':libaums') implementation project(':dmg2img') implementation 'com.android.support.constraint:constraint-layout:1.1.3' - implementation 'com.android.support:design:28.0.0-rc02' - implementation 'com.android.support:appcompat-v7:28.0.0-rc02' + implementation 'com.android.support:design:28.0.0' + implementation 'com.android.support:appcompat-v7:28.0.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.1.0-alpha4' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4' diff --git a/app/src/main/java/eu/depau/etchdroid/activities/ActivityBase.kt b/app/src/main/java/eu/depau/etchdroid/activities/ActivityBase.kt index 899d3d6..4811550 100644 --- a/app/src/main/java/eu/depau/etchdroid/activities/ActivityBase.kt +++ b/app/src/main/java/eu/depau/etchdroid/activities/ActivityBase.kt @@ -1,12 +1,21 @@ package eu.depau.etchdroid.activities import android.content.Intent +import android.os.Bundle import android.view.Menu import android.view.MenuItem import androidx.appcompat.app.AppCompatActivity import eu.depau.etchdroid.R +import eu.depau.etchdroid.utils.NightModeHelper -abstract class ActivityBase: AppCompatActivity() { + +abstract class ActivityBase : AppCompatActivity() { + protected lateinit var nightModeHelper: NightModeHelper + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + nightModeHelper = NightModeHelper(this, R.style.AppTheme) + } override fun onCreateOptionsMenu(menu: Menu): Boolean { // Inflate the menu; this adds items to the action bar if it is present. @@ -24,6 +33,10 @@ abstract class ActivityBase: AppCompatActivity() { startActivity(intent) return true } + R.id.action_nightmode -> { + nightModeHelper.toggle() + return true + } else -> super.onOptionsItemSelected(item) } } diff --git a/app/src/main/java/eu/depau/etchdroid/activities/ConfirmationActivity.kt b/app/src/main/java/eu/depau/etchdroid/activities/ConfirmationActivity.kt index 9c99ade..69b2c4e 100644 --- a/app/src/main/java/eu/depau/etchdroid/activities/ConfirmationActivity.kt +++ b/app/src/main/java/eu/depau/etchdroid/activities/ConfirmationActivity.kt @@ -37,7 +37,7 @@ class ConfirmationActivity : ActivityBase() { fun showDataLossAlertDialog() { - val dialogFragment = DoNotShowAgainDialogFragment() + val dialogFragment = DoNotShowAgainDialogFragment(nightModeHelper.nightMode) dialogFragment.title = getString(R.string.warning) dialogFragment.message = getString(R.string.dataloss_confirmation_dialog_message) dialogFragment.positiveButton = getString(R.string.confirm_flash_image) diff --git a/app/src/main/java/eu/depau/etchdroid/activities/ErrorActivity.kt b/app/src/main/java/eu/depau/etchdroid/activities/ErrorActivity.kt index 8462d5d..50a35ed 100644 --- a/app/src/main/java/eu/depau/etchdroid/activities/ErrorActivity.kt +++ b/app/src/main/java/eu/depau/etchdroid/activities/ErrorActivity.kt @@ -1,11 +1,10 @@ package eu.depau.etchdroid.activities import android.os.Bundle -import androidx.appcompat.app.AppCompatActivity import eu.depau.etchdroid.R import kotlinx.android.synthetic.main.activity_error.* -class ErrorActivity : AppCompatActivity() { +class ErrorActivity : ActivityBase() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/eu/depau/etchdroid/activities/StartActivity.kt b/app/src/main/java/eu/depau/etchdroid/activities/StartActivity.kt index 307dd05..a7356f5 100644 --- a/app/src/main/java/eu/depau/etchdroid/activities/StartActivity.kt +++ b/app/src/main/java/eu/depau/etchdroid/activities/StartActivity.kt @@ -1,16 +1,15 @@ package eu.depau.etchdroid.activities import android.Manifest -import android.app.Activity import android.content.Intent import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.os.Environment import android.view.View +import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat -import com.codekidlabs.storagechooser.StorageChooser import eu.depau.etchdroid.R import eu.depau.etchdroid.StateKeeper import eu.depau.etchdroid.enums.FlashMethod @@ -62,7 +61,7 @@ class StartActivity : ActivityBase() { } fun showDMGBetaAlertDialog() { - val dialogFragment = DoNotShowAgainDialogFragment() + val dialogFragment = DoNotShowAgainDialogFragment(nightModeHelper.nightMode) dialogFragment.title = getString(R.string.here_be_dragons) dialogFragment.message = getString(R.string.dmg_alert_dialog_text) dialogFragment.positiveButton = getString(R.string.i_understand) @@ -145,7 +144,7 @@ class StartActivity : ActivityBase() { } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - if (requestCode == READ_REQUEST_CODE && resultCode == Activity.RESULT_OK) { + if (requestCode == READ_REQUEST_CODE && resultCode == AppCompatActivity.RESULT_OK) { // The document selected by the user won't be returned in the intent. // Instead, a URI to that document will be contained in the return intent // provided to this method as a parameter. diff --git a/app/src/main/java/eu/depau/etchdroid/utils/DoNotShowAgainDialogFragment.kt b/app/src/main/java/eu/depau/etchdroid/utils/DoNotShowAgainDialogFragment.kt index 75da5d7..a135117 100644 --- a/app/src/main/java/eu/depau/etchdroid/utils/DoNotShowAgainDialogFragment.kt +++ b/app/src/main/java/eu/depau/etchdroid/utils/DoNotShowAgainDialogFragment.kt @@ -1,5 +1,6 @@ package eu.depau.etchdroid.utils +import android.annotation.SuppressLint import android.app.Dialog import android.os.Bundle import android.view.LayoutInflater @@ -8,13 +9,21 @@ import androidx.fragment.app.DialogFragment import eu.depau.etchdroid.R import kotlinx.android.synthetic.main.do_not_show_again.view.* - -class DoNotShowAgainDialogFragment() : DialogFragment() { +@SuppressLint("ValidFragment") +class DoNotShowAgainDialogFragment(nightMode: Boolean) : DialogFragment() { var title: String? = null var positiveButton: String? = null var negativeButton: String? = null var message: String? = null var listener: DialogListener? = null + val dialogTheme: Int + + constructor() : this(false) + + init { + dialogTheme = if (nightMode) R.style.DialogThemeDark else R.style.DialogThemeLight + setStyle(DialogFragment.STYLE_NORMAL, dialogTheme) + } interface DialogListener { fun onDialogPositive(dialog: DoNotShowAgainDialogFragment, showAgain: Boolean) @@ -23,7 +32,7 @@ class DoNotShowAgainDialogFragment() : DialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { // Build the dialog and set up the button click handlers - val builder = AlertDialog.Builder(activity!!) + val builder = AlertDialog.Builder(activity!!, dialogTheme) val inflater = LayoutInflater.from(this.context) val dnsaLayout = inflater.inflate(R.layout.do_not_show_again, null) val doNotShowAgainCB = dnsaLayout.do_not_show_again @@ -37,7 +46,7 @@ class DoNotShowAgainDialogFragment() : DialogFragment() { } if (negativeButton != null) - builder.setNegativeButton(negativeButton) {_, _ -> + builder.setNegativeButton(negativeButton) { _, _ -> listener?.onDialogNegative(this@DoNotShowAgainDialogFragment, !doNotShowAgainCB.isChecked) } diff --git a/app/src/main/java/eu/depau/etchdroid/utils/NightModeHelper.kt b/app/src/main/java/eu/depau/etchdroid/utils/NightModeHelper.kt new file mode 100644 index 0000000..510313b --- /dev/null +++ b/app/src/main/java/eu/depau/etchdroid/utils/NightModeHelper.kt @@ -0,0 +1,121 @@ +package eu.depau.etchdroid.utils + +import android.content.SharedPreferences +import android.content.res.Configuration +import android.preference.PreferenceManager +import androidx.appcompat.app.AppCompatActivity +import java.lang.ref.WeakReference + + +/** + * Night Mode Helper + * + * Adapted from https://gist.github.com/slightfoot/c508cdc8828a478572e0 + * + * Helps use utilise the night and notnight resource qualifiers without + * being in car or dock mode. + * + * + * Implementation is simple. Add the follow line at the top of your + * activity's onCreate just after the super.onCreate(); The idea here + * is to do it before we create any views. So the new views will use + * the correct Configuration. + * + *
+ * mNightModeHelper = new NightModeHelper(this, R.style.AppTheme); +* + * + * You can now use your instance of NightModeHelper to control which mode + * you are in. You can choose to persist the current setting and hand + * it back to this class as the defaultUiMode, otherwise this is done + * for you automatically. + * + * + * I'd suggest you setup your Theme as follows: + * + * * + * **res\values\styles.xml** + *
<style name="AppTheme" parent="AppBaseTheme"></style>+ * + * * + * **res\values-night\styles.xml** + *
<style name="AppBaseTheme" parent="@android:style/Theme.Holo"></style>+ * + * * + * **res\values-notnight\styles.xml** + *
<style name="AppBaseTheme" parent="@android:style/Theme.Holo.Light"></style>+ * + * @author Simon Lightfoot