From d11cb63c164a65fba5567e820e0f0c7034cafe46 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 15 Feb 2022 18:35:57 +0100 Subject: [PATCH] Create a new activity to manage certificates --- .idea/misc.xml | 1 + app/build.gradle | 1 + app/src/main/AndroidManifest.xml | 12 +++++++- .../dccaggregator/DCCAggregator.kt | 10 +++++++ .../dccaggregator/MainActivity.kt | 16 ---------- .../dccaggregator/activities/CertsManager.kt | 24 +++++++++++++++ .../dccaggregator/activities/MainActivity.kt | 30 +++++++++++++++++++ .../dccaggregator/helper/CertificatesList.kt | 10 +++++++ .../res/layout/activity_certs_manager.xml | 9 ++++++ app/src/main/res/layout/activity_main.xml | 2 +- app/src/main/res/values/strings.xml | 1 + 11 files changed, 98 insertions(+), 18 deletions(-) create mode 100644 app/src/main/java/org/communiquons/dccaggregator/DCCAggregator.kt delete mode 100644 app/src/main/java/org/communiquons/dccaggregator/MainActivity.kt create mode 100644 app/src/main/java/org/communiquons/dccaggregator/activities/CertsManager.kt create mode 100644 app/src/main/java/org/communiquons/dccaggregator/activities/MainActivity.kt create mode 100644 app/src/main/java/org/communiquons/dccaggregator/helper/CertificatesList.kt create mode 100644 app/src/main/res/layout/activity_certs_manager.xml diff --git a/.idea/misc.xml b/.idea/misc.xml index 1736f05..c776a8f 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -7,6 +7,7 @@ + diff --git a/app/build.gradle b/app/build.gradle index 950e3f1..6a6269d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -37,6 +37,7 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.4.0' implementation 'com.google.android.material:material:1.4.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.2' + implementation 'androidx.preference:preference:1.2.0' testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index aeae542..f64e8bc 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -3,14 +3,17 @@ package="org.communiquons.dccaggregator"> + + @@ -19,6 +22,13 @@ + + + + \ No newline at end of file diff --git a/app/src/main/java/org/communiquons/dccaggregator/DCCAggregator.kt b/app/src/main/java/org/communiquons/dccaggregator/DCCAggregator.kt new file mode 100644 index 0000000..9776061 --- /dev/null +++ b/app/src/main/java/org/communiquons/dccaggregator/DCCAggregator.kt @@ -0,0 +1,10 @@ +package org.communiquons.dccaggregator + +import android.app.Application +import org.communiquons.dccaggregator.helper.CertificatesList + +class DCCAggregator : Application() { + val certManager by lazy { + CertificatesList(this) + } +} \ No newline at end of file diff --git a/app/src/main/java/org/communiquons/dccaggregator/MainActivity.kt b/app/src/main/java/org/communiquons/dccaggregator/MainActivity.kt deleted file mode 100644 index 8ce4df5..0000000 --- a/app/src/main/java/org/communiquons/dccaggregator/MainActivity.kt +++ /dev/null @@ -1,16 +0,0 @@ -package org.communiquons.dccaggregator - -import android.os.Bundle -import androidx.appcompat.app.AppCompatActivity -import androidx.appcompat.app.AppCompatDelegate - -class MainActivity : AppCompatActivity() { - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setTheme(R.style.Theme_DCCAggregator) - setContentView(R.layout.activity_main) - - - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) - } -} \ No newline at end of file diff --git a/app/src/main/java/org/communiquons/dccaggregator/activities/CertsManager.kt b/app/src/main/java/org/communiquons/dccaggregator/activities/CertsManager.kt new file mode 100644 index 0000000..4132423 --- /dev/null +++ b/app/src/main/java/org/communiquons/dccaggregator/activities/CertsManager.kt @@ -0,0 +1,24 @@ +package org.communiquons.dccaggregator.activities + +import android.os.Bundle +import android.view.MenuItem +import androidx.appcompat.app.AppCompatActivity +import org.communiquons.dccaggregator.R + +class CertsManager : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_certs_manager) + + supportActionBar?.setDisplayHomeAsUpEnabled(true) + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + if (item.itemId == android.R.id.home) { + finish() + return true + } + + return super.onOptionsItemSelected(item) + } +} \ No newline at end of file diff --git a/app/src/main/java/org/communiquons/dccaggregator/activities/MainActivity.kt b/app/src/main/java/org/communiquons/dccaggregator/activities/MainActivity.kt new file mode 100644 index 0000000..4ccedf3 --- /dev/null +++ b/app/src/main/java/org/communiquons/dccaggregator/activities/MainActivity.kt @@ -0,0 +1,30 @@ +package org.communiquons.dccaggregator.activities + +import android.content.Intent +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import androidx.appcompat.app.AppCompatDelegate +import org.communiquons.dccaggregator.DCCAggregator +import org.communiquons.dccaggregator.R + +class MainActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setTheme(R.style.Theme_DCCAggregator) + setContentView(R.layout.activity_main) + + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) + } + + override fun onResume() { + super.onResume() + + // On first launch, start certificates manager first + if (!(application as DCCAggregator).certManager.hasGeneratedCertificate) + openCertsManager() + } + + fun openCertsManager() { + startActivity(Intent(this, CertsManager::class.java)) + } +} \ No newline at end of file diff --git a/app/src/main/java/org/communiquons/dccaggregator/helper/CertificatesList.kt b/app/src/main/java/org/communiquons/dccaggregator/helper/CertificatesList.kt new file mode 100644 index 0000000..7aa8387 --- /dev/null +++ b/app/src/main/java/org/communiquons/dccaggregator/helper/CertificatesList.kt @@ -0,0 +1,10 @@ +package org.communiquons.dccaggregator.helper + +import android.content.Context +import androidx.preference.PreferenceManager + +class CertificatesList(context: Context) { + private val prefsManager = PreferenceManager.getDefaultSharedPreferences(context) + + val hasGeneratedCertificate get() = false +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_certs_manager.xml b/app/src/main/res/layout/activity_certs_manager.xml new file mode 100644 index 0000000..1d676c6 --- /dev/null +++ b/app/src/main/res/layout/activity_certs_manager.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 4fc2444..fd8eba3 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -4,7 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".MainActivity"> + tools:context=".activities.MainActivity"> DCCAggregator + Input certificates \ No newline at end of file