Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

Commit

Permalink
App: Shortcuts to launch floating
Browse files Browse the repository at this point in the history
Signed-off-by: Siubeng Fung <[email protected]>
  • Loading branch information
fython committed Feb 21, 2020
1 parent 666c9ca commit e504dc6
Show file tree
Hide file tree
Showing 22 changed files with 435 additions and 28 deletions.
102 changes: 102 additions & 0 deletions app/schemas/moe.feng.danmaqua.data.DanmaquaDB/3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"formatVersion": 1,
"database": {
"version": 3,
"identityHash": "73c802a8a8186714e00eb71577ac5174",
"entities": [
{
"tableName": "Subscription",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`uid` INTEGER NOT NULL, `room_id` INTEGER NOT NULL, `username` TEXT NOT NULL, `avatar` TEXT NOT NULL, `order` INTEGER NOT NULL, `selected` INTEGER NOT NULL, `favourite` INTEGER NOT NULL, PRIMARY KEY(`uid`))",
"fields": [
{
"fieldPath": "uid",
"columnName": "uid",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "roomId",
"columnName": "room_id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "username",
"columnName": "username",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "avatar",
"columnName": "avatar",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "order",
"columnName": "order",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "selected",
"columnName": "selected",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "favourite",
"columnName": "favourite",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"uid"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "blocked_user_rule",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`uid` INTEGER NOT NULL, `username` TEXT NOT NULL, `face` TEXT, PRIMARY KEY(`uid`))",
"fields": [
{
"fieldPath": "uid",
"columnName": "uid",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "username",
"columnName": "username",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "face",
"columnName": "face",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"uid"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '73c802a8a8186714e00eb71577ac5174')"
]
}
}
13 changes: 13 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.INSTALL_SHORTCUT"/>
<uses-permission android:name="android.permission.UNINSTALL_SHORTCUT"/>

<application
android:name=".DanmaquaApplication"
Expand Down Expand Up @@ -101,6 +103,17 @@
</intent-filter>
</activity>

<activity
android:name=".ui.proxy.QuickStartShortcutActivity"
android:theme="@style/Theme.EmptyActivity"
android:excludeFromRecents="true"
android:noHistory="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
</intent-filter>
</activity>

<service
android:name=".service.DanmakuListenerService"
android:label="@string/listener_service_label"
Expand Down
30 changes: 20 additions & 10 deletions app/src/main/java/moe/feng/danmaqua/data/DanmaquaDB.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import moe.feng.danmaqua.model.Subscription
@Database(entities = [
Subscription::class,
BlockedUserRule::class
], version = 2)
], version = 3)
abstract class DanmaquaDB : RoomDatabase() {

companion object {
Expand All @@ -25,15 +25,9 @@ abstract class DanmaquaDB : RoomDatabase() {
fun init(context: Context) {
val appContext = if (context is Application) context else context.applicationContext
if (!::instance.isInitialized) {
instance = Room.databaseBuilder(
appContext,
DanmaquaDB::class.java,
DATABASE_NAME
).addMigrations(object : Migration(1, 2) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("CREATE TABLE IF NOT EXISTS `blocked_user_rule` (`uid` INTEGER NOT NULL, `username` TEXT NOT NULL, `face` TEXT, PRIMARY KEY(`uid`))")
}
}).build()
instance = Room.databaseBuilder(appContext, DanmaquaDB::class.java, DATABASE_NAME)
.addMigrations(MigrationV1ToV2, MigrationV2ToV3)
.build()
}
}

Expand All @@ -43,4 +37,20 @@ abstract class DanmaquaDB : RoomDatabase() {

abstract fun blockedUsers(): BlockedUserRulesDao

object MigrationV1ToV2 : Migration(1, 2) {

override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("CREATE TABLE IF NOT EXISTS `blocked_user_rule` (`uid` INTEGER NOT NULL, `username` TEXT NOT NULL, `face` TEXT, PRIMARY KEY(`uid`))")
}

}

object MigrationV2ToV3 : Migration(2, 3) {

override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE `Subscription` ADD `favourite` INTEGER NOT NULL DEFAULT 0")
}

}

}
3 changes: 3 additions & 0 deletions app/src/main/java/moe/feng/danmaqua/data/SubscriptionDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ interface SubscriptionDao {
@Query("SELECT * FROM subscription ORDER BY `order`")
suspend fun getAll(): List<Subscription>

@Query("SELECT * FROM subscription WHERE favourite = 1 ORDER BY `order`")
suspend fun getFavourites(): List<Subscription>

@Query("SELECT * FROM subscription WHERE selected = 1 LIMIT 1")
suspend fun findSelected(): Subscription?

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/moe/feng/danmaqua/model/Subscription.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ data class Subscription(
@ColumnInfo val username: String,
@ColumnInfo val avatar: String,
@ColumnInfo var order: Int = 0,
@ColumnInfo var selected: Boolean = false
@ColumnInfo var selected: Boolean = false,
@ColumnInfo var favourite: Boolean = false
) : Comparable<Subscription>, Parcelable {

override fun compareTo(other: Subscription): Int {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package moe.feng.danmaqua.service

import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.res.Configuration
import android.os.IBinder
import android.util.Log
import androidx.core.content.ContextCompat
import androidx.core.text.HtmlCompat
import kotlinx.coroutines.*
import moe.feng.danmaqua.Danmaqua.EXTRA_ACTION
import moe.feng.danmaqua.Danmaqua.EXTRA_DATA
import moe.feng.danmaqua.Danmaqua.EXTRA_START_ROOM
import moe.feng.danmaqua.IDanmakuListenerCallback
import moe.feng.danmaqua.IDanmakuListenerService
Expand All @@ -34,6 +35,13 @@ class DanmakuListenerService :
const val ACTION_STOP = "stop"
const val ACTION_RECONNECT = "reconnect"

fun startServiceAndConnect(context: Context, roomId: Long) {
val intent = Intent(context, DanmakuListenerService::class.java)
intent.putExtra(EXTRA_ACTION, ACTION_START)
intent.putExtra(EXTRA_START_ROOM, roomId)
ContextCompat.startForegroundService(context, intent)
}

}

private val binder: AidlInterfaceImpl = AidlInterfaceImpl()
Expand Down
21 changes: 18 additions & 3 deletions app/src/main/java/moe/feng/danmaqua/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ class MainActivity : BaseActivity(),
insets
}
bottomAppBar.addOnLayoutChangeListener { _, _, top, _, bottom, _, _, _, _ ->
recyclerView.updatePadding(bottom = bottom - top)
recyclerView.updatePadding(bottom = bottom - top
+ resources.getDimensionPixelSize(R.dimen.main_list_bottom_padding_extra))
backToLatestButtonContainer.updateLayoutParams<CoordinatorLayout.LayoutParams> {
bottomMargin = bottom - top
}
Expand Down Expand Up @@ -224,11 +225,13 @@ class MainActivity : BaseActivity(),
override fun onResume() {
super.onResume()
connectivityHelper.register()
ShortcutsUtils.requestUpdateShortcuts(this)
}

override fun onPause() {
super.onPause()
connectivityHelper.unregister()
ShortcutsUtils.requestUpdateShortcuts(this)
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
Expand All @@ -253,7 +256,7 @@ class MainActivity : BaseActivity(),
return when (item.itemId) {
R.id.action_open_stream -> {
launchWhenStarted {
val current = database.subscriptions().getAll().firstOrNull { it.selected }
val current = database.subscriptions().findSelected()
if (current != null) {
startActivity(IntentUtils.openBilibiliLive(
this@MainActivity, current.roomId))
Expand All @@ -263,14 +266,26 @@ class MainActivity : BaseActivity(),
}
R.id.action_room_info -> {
launchWhenResumed {
val current = database.subscriptions().getAll().firstOrNull { it.selected }
val current = database.subscriptions().findSelected()
if (current != null) {
RoomInfoDialogFragment.newInstance(current.roomId)
.show(supportFragmentManager, "room_info")
}
}
true
}
R.id.action_add_to_home -> {
launchWhenResumed {
val current = database.subscriptions().findSelected()
if (current != null) {
if (!ShortcutsUtils.requestPinSubscription(this@MainActivity, current)) {
Toast.makeText(this@MainActivity,
R.string.toast_failed_to_add_to_home, Toast.LENGTH_LONG).show()
}
}
}
true
}
else -> super.onOptionsItemSelected(item)
}
}
Expand Down
Loading

0 comments on commit e504dc6

Please sign in to comment.