Set new login UI
This commit is contained in:
parent
3485a77e95
commit
120f0dea12
|
@ -17,8 +17,7 @@
|
|||
android:theme="@style/Theme.NextPush"
|
||||
android:networkSecurityConfig="@xml/network_security_config">
|
||||
<activity
|
||||
android:name=".activities.MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:name=".activities.StartActivity"
|
||||
android:theme="@style/Theme.NextPush.NoActionBar"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
|
@ -26,6 +25,10 @@
|
|||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activities.MainActivity"
|
||||
android:theme="@style/Theme.NextPush.NoActionBar">
|
||||
</activity>
|
||||
|
||||
<service
|
||||
android:name=".services.StartService"
|
||||
|
|
|
@ -1,26 +1,21 @@
|
|||
package org.unifiedpush.distributor.nextpush.activities
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.* // ktlint-disable no-wildcard-imports
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.view.isVisible
|
||||
import com.nextcloud.android.sso.AccountImporter
|
||||
import com.nextcloud.android.sso.AccountImporter.clearAllAuthTokens
|
||||
import org.unifiedpush.distributor.nextpush.R
|
||||
import org.unifiedpush.distributor.nextpush.account.Account.getAccount
|
||||
import org.unifiedpush.distributor.nextpush.account.Account.isConnected
|
||||
import org.unifiedpush.distributor.nextpush.activities.PermissionsRequest.requestAppPermissions
|
||||
import org.unifiedpush.distributor.nextpush.activities.StartActivity.Companion.goToStartActivity
|
||||
import org.unifiedpush.distributor.nextpush.distributor.Distributor.deleteApp
|
||||
import org.unifiedpush.distributor.nextpush.distributor.Distributor.deleteDevice
|
||||
import org.unifiedpush.distributor.nextpush.distributor.Distributor.getDb
|
||||
|
@ -34,42 +29,17 @@ class MainActivity : AppCompatActivity() {
|
|||
|
||||
private lateinit var listView: ListView
|
||||
private var showLogout = false
|
||||
private var onResult: ((activity: Activity, requestCode: Int, resultCode: Int, data: Intent?, block: (success: Boolean) -> Unit) -> Unit)? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
setSupportActionBar(findViewById(R.id.toolbar))
|
||||
requestPermissions()
|
||||
if (isConnected(this)) {
|
||||
showMain()
|
||||
} else {
|
||||
findViewById<Button>(R.id.button_connection).setOnClickListener {
|
||||
getAccount(this, uninitialized = true)?.let {
|
||||
onResult = { activity: Activity, i: Int, i1: Int, intent: Intent?, block: (success: Boolean) -> Unit ->
|
||||
it.onActivityResult(activity, i, i1, intent, block)
|
||||
}
|
||||
it.connect(this)
|
||||
}
|
||||
}
|
||||
showStart()
|
||||
this.requestAppPermissions()
|
||||
if (!isConnected(this)) {
|
||||
goToStartActivity(this)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
onResult?.let {
|
||||
it(this, requestCode, resultCode, data) { success ->
|
||||
if (success) {
|
||||
showMain()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showMain() {
|
||||
findViewById<ConstraintLayout>(R.id.sub_start).isVisible = false
|
||||
findViewById<ConstraintLayout>(R.id.sub_main).isVisible = true
|
||||
findViewById<TextView>(R.id.main_account_desc).text =
|
||||
format(getString(R.string.main_account_desc), getAccount(this)?.name)
|
||||
showLogout = true
|
||||
|
@ -77,41 +47,6 @@ class MainActivity : AppCompatActivity() {
|
|||
RestartWorker.startPeriodic(this)
|
||||
}
|
||||
|
||||
private fun showStart() {
|
||||
findViewById<ConstraintLayout>(R.id.sub_start).isVisible = true
|
||||
findViewById<ConstraintLayout>(R.id.sub_main).isVisible = false
|
||||
showLogout = false
|
||||
invalidateOptionsMenu()
|
||||
}
|
||||
|
||||
private fun requestPermissions() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
if (checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS)
|
||||
!= PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
Log.d(TAG, "Requesting POST_NOTIFICATIONS permission")
|
||||
registerForActivityResult(
|
||||
ActivityResultContracts.RequestPermission()
|
||||
) { granted ->
|
||||
Log.d(TAG, "POST_NOTIFICATIONS permission granted: $granted")
|
||||
if (granted) {
|
||||
restart()
|
||||
} else {
|
||||
if (shouldShowRequestPermissionRationale(Manifest.permission.POST_NOTIFICATIONS)) {
|
||||
Log.d(TAG, "Show POST_NOTIFICATIONS permission rationale")
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(getString(R.string.no_notification_dialog_title))
|
||||
.setMessage(R.string.no_notification_dialog_message)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
}.launch(
|
||||
Manifest.permission.POST_NOTIFICATIONS
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
||||
super.onWindowFocusChanged(hasFocus)
|
||||
if (hasFocus) {
|
||||
|
@ -121,8 +56,6 @@ class MainActivity : AppCompatActivity() {
|
|||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_main, menu)
|
||||
menu.findItem(R.id.action_restart).isEnabled = showLogout
|
||||
menu.findItem(R.id.action_logout).isEnabled = showLogout
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -166,9 +99,8 @@ class MainActivity : AppCompatActivity() {
|
|||
StartService.stopService()
|
||||
FailureHandler.clearFails()
|
||||
}
|
||||
showStart()
|
||||
finish()
|
||||
startActivity(intent)
|
||||
goToStartActivity(this)
|
||||
}
|
||||
alert.setNegativeButton(getString(R.string.discard)) { dialog, _ -> dialog.dismiss() }
|
||||
alert.show()
|
||||
|
@ -216,4 +148,13 @@ class MainActivity : AppCompatActivity() {
|
|||
}
|
||||
)
|
||||
}
|
||||
companion object {
|
||||
fun goToMainActivity(context: Context) {
|
||||
val intent = Intent(
|
||||
context,
|
||||
MainActivity::class.java
|
||||
)
|
||||
context.startActivity(intent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package org.unifiedpush.distributor.nextpush.activities
|
||||
|
||||
import android.Manifest
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import org.unifiedpush.distributor.nextpush.R
|
||||
import org.unifiedpush.distributor.nextpush.utils.TAG
|
||||
|
||||
object PermissionsRequest {
|
||||
|
||||
fun AppCompatActivity.requestAppPermissions() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
if (checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS)
|
||||
!= PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
Log.d(TAG, "Requesting POST_NOTIFICATIONS permission")
|
||||
this.registerForActivityResult(
|
||||
ActivityResultContracts.RequestPermission()
|
||||
) { granted ->
|
||||
Log.d(TAG, "POST_NOTIFICATIONS permission granted: $granted")
|
||||
if (!granted) {
|
||||
if (shouldShowRequestPermissionRationale(Manifest.permission.POST_NOTIFICATIONS)) {
|
||||
Log.d(TAG, "Show POST_NOTIFICATIONS permission rationale")
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(getString(R.string.no_notification_dialog_title))
|
||||
.setMessage(R.string.no_notification_dialog_message)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
}.launch(
|
||||
Manifest.permission.POST_NOTIFICATIONS
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package org.unifiedpush.distributor.nextpush.activities
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.widget.Button
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import org.unifiedpush.distributor.nextpush.R
|
||||
import org.unifiedpush.distributor.nextpush.account.Account
|
||||
import org.unifiedpush.distributor.nextpush.activities.MainActivity.Companion.goToMainActivity
|
||||
import org.unifiedpush.distributor.nextpush.activities.PermissionsRequest.requestAppPermissions
|
||||
|
||||
class StartActivity : AppCompatActivity() {
|
||||
private var onResult: ((activity: Activity, requestCode: Int, resultCode: Int, data: Intent?, block: (success: Boolean) -> Unit) -> Unit)? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_start)
|
||||
this.requestAppPermissions()
|
||||
if (Account.isConnected(this)) {
|
||||
goToMainActivity(this)
|
||||
finish()
|
||||
}
|
||||
findViewById<Button>(R.id.sso_connection).setOnClickListener {
|
||||
Account.getAccount(this, uninitialized = true)?.let {
|
||||
onResult = { activity: Activity, i: Int, i1: Int, intent: Intent?, block: (success: Boolean) -> Unit ->
|
||||
it.onActivityResult(activity, i, i1, intent, block)
|
||||
}
|
||||
it.connect(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
onResult?.let {
|
||||
it(this, requestCode, resultCode, data) { success ->
|
||||
if (success) {
|
||||
goToMainActivity(this)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun goToStartActivity(context: Context) {
|
||||
val intent = Intent(
|
||||
context,
|
||||
StartActivity::class.java
|
||||
)
|
||||
context.startActivity(intent)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -62,7 +62,7 @@ object NotificationUtils {
|
|||
return builder
|
||||
.setContentTitle(context.getString(R.string.app_name))
|
||||
.setContentText(context.getString(R.string.foreground_notif_description))
|
||||
.setSmallIcon(R.drawable.ic_launcher_notification)
|
||||
.setSmallIcon(R.drawable.ic_logo)
|
||||
.setTicker(context.getString(R.string.foreground_notif_ticker))
|
||||
.setPriority(Notification.PRIORITY_LOW) // for under android 26 compatibility
|
||||
.setContentIntent(intent)
|
||||
|
@ -112,7 +112,7 @@ object NotificationUtils {
|
|||
}
|
||||
).setContentTitle(context.getString(R.string.app_name))
|
||||
.setContentText(context.getString(R.string.warning_notif_description))
|
||||
.setSmallIcon(R.drawable.ic_launcher_notification)
|
||||
.setSmallIcon(R.drawable.ic_logo)
|
||||
.setTicker(context.getString(R.string.warning_notif_ticker))
|
||||
.setPriority(Notification.PRIORITY_HIGH) // for under android 26 compatibility
|
||||
.setContentIntent(intent)
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
android:viewportHeight="108">
|
||||
<group android:scaleX="8"
|
||||
android:scaleY="8"
|
||||
android:translateX="8"
|
||||
android:translateY="8">
|
||||
android:translateX="4"
|
||||
android:translateY="4">
|
||||
<path
|
||||
android:pathData="M6.35,0.7937A5.5563,5.5563 0,0 0,0.7937 6.35,5.5563 5.5563,0 0,0 6.35,11.9063 5.5563,5.5563 0,0 0,11.9063 6.35,5.5563 5.5563,0 0,0 6.35,0.7937ZM6.35,2.1167A4.2333,4.2333 0,0 1,10.5833 6.35,4.2333 4.2333,0 0,1 6.35,10.5833 4.2333,4.2333 0,0 1,2.1167 6.35,4.2333 4.2333,0 0,1 6.35,2.1167Z"
|
||||
android:strokeWidth="0.291905"
|
|
@ -24,8 +24,4 @@
|
|||
android:id="@+id/sub_main"
|
||||
layout="@layout/content_main" />
|
||||
|
||||
<include
|
||||
android:id="@+id/sub_start"
|
||||
layout="@layout/content_start" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="org.unifiedpush.distributor.nextpush.activities.StartActivity">
|
||||
|
||||
<include
|
||||
android:id="@+id/sub_start"
|
||||
layout="@layout/content_start" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
|
@ -4,29 +4,69 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/nextcloud"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_connection"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:text="@string/connection_button"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView3" />
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView3"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:text="@string/connection_description"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
<ImageView
|
||||
android:id="@+id/img_nextcloud_logo"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="130dp"
|
||||
android:contentDescription="NextPush Logo"
|
||||
android:gravity="center"
|
||||
android:src="@drawable/ic_logo"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="1dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/app_name"
|
||||
android:textColor="@color/material_grey_100"
|
||||
android:textSize="20sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintTop_toBottomOf="@+id/img_nextcloud_logo" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/sso_connection"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="32dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="32dp"
|
||||
android:backgroundTint="@color/white"
|
||||
android:padding="16dp"
|
||||
android:text="@string/sso_connection_button"
|
||||
android:textAllCaps="false"
|
||||
android:textColor="@color/nextcloud"
|
||||
android:textStyle="bold"
|
||||
app:cornerRadius="24dp"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView3" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/manual_login"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/manual_login"
|
||||
android:textColor="@color/material_grey_100"
|
||||
app:layout_constraintTop_toBottomOf="@+id/sso_connection" />
|
||||
|
||||
</LinearLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -6,8 +6,7 @@
|
|||
|
||||
<string name="help"></string>
|
||||
<string name="foreground_notif_description">Notification to run in the foreground</string>
|
||||
<string name="connection_button">Login</string>
|
||||
<string name="connection_description">You are not connected to Nextcloud yet</string>
|
||||
<string name="sso_connection_button">Login with the Nextcloud File application</string>
|
||||
<string name="action_logout">Logout</string>
|
||||
<string name="logout_alert_title">Logout</string>
|
||||
<string name="logout_alert_content">Confirm to logout</string>
|
||||
|
@ -28,4 +27,5 @@
|
|||
<string name="nextcloud_files_not_found_title">Nextcloud Files not found</string>
|
||||
<string name="no_notification_dialog_title">Notifications refused</string>
|
||||
<string name="no_notification_dialog_message">You won\'t be notified when the application is disconnected.\nYou can enable notifications later in the settings.</string>
|
||||
<string name="manual_login">Manual login</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue