Open market app if Nextcloud App isn't installed
This commit is contained in:
parent
26531567e1
commit
0c44f3f483
|
@ -2,7 +2,12 @@ package org.unifiedpush.distributor.nextpush.account
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.text.SpannableString
|
||||||
|
import android.text.method.LinkMovementMethod
|
||||||
|
import android.text.util.Linkify
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import android.widget.TextView
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
import com.nextcloud.android.sso.AccountImporter
|
import com.nextcloud.android.sso.AccountImporter
|
||||||
import com.nextcloud.android.sso.exceptions.AndroidGetAccountsPermissionNotGranted
|
import com.nextcloud.android.sso.exceptions.AndroidGetAccountsPermissionNotGranted
|
||||||
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException
|
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException
|
||||||
|
@ -11,6 +16,10 @@ import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException
|
||||||
import com.nextcloud.android.sso.helper.SingleAccountHelper
|
import com.nextcloud.android.sso.helper.SingleAccountHelper
|
||||||
import com.nextcloud.android.sso.model.SingleSignOnAccount
|
import com.nextcloud.android.sso.model.SingleSignOnAccount
|
||||||
import com.nextcloud.android.sso.ui.UiExceptionManager
|
import com.nextcloud.android.sso.ui.UiExceptionManager
|
||||||
|
import android.content.DialogInterface
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import org.unifiedpush.distributor.nextpush.R
|
||||||
|
|
||||||
private const val TAG = "AccountUtils"
|
private const val TAG = "AccountUtils"
|
||||||
|
|
||||||
|
@ -20,11 +29,47 @@ const val PREF_URL = "url"
|
||||||
|
|
||||||
lateinit var ssoAccount: SingleSignOnAccount
|
lateinit var ssoAccount: SingleSignOnAccount
|
||||||
|
|
||||||
|
fun nextcloudAppNotInstalledDialog(context: Context) {
|
||||||
|
val message = TextView(context)
|
||||||
|
val builder = AlertDialog.Builder(context)
|
||||||
|
var messageContent = context.getString(R.string.message_missing_nextcloud_app)
|
||||||
|
val installIntent =
|
||||||
|
Intent(Intent.ACTION_VIEW, Uri.parse(context.getString(R.string.uri_market_nextcloud_app)))
|
||||||
|
messageContent += if (
|
||||||
|
installIntent.resolveActivity(context.applicationContext.packageManager) != null
|
||||||
|
) {
|
||||||
|
val callback = {
|
||||||
|
context.startActivity(
|
||||||
|
Intent.createChooser(
|
||||||
|
installIntent,
|
||||||
|
context.getString(R.string.market_chooser_title))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
builder.setPositiveButton(context.getString(R.string.install)) {
|
||||||
|
_: DialogInterface, _: Int -> callback()
|
||||||
|
}
|
||||||
|
builder.setNegativeButton(context.getString(R.string.dismiss)) {
|
||||||
|
_: DialogInterface, _: Int ->
|
||||||
|
}
|
||||||
|
"."
|
||||||
|
} else {
|
||||||
|
": " + context.getString(R.string.uri_fdroid_nextcloud_app)
|
||||||
|
}
|
||||||
|
val s = SpannableString(messageContent)
|
||||||
|
Linkify.addLinks(s, Linkify.ALL)
|
||||||
|
message.text = s
|
||||||
|
message.movementMethod = LinkMovementMethod.getInstance()
|
||||||
|
message.setPadding(32,32,32,32)
|
||||||
|
builder.setTitle(context.getString(R.string.nextcloud_files_not_found_title))
|
||||||
|
builder.setView(message)
|
||||||
|
builder.show()
|
||||||
|
}
|
||||||
|
|
||||||
fun isConnected(context: Context) : Boolean {
|
fun isConnected(context: Context) : Boolean {
|
||||||
try {
|
try {
|
||||||
ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(context)
|
ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(context)
|
||||||
} catch (e: NextcloudFilesAppAccountNotFoundException) {
|
} catch (e: NextcloudFilesAppAccountNotFoundException) {
|
||||||
UiExceptionManager.showDialogForException(context, e)
|
nextcloudAppNotInstalledDialog(context)
|
||||||
} catch (e: NoCurrentAccountSelectedException) {
|
} catch (e: NoCurrentAccountSelectedException) {
|
||||||
Log.d(TAG,"Device is not connected")
|
Log.d(TAG,"Device is not connected")
|
||||||
return false
|
return false
|
||||||
|
@ -36,7 +81,7 @@ fun connect(activity: Activity) {
|
||||||
try {
|
try {
|
||||||
AccountImporter.pickNewAccount(activity)
|
AccountImporter.pickNewAccount(activity)
|
||||||
} catch (e: NextcloudFilesAppNotInstalledException) {
|
} catch (e: NextcloudFilesAppNotInstalledException) {
|
||||||
UiExceptionManager.showDialogForException(activity, e)
|
nextcloudAppNotInstalledDialog(activity)
|
||||||
} catch (e: AndroidGetAccountsPermissionNotGranted) {
|
} catch (e: AndroidGetAccountsPermissionNotGranted) {
|
||||||
UiExceptionManager.showDialogForException(activity, e)
|
UiExceptionManager.showDialogForException(activity, e)
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ import com.nextcloud.android.sso.exceptions.*
|
||||||
import org.unifiedpush.distributor.nextpush.R
|
import org.unifiedpush.distributor.nextpush.R
|
||||||
import org.unifiedpush.distributor.nextpush.account.isConnected
|
import org.unifiedpush.distributor.nextpush.account.isConnected
|
||||||
import org.unifiedpush.distributor.nextpush.account.connect
|
import org.unifiedpush.distributor.nextpush.account.connect
|
||||||
|
import org.unifiedpush.distributor.nextpush.account.nextcloudAppNotInstalledDialog
|
||||||
import org.unifiedpush.distributor.nextpush.account.ssoAccount
|
import org.unifiedpush.distributor.nextpush.account.ssoAccount
|
||||||
import org.unifiedpush.distributor.nextpush.api.apiDeleteApp
|
import org.unifiedpush.distributor.nextpush.api.apiDeleteApp
|
||||||
import org.unifiedpush.distributor.nextpush.api.apiDeleteDevice
|
import org.unifiedpush.distributor.nextpush.api.apiDeleteDevice
|
||||||
|
@ -83,7 +84,7 @@ class MainActivity : AppCompatActivity() {
|
||||||
try {
|
try {
|
||||||
ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(context)
|
ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(context)
|
||||||
} catch (e: NextcloudFilesAppAccountNotFoundException) {
|
} catch (e: NextcloudFilesAppAccountNotFoundException) {
|
||||||
UiExceptionManager.showDialogForException(context, e)
|
nextcloudAppNotInstalledDialog(context)
|
||||||
} catch (e: NoCurrentAccountSelectedException) {
|
} catch (e: NoCurrentAccountSelectedException) {
|
||||||
UiExceptionManager.showDialogForException(context, e)
|
UiExceptionManager.showDialogForException(context, e)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,9 @@ import android.util.Log
|
||||||
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException
|
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException
|
||||||
import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException
|
import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException
|
||||||
import com.nextcloud.android.sso.helper.SingleAccountHelper
|
import com.nextcloud.android.sso.helper.SingleAccountHelper
|
||||||
import com.nextcloud.android.sso.ui.UiExceptionManager
|
|
||||||
|
|
||||||
import org.unifiedpush.distributor.nextpush.account.ssoAccount
|
import org.unifiedpush.distributor.nextpush.account.ssoAccount
|
||||||
|
import org.unifiedpush.distributor.nextpush.account.nextcloudAppNotInstalledDialog
|
||||||
|
|
||||||
import android.net.Network
|
import android.net.Network
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ class StartService: Service(){
|
||||||
try {
|
try {
|
||||||
ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(this)
|
ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(this)
|
||||||
} catch (e: NextcloudFilesAppAccountNotFoundException) {
|
} catch (e: NextcloudFilesAppAccountNotFoundException) {
|
||||||
UiExceptionManager.showDialogForException(this, e)
|
nextcloudAppNotInstalledDialog(this)
|
||||||
} catch (e: NoCurrentAccountSelectedException) {
|
} catch (e: NoCurrentAccountSelectedException) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,4 +19,11 @@
|
||||||
<string name="warning_notif_description">NextPush is disconnected</string>
|
<string name="warning_notif_description">NextPush is disconnected</string>
|
||||||
<string name="warning_notif_ticker">Warning</string>
|
<string name="warning_notif_ticker">Warning</string>
|
||||||
<string name="listening_notif_ticker">Listening</string>
|
<string name="listening_notif_ticker">Listening</string>
|
||||||
|
<string name="message_missing_nextcloud_app">Nextcloud Files is not installed on your device.\nPlease install it</string>
|
||||||
|
<string name="uri_market_nextcloud_app">market://details?id=com.nextcloud.client</string>
|
||||||
|
<string name="market_chooser_title">Market</string>
|
||||||
|
<string name="install">Install</string>
|
||||||
|
<string name="dismiss">Dismiss</string>
|
||||||
|
<string name="uri_fdroid_nextcloud_app">https://f-droid.org/repository/browse/?fdid=com.nextcloud.client</string>
|
||||||
|
<string name="nextcloud_files_not_found_title">Nextcloud Files not found</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue