Skip to content
Snippets Groups Projects
Commit b5729f45 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Integrated account setup with the test activity

parent f6975e69
Branches
Tags
No related merge requests found
...@@ -17,14 +17,7 @@ ...@@ -17,14 +17,7 @@
android:exported="true" android:exported="true"
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@style/SplashTheme" android:theme="@style/SplashTheme"
android:windowSoftInputMode="adjustResize"> android:windowSoftInputMode="adjustResize" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity <activity
android:name=".ui.setup.accounts.AccountSetupActivity" android:name=".ui.setup.accounts.AccountSetupActivity"
android:exported="false" android:exported="false"
...@@ -38,11 +31,18 @@ ...@@ -38,11 +31,18 @@
android:theme="@style/SplashTheme" android:theme="@style/SplashTheme"
android:windowSoftInputMode="adjustResize" /> android:windowSoftInputMode="adjustResize" />
<activity <activity
android:name="de.kuschku.quasseldroid_ng.ui.setup.accounts.AccountSelectionActivity" android:name=".ui.setup.accounts.AccountSelectionActivity"
android:exported="true" android:exported="true"
android:label="AccountSelection" android:label="AccountSelection"
android:theme="@style/SplashTheme" android:theme="@style/SplashTheme"
android:windowSoftInputMode="adjustResize" /> android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service <service
android:name=".service.QuasselService" android:name=".service.QuasselService"
......
...@@ -29,7 +29,7 @@ abstract class AccountDatabase : RoomDatabase() { ...@@ -29,7 +29,7 @@ abstract class AccountDatabase : RoomDatabase() {
fun create(vararg entities: AccountDatabase.Account): Array<Long> fun create(vararg entities: AccountDatabase.Account): Array<Long>
@Query("SELECT * FROM account WHERE id = :id") @Query("SELECT * FROM account WHERE id = :id")
fun findById(id: Long): AccountDatabase.Account fun findById(id: Long): AccountDatabase.Account?
@Query("SELECT * FROM account ORDER BY lastUsed DESC") @Query("SELECT * FROM account ORDER BY lastUsed DESC")
fun all(): LivePagedListProvider<Int, Account> fun all(): LivePagedListProvider<Int, Account>
......
package de.kuschku.quasseldroid_ng.ui package de.kuschku.quasseldroid_ng.ui
import android.app.Activity
import android.arch.lifecycle.LiveDataReactiveStreams import android.arch.lifecycle.LiveDataReactiveStreams
import android.arch.lifecycle.Observer import android.arch.lifecycle.Observer
import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.os.Handler
import android.os.HandlerThread
import android.support.design.widget.Snackbar import android.support.design.widget.Snackbar
import android.util.Log import android.util.Log
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.widget.Button import android.widget.Button
import android.widget.EditText
import android.widget.TextView import android.widget.TextView
import butterknife.BindView import butterknife.BindView
import butterknife.ButterKnife import butterknife.ButterKnife
...@@ -18,7 +21,9 @@ import de.kuschku.libquassel.session.ConnectionState ...@@ -18,7 +21,9 @@ import de.kuschku.libquassel.session.ConnectionState
import de.kuschku.libquassel.session.SocketAddress import de.kuschku.libquassel.session.SocketAddress
import de.kuschku.libquassel.util.compatibility.LoggingHandler import de.kuschku.libquassel.util.compatibility.LoggingHandler
import de.kuschku.quasseldroid_ng.R import de.kuschku.quasseldroid_ng.R
import de.kuschku.quasseldroid_ng.persistence.AccountDatabase
import de.kuschku.quasseldroid_ng.service.QuasselService import de.kuschku.quasseldroid_ng.service.QuasselService
import de.kuschku.quasseldroid_ng.util.helper.editApply
import de.kuschku.quasseldroid_ng.util.helper.stickyMapNotNull import de.kuschku.quasseldroid_ng.util.helper.stickyMapNotNull
import de.kuschku.quasseldroid_ng.util.helper.stickySwitchMapNotNull import de.kuschku.quasseldroid_ng.util.helper.stickySwitchMapNotNull
import org.threeten.bp.ZoneOffset import org.threeten.bp.ZoneOffset
...@@ -26,18 +31,6 @@ import org.threeten.bp.ZonedDateTime ...@@ -26,18 +31,6 @@ import org.threeten.bp.ZonedDateTime
import org.threeten.bp.format.DateTimeFormatter import org.threeten.bp.format.DateTimeFormatter
class ChatActivity : ServiceBoundActivity() { class ChatActivity : ServiceBoundActivity() {
@BindView(R.id.host)
lateinit var host: EditText
@BindView(R.id.port)
lateinit var port: EditText
@BindView(R.id.user)
lateinit var user: EditText
@BindView(R.id.pass)
lateinit var pass: EditText
@BindView(R.id.connect) @BindView(R.id.connect)
lateinit var connect: Button lateinit var connect: Button
...@@ -50,6 +43,9 @@ class ChatActivity : ServiceBoundActivity() { ...@@ -50,6 +43,9 @@ class ChatActivity : ServiceBoundActivity() {
@BindView(R.id.errorList) @BindView(R.id.errorList)
lateinit var errorList: TextView lateinit var errorList: TextView
private val thread = HandlerThread("Chat")
private lateinit var handler: Handler
private val state = backend.stickyMapNotNull(null, Backend::sessionManager) private val state = backend.stickyMapNotNull(null, Backend::sessionManager)
.stickySwitchMapNotNull(ConnectionState.DISCONNECTED) { session -> .stickySwitchMapNotNull(ConnectionState.DISCONNECTED) { session ->
LiveDataReactiveStreams.fromPublisher(session.state) LiveDataReactiveStreams.fromPublisher(session.state)
...@@ -58,7 +54,7 @@ class ChatActivity : ServiceBoundActivity() { ...@@ -58,7 +54,7 @@ class ChatActivity : ServiceBoundActivity() {
private var snackbar: Snackbar? = null private var snackbar: Snackbar? = null
private val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_TIME private val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_TIME
private val handler = object : LoggingHandler() { private val logHandler = object : LoggingHandler() {
override fun log(logLevel: LogLevel, tag: String, message: String?, throwable: Throwable?) { override fun log(logLevel: LogLevel, tag: String, message: String?, throwable: Throwable?) {
val time = dateTimeFormatter.format(ZonedDateTime.now(ZoneOffset.UTC)) val time = dateTimeFormatter.format(ZonedDateTime.now(ZoneOffset.UTC))
runOnUiThread { runOnUiThread {
...@@ -78,18 +74,40 @@ class ChatActivity : ServiceBoundActivity() { ...@@ -78,18 +74,40 @@ class ChatActivity : ServiceBoundActivity() {
= (logLevel.ordinal >= LogLevel.INFO.ordinal) = (logLevel.ordinal >= LogLevel.INFO.ordinal)
} }
var account: AccountDatabase.Account? = null
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
thread.start()
handler = Handler(thread.looper)
startService(Intent(this, QuasselService::class.java)) startService(Intent(this, QuasselService::class.java))
setTheme(R.style.AppTheme) setTheme(R.style.AppTheme)
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
ButterKnife.bind(this) ButterKnife.bind(this)
val database = AccountDatabase.Creator.init(this)
handler.post {
val accountId = getSharedPreferences("status", Context.MODE_PRIVATE)
?.getLong(selectedAccountKey, -1) ?: -1
if (accountId == -1L) {
setResult(Activity.RESULT_CANCELED)
finish()
}
val it = database.accounts().findById(accountId)
if (it == null) {
setResult(Activity.RESULT_CANCELED)
finish()
}
account = it
}
connect.setOnClickListener { connect.setOnClickListener {
val account = account
if (account != null)
backend.value?.connect( backend.value?.connect(
SocketAddress(host.text.toString(), port.text.toString().toShort()), SocketAddress(account.host, account.port.toShort()),
user.text.toString(), account.user,
pass.text.toString() account.pass
) )
} }
...@@ -120,16 +138,27 @@ class ChatActivity : ServiceBoundActivity() { ...@@ -120,16 +138,27 @@ class ChatActivity : ServiceBoundActivity() {
} }
override fun onOptionsItemSelected(item: MenuItem?) = when (item?.itemId) { override fun onOptionsItemSelected(item: MenuItem?) = when (item?.itemId) {
R.id.disconnect -> {
getSharedPreferences("status", Context.MODE_PRIVATE).editApply {
putBoolean("reconnect", false)
}
finish()
true
}
else -> super.onOptionsItemSelected(item) else -> super.onOptionsItemSelected(item)
} }
override fun onStart() { override fun onStart() {
super.onStart() super.onStart()
LoggingHandler.loggingHandlers.add(handler) LoggingHandler.loggingHandlers.add(logHandler)
} }
override fun onStop() { override fun onStop() {
LoggingHandler.loggingHandlers.remove(handler) LoggingHandler.loggingHandlers.remove(logHandler)
super.onStop() super.onStop()
} }
companion object {
private const val selectedAccountKey = "selectedAccount"
}
} }
package de.kuschku.quasseldroid_ng.ui.setup.accounts package de.kuschku.quasseldroid_ng.ui.setup.accounts
import android.content.Context import android.content.Context
import android.content.Intent
import android.content.SharedPreferences import android.content.SharedPreferences
import android.os.Bundle import android.os.Bundle
import de.kuschku.quasseldroid_ng.ui.ChatActivity
import de.kuschku.quasseldroid_ng.ui.setup.SetupActivity import de.kuschku.quasseldroid_ng.ui.setup.SetupActivity
import de.kuschku.quasseldroid_ng.util.helper.editCommit import de.kuschku.quasseldroid_ng.util.helper.editCommit
...@@ -15,15 +17,22 @@ class AccountSelectionActivity : SetupActivity() { ...@@ -15,15 +17,22 @@ class AccountSelectionActivity : SetupActivity() {
override fun onDone(data: Bundle) { override fun onDone(data: Bundle) {
statusPreferences.editCommit { statusPreferences.editCommit {
putLong(selectedAccountKey, data.getLong(selectedAccountKey, -1)) putLong(selectedAccountKey, data.getLong(selectedAccountKey, -1))
putBoolean("reconnect", true)
} }
startActivity(Intent(this, ChatActivity::class.java))
} }
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
statusPreferences = this.getSharedPreferences("status", Context.MODE_PRIVATE) statusPreferences = this.getSharedPreferences("status", Context.MODE_PRIVATE)
val data = Bundle() val data = Bundle()
data.putLong(selectedAccountKey, statusPreferences.getLong(selectedAccountKey, -1)) val selectedAccount = statusPreferences.getLong(selectedAccountKey, -1)
data.putLong(selectedAccountKey, selectedAccount)
setInitData(data) setInitData(data)
if (statusPreferences.getBoolean("reconnect", false) && selectedAccount != -1L) {
startActivity(Intent(this, ChatActivity::class.java))
}
} }
companion object { companion object {
......
...@@ -12,61 +12,6 @@ ...@@ -12,61 +12,6 @@
android:paddingLeft="24dp" android:paddingLeft="24dp"
android:paddingRight="24dp"> android:paddingRight="24dp">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/host"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Host"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/port"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Port"
android:inputType="number"
android:maxLines="1"
android:singleLine="true"
android:text="4242" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/pass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
......
...@@ -3,4 +3,7 @@ ...@@ -3,4 +3,7 @@
<item <item
android:id="@+id/settings" android:id="@+id/settings"
android:title="Settings" /> android:title="Settings" />
<item
android:id="@+id/disconnect"
android:title="Disconnect" />
</menu> </menu>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment