diff --git a/android/app/build.gradle b/android/app/build.gradle index da054bc..c195467 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -55,9 +55,10 @@ dependencies { implementation 'androidx.core:core-ktx:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.recyclerview:recyclerview:1.0.0' - implementation 'com.google.android.material:material:1.0.0' + implementation 'com.google.android.material:material:1.1.0-alpha10' implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0' - implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0" + implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0' + implementation 'androidx.lifecycle:lifecycle-reactivestreams:2.1.0' implementation "io.reactivex.rxjava2:rxjava:2.2.12" implementation "io.reactivex.rxjava2:rxkotlin:2.4.0" implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' diff --git a/android/app/src/main/java/com/metallic/chiaki/common/DisplayHost.kt b/android/app/src/main/java/com/metallic/chiaki/common/DisplayHost.kt index 00f4d21..841da65 100644 --- a/android/app/src/main/java/com/metallic/chiaki/common/DisplayHost.kt +++ b/android/app/src/main/java/com/metallic/chiaki/common/DisplayHost.kt @@ -22,14 +22,21 @@ import com.metallic.chiaki.lib.DiscoveryHost sealed class DisplayHost { abstract val registeredHost: RegisteredHost? + abstract val host: String } -class DiscoveredDisplayServer( +class DiscoveredDisplayHost( override val registeredHost: RegisteredHost?, val discoveredHost: DiscoveryHost ): DisplayHost() +{ + override val host get() = discoveredHost.hostAddr ?: "" +} -class ManualDisplayServer( +class ManualDisplayHost( override val registeredHost: RegisteredHost?, val manualHost: ManualHost -): DisplayHost() \ No newline at end of file +): DisplayHost() +{ + override val host get() = manualHost.host +} \ No newline at end of file diff --git a/android/app/src/main/java/com/metallic/chiaki/common/ext/PublisherLiveData.kt b/android/app/src/main/java/com/metallic/chiaki/common/ext/PublisherLiveData.kt new file mode 100644 index 0000000..c370604 --- /dev/null +++ b/android/app/src/main/java/com/metallic/chiaki/common/ext/PublisherLiveData.kt @@ -0,0 +1,23 @@ +/* + * This file is part of Chiaki. + * + * Chiaki is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Chiaki is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chiaki. If not, see . + */ + +package com.metallic.chiaki.common.ext + +import androidx.lifecycle.LiveDataReactiveStreams +import org.reactivestreams.Publisher + +fun Publisher.toLiveData() = LiveDataReactiveStreams.fromPublisher(this) \ No newline at end of file diff --git a/android/app/src/main/java/com/metallic/chiaki/common/ext/ViewGroupInflate.kt b/android/app/src/main/java/com/metallic/chiaki/common/ext/ViewGroupInflate.kt new file mode 100644 index 0000000..b811a5c --- /dev/null +++ b/android/app/src/main/java/com/metallic/chiaki/common/ext/ViewGroupInflate.kt @@ -0,0 +1,28 @@ +/* + * This file is part of Chiaki. + * + * Chiaki is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Chiaki is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chiaki. If not, see . + */ + +package com.metallic.chiaki.common.ext + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.annotation.LayoutRes + +fun ViewGroup.inflate(@LayoutRes layoutRes: Int, attachToRoot: Boolean = false): View +{ + return LayoutInflater.from(context).inflate(layoutRes, this, attachToRoot) +} \ No newline at end of file diff --git a/android/app/src/main/java/com/metallic/chiaki/common/ext/ViewModelFactory.kt b/android/app/src/main/java/com/metallic/chiaki/common/ext/ViewModelFactory.kt new file mode 100644 index 0000000..addfab3 --- /dev/null +++ b/android/app/src/main/java/com/metallic/chiaki/common/ext/ViewModelFactory.kt @@ -0,0 +1,11 @@ +package com.metallic.chiaki.common.ext + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.ViewModelProvider + +inline fun viewModelFactory(crossinline f: () -> T) = + object : ViewModelProvider.Factory + { + @Suppress("UNCHECKED_CAST") + override fun create(aClass: Class): T = f() as T + } \ No newline at end of file diff --git a/android/app/src/main/java/com/metallic/chiaki/lib/Chiaki.kt b/android/app/src/main/java/com/metallic/chiaki/lib/Chiaki.kt index f1e638c..5a197b9 100644 --- a/android/app/src/main/java/com/metallic/chiaki/lib/Chiaki.kt +++ b/android/app/src/main/java/com/metallic/chiaki/lib/Chiaki.kt @@ -181,14 +181,14 @@ class Session(connectInfo: ConnectInfo) data class DiscoveryHost( val state: State, val hostRequestPort: UShort, - val host_addr: String?, - val system_version: String?, - val device_discovery_protocol_version: String?, - val host_name: String?, - val host_type: String?, - val host_id: String?, - val running_app_titleid: String?, - val running_app_name: String?) + val hostAddr: String?, + val systemVersion: String?, + val deviceDiscoveryProtocolVersion: String?, + val hostName: String?, + val hostType: String?, + val hostId: String?, + val runningAppTitleid: String?, + val runningAppName: String?) { enum class State { diff --git a/android/app/src/main/java/com/metallic/chiaki/main/DisplayHostRecyclerViewAdapter.kt b/android/app/src/main/java/com/metallic/chiaki/main/DisplayHostRecyclerViewAdapter.kt new file mode 100644 index 0000000..93e7ba9 --- /dev/null +++ b/android/app/src/main/java/com/metallic/chiaki/main/DisplayHostRecyclerViewAdapter.kt @@ -0,0 +1,51 @@ +/* + * This file is part of Chiaki. + * + * Chiaki is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Chiaki is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chiaki. If not, see . + */ + +package com.metallic.chiaki.main + +import android.view.View +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import com.metallic.chiaki.R +import com.metallic.chiaki.common.DisplayHost +import com.metallic.chiaki.common.ext.inflate +import kotlinx.android.synthetic.main.item_display_host.view.* + +class DisplayHostRecyclerViewAdapter: RecyclerView.Adapter() +{ + var hosts: List = listOf() + set(value) + { + field = value + notifyDataSetChanged() + } + + class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) + = ViewHolder(parent.inflate(R.layout.item_display_host)) + + override fun getItemCount() = hosts.count() + + override fun onBindViewHolder(holder: ViewHolder, position: Int) + { + val host = hosts[position] + holder.itemView.also { + it.hostTextView.text = host.host + } + } +} \ No newline at end of file diff --git a/android/app/src/main/java/com/metallic/chiaki/main/MainActivity.kt b/android/app/src/main/java/com/metallic/chiaki/main/MainActivity.kt index 69c743d..309cb51 100644 --- a/android/app/src/main/java/com/metallic/chiaki/main/MainActivity.kt +++ b/android/app/src/main/java/com/metallic/chiaki/main/MainActivity.kt @@ -21,16 +21,14 @@ import android.app.ActivityOptions import android.content.Intent import androidx.appcompat.app.AppCompatActivity import android.os.Bundle -import android.util.Log +import androidx.lifecycle.Observer +import androidx.lifecycle.ViewModelProviders +import androidx.recyclerview.widget.LinearLayoutManager import com.metallic.chiaki.R import com.metallic.chiaki.TestStartActivity -import com.metallic.chiaki.common.ManualHost import com.metallic.chiaki.common.getDatabase -import io.reactivex.Completable -import io.reactivex.Observable -import io.reactivex.android.schedulers.AndroidSchedulers +import com.metallic.chiaki.common.ext.viewModelFactory import io.reactivex.disposables.CompositeDisposable -import io.reactivex.schedulers.Schedulers import kotlinx.android.synthetic.main.activity_main.* class MainActivity : AppCompatActivity() @@ -50,18 +48,14 @@ class MainActivity : AppCompatActivity() } } - /*val db = getDatabase(this) - Completable.mergeArray( - db.manualHostDao().insert(ManualHost(host = "test", registeredHost = null)), - db.manualHostDao().insert(ManualHost(host = "adsgsdfgdsfg", registeredHost = null)), - db.manualHostDao().insert(ManualHost(host = "sdfgsdfg", registeredHost = null)) - ).andThen(db.manualHostDao().getAll()) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe { - Log.i("MainActivity", "got $it") - } - .also { disposable.add(it) }*/ + val viewModel = ViewModelProviders + .of(this, viewModelFactory { MainViewModel(getDatabase(this)) }) + .get(MainViewModel::class.java) + + val recyclerViewAdapter = DisplayHostRecyclerViewAdapter() + hostsRecyclerView.adapter = recyclerViewAdapter + hostsRecyclerView.layoutManager = LinearLayoutManager(this) + viewModel.displayHosts.observe(this, Observer { recyclerViewAdapter.hosts = it }) } override fun onDestroy() diff --git a/android/app/src/main/java/com/metallic/chiaki/main/MainViewModel.kt b/android/app/src/main/java/com/metallic/chiaki/main/MainViewModel.kt index cd9ee39..ead0ec0 100644 --- a/android/app/src/main/java/com/metallic/chiaki/main/MainViewModel.kt +++ b/android/app/src/main/java/com/metallic/chiaki/main/MainViewModel.kt @@ -18,8 +18,19 @@ package com.metallic.chiaki.main import androidx.lifecycle.ViewModel +import com.metallic.chiaki.common.AppDatabase +import com.metallic.chiaki.common.ManualDisplayHost +import com.metallic.chiaki.common.ext.toLiveData -class MainViewModel: ViewModel() +class MainViewModel(val database: AppDatabase): ViewModel() { - + val displayHosts by lazy { + database.manualHostDao().getAll() + .map { + it.map { manualHost -> + ManualDisplayHost(null, manualHost) + } + } + .toLiveData() + } } \ No newline at end of file diff --git a/android/app/src/main/res/drawable/ic_console.xml b/android/app/src/main/res/drawable/ic_console.xml new file mode 100644 index 0000000..0ed1bc8 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_console.xml @@ -0,0 +1,13 @@ + + + diff --git a/android/app/src/main/res/drawable/ic_console_ready.xml b/android/app/src/main/res/drawable/ic_console_ready.xml new file mode 100644 index 0000000..177e2a6 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_console_ready.xml @@ -0,0 +1,20 @@ + + + + diff --git a/android/app/src/main/res/drawable/ic_console_standby.xml b/android/app/src/main/res/drawable/ic_console_standby.xml new file mode 100644 index 0000000..177e2a6 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_console_standby.xml @@ -0,0 +1,20 @@ + + + + diff --git a/android/app/src/main/res/layout/activity_main.xml b/android/app/src/main/res/layout/activity_main.xml index a6810b2..3f3a61a 100644 --- a/android/app/src/main/res/layout/activity_main.xml +++ b/android/app/src/main/res/layout/activity_main.xml @@ -1,15 +1,9 @@ - - - + android:layout_width="match_parent" + android:layout_height="match_parent"> + android:layout_gravity="bottom|end" /> - \ No newline at end of file + + + + + + + + + + + \ No newline at end of file diff --git a/android/app/src/main/res/layout/item_display_host.xml b/android/app/src/main/res/layout/item_display_host.xml new file mode 100644 index 0000000..0b44552 --- /dev/null +++ b/android/app/src/main/res/layout/item_display_host.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml index 6c56835..ff94885 100644 --- a/android/app/src/main/res/values/strings.xml +++ b/android/app/src/main/res/values/strings.xml @@ -1,5 +1,6 @@ Chiaki + Chiaki 千秋 Session has quit: %s Failed to create Session: %s Login PIN: diff --git a/android/app/src/main/res/values/styles.xml b/android/app/src/main/res/values/styles.xml index 0d16439..f36dbcb 100644 --- a/android/app/src/main/res/values/styles.xml +++ b/android/app/src/main/res/values/styles.xml @@ -1,8 +1,13 @@ - diff --git a/assets/console.svg b/assets/console.svg new file mode 100644 index 0000000..00fba66 --- /dev/null +++ b/assets/console.svg @@ -0,0 +1,74 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + +