Skip to content

Commit

Permalink
Merge pull request #2272 from AndBible/feature/discrete_mode
Browse files Browse the repository at this point in the history
Feature/discrete mode
  • Loading branch information
tuomas2 authored Oct 6, 2022
2 parents 9a3f2d6 + 098b433 commit e5f887c
Show file tree
Hide file tree
Showing 12 changed files with 809 additions and 35 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ dependencies {
implementation("androidx.preference:preference-ktx:1.2.0")
implementation("androidx.recyclerview:recyclerview:1.2.1")
implementation("androidx.webkit:webkit:1.5.0")
implementation("io.apisense:rhino-android:1.1.1")

//implementation("androidx.recyclerview:recyclerview-selection:1.0.0")

Expand Down
33 changes: 30 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,42 @@
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
<activity
android:name=".StartupActivity"

<activity android:name=".StartupActivity"
android:configChanges="keyboardHidden|orientation|screenSize|locale"
android:icon="@mipmap/ic_launcher" />

<activity-alias
android:name="net.bible.android.view.activity.Bible"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name_short"
android:targetActivity=".StartupActivity"
android:exported="true"
android:enabled="true"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<!-- see Samsung multi-window info at bottom -->
<category android:name="android.intent.category.MULTIWINDOW_LAUNCHER" />
</intent-filter>
</activity>
</activity-alias>
<activity-alias
android:name="net.bible.android.view.activity.Calculator"
android:icon="@drawable/ic_baseline_calculate_24"
android:label="@string/app_name_calculator"
android:enabled="false"
android:exported="true"
android:targetActivity=".StartupActivity"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<!-- see Samsung multi-window info at bottom -->
<category android:name="android.intent.category.MULTIWINDOW_LAUNCHER" />
</intent-filter>
</activity-alias>

<activity
android:name="net.bible.android.view.activity.page.MainBibleActivity"
android:configChanges="keyboard|navigation|keyboardHidden|screenSize|locale"
Expand Down Expand Up @@ -242,6 +265,10 @@
<data android:mimeType="application/zip" />
</intent-filter>
</activity>
<activity
android:name="net.bible.android.view.activity.discrete.CalculatorActivity"
android:label="@string/app_name_calculator"
/>

<service
android:name="net.bible.service.device.speak.TextToSpeechNotificationManager$ForegroundService"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package net.bible.android.view.activity
import android.annotation.SuppressLint
import android.app.Activity
import android.app.AlertDialog
import android.app.Instrumentation
import android.content.Context
import android.content.Intent
import android.os.Build
Expand Down Expand Up @@ -53,6 +54,7 @@ import net.bible.android.database.SwordDocumentInfo
import net.bible.android.view.activity.base.CurrentActivityHolder
import net.bible.android.view.activity.base.CustomTitlebarActivityBase
import net.bible.android.view.activity.base.Dialogs
import net.bible.android.view.activity.discrete.CalculatorActivity
import net.bible.android.view.activity.download.DownloadActivity
import net.bible.android.view.activity.download.FirstDownload
import net.bible.android.view.activity.installzip.InstallZip
Expand Down Expand Up @@ -200,6 +202,12 @@ open class StartupActivity : CustomTitlebarActivityBase() {
// switch back to ui thread to continue
withContext(Dispatchers.Main) {
postBasicInitialisationControl()
if(CommonUtils.settings.getBoolean("show_calculator", false)) {
spinnerBinding.imageView.setImageDrawable(
CommonUtils.getTintedDrawable(R.drawable.ic_baseline_calculate_24, R.color.grey_500)
)
spinnerBinding.splashTitleText.text = getString(R.string.app_name_calculator)
}
}
}
}
Expand Down Expand Up @@ -303,6 +311,15 @@ open class StartupActivity : CustomTitlebarActivityBase() {
startActivityForResult(handlerIntent, DOWNLOAD_DOCUMENT_REQUEST)
}

private suspend fun gotoCalculator() {
val show = CommonUtils.settings.getBoolean("show_calculator", false)
if(show) {
Log.i(TAG, "Going to Calculator")
val handlerIntent = Intent(this, CalculatorActivity::class.java)
while(awaitIntent(handlerIntent)?.resultCode != RESULT_OK) {}
}
}

private fun gotoMainBibleActivity() {
Log.i(TAG, "Going to MainBibleActivity")
val handlerIntent = Intent(this, MainBibleActivity::class.java)
Expand All @@ -318,6 +335,7 @@ open class StartupActivity : CustomTitlebarActivityBase() {
}
}

gotoCalculator()
startActivity(handlerIntent)
finish()
}
Expand All @@ -330,40 +348,43 @@ open class StartupActivity : CustomTitlebarActivityBase() {
Log.i(TAG, "Activity result:$resultCode")
super.onActivityResult(requestCode, resultCode, data)

if (requestCode == DOWNLOAD_DOCUMENT_REQUEST) {
Log.i(TAG, "Returned from Download")
if (swordDocumentFacade.bibles.isNotEmpty()) {
Log.i(TAG, "Bibles now exist so go to main bible view")
// select appropriate default verse e.g. John 3.16 if NT only
GlobalScope.launch(Dispatchers.Main) {
gotoMainBibleActivity()
}
when (requestCode) {
DOWNLOAD_DOCUMENT_REQUEST -> {
Log.i(TAG, "Returned from Download")
if (swordDocumentFacade.bibles.isNotEmpty()) {
Log.i(TAG, "Bibles now exist so go to main bible view")
// select appropriate default verse e.g. John 3.16 if NT only
GlobalScope.launch(Dispatchers.Main) {
gotoMainBibleActivity()
}

} else {
Log.i(TAG, "No Bibles exist so start again")
GlobalScope.launch(Dispatchers.Main) {
postBasicInitialisationControl()
} else {
Log.i(TAG, "No Bibles exist so start again")
GlobalScope.launch(Dispatchers.Main) {
postBasicInitialisationControl()
}
}
}
} else if (requestCode == REQUEST_PICK_FILE_FOR_BACKUP_RESTORE) {
// this and the one in MainActivity could potentially be merged into the same thing
if (resultCode == Activity.RESULT_OK) {
CurrentActivityHolder.currentActivity = this
Dialogs.showMsg(R.string.restore_confirmation, true) {
ABEventBus.post(ToastEvent(getString(R.string.loading_backup)))
val hourglass = Hourglass(this)
GlobalScope.launch(Dispatchers.IO) {
hourglass.show()
val inputStream = contentResolver.openInputStream(data!!.data!!)
if (BackupControl.restoreDatabaseViaIntent(inputStream!!)) {
Log.i(TAG, "Restored database successfully")

withContext(Dispatchers.Main) {
Dialogs.showMsg(R.string.restore_success)
postBasicInitialisationControl()
REQUEST_PICK_FILE_FOR_BACKUP_RESTORE -> {
// this and the one in MainActivity could potentially be merged into the same thing
if (resultCode == Activity.RESULT_OK) {
CurrentActivityHolder.currentActivity = this
Dialogs.showMsg(R.string.restore_confirmation, true) {
ABEventBus.post(ToastEvent(getString(R.string.loading_backup)))
val hourglass = Hourglass(this)
GlobalScope.launch(Dispatchers.IO) {
hourglass.show()
val inputStream = contentResolver.openInputStream(data!!.data!!)
if (BackupControl.restoreDatabaseViaIntent(inputStream!!)) {
Log.i(TAG, "Restored database successfully")

withContext(Dispatchers.Main) {
Dialogs.showMsg(R.string.restore_success)
postBasicInitialisationControl()
}
}
hourglass.dismiss()
}
hourglass.dismiss()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import android.app.Activity
import android.util.Log
import net.bible.android.control.event.ABEventBus
import net.bible.android.control.event.apptobackground.AppToBackgroundEvent
import net.bible.service.common.CommonUtils

/** Allow operations form middle tier that require a reference to the current Activity
*
Expand Down Expand Up @@ -48,6 +49,10 @@ object CurrentActivityHolder {
appIsInForeground = false
ABEventBus
.post(AppToBackgroundEvent(AppToBackgroundEvent.Position.BACKGROUND))
if (CommonUtils.initialized && CommonUtils.settings.getBoolean("show_calculator", false)) {
Log.d(TAG, "Closing app to start from calculator again...")
CommonUtils.forceStopApp()
}
}
}
}
Expand Down
Loading

0 comments on commit e5f887c

Please sign in to comment.