Skip to content

Commit

Permalink
Merge pull request #301 from stakwork/kg/feature/subscriptions
Browse files Browse the repository at this point in the history
Subscriptions
  • Loading branch information
05nelsonm authored Sep 2, 2021
2 parents 4ecaa2c + 2a7957a commit b2db8bb
Show file tree
Hide file tree
Showing 76 changed files with 2,770 additions and 60 deletions.
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ include ':sphinx:application:data:concepts:repositories:concept-repository-dashb
include ':sphinx:application:data:concepts:repositories:concept-repository-lightning'
include ':sphinx:application:data:concepts:repositories:concept-repository-media'
include ':sphinx:application:data:concepts:repositories:concept-repository-message'
include ':sphinx:application:data:concepts:repositories:concept-repository-subscription'
include ':sphinx:application:data:features:feature-repository'
include ':sphinx:application:data:features:feature-repository-android'

Expand Down Expand Up @@ -137,6 +138,7 @@ include ':sphinx:screens-detail:podcast-player:podcast-player'
include ':sphinx:screens-detail:qr-code:qr-code'
include ':sphinx:screens-detail:scanner:scanner'
include ':sphinx:screens-detail:scanner:scanner-view-model-coordinator'
include ':sphinx:screens-detail:subscription:subscription'
include ':sphinx:screens-detail:support-ticket:support-ticket'
include ':sphinx:screens-detail:transactions:transactions'
include ':sphinx:screens-detail:tribe-members-list:tribe-members-list'
Expand Down
1 change: 1 addition & 0 deletions sphinx/activity/main/activitymain/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ dependencies {
api project(path: ':sphinx:screens-detail:podcast-player:podcast-player')
api project(path: ':sphinx:screens-detail:qr-code:qr-code')
api project(path: ':sphinx:screens-detail:scanner:scanner')
api project(path: ':sphinx:screens-detail:subscription:subscription')
api project(path: ':sphinx:screens-detail:support-ticket:support-ticket')
api project(path: ':sphinx:screens-detail:transactions:transactions')
api project(path: ':sphinx:screens-detail:tribe-members-list:tribe-members-list')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import chat.sphinx.profile.navigation.ProfileNavigator
import chat.sphinx.qr_code.navigation.QRCodeNavigator
import chat.sphinx.scanner.navigation.ScannerNavigator
import chat.sphinx.splash.navigation.SplashNavigator
import chat.sphinx.subscription.navigation.SubscriptionNavigator
import chat.sphinx.support_ticket.navigation.SupportTicketNavigator
import chat.sphinx.transactions.navigation.TransactionsNavigator
import chat.sphinx.tribe_detail.navigation.TribeDetailNavigator
Expand Down Expand Up @@ -226,6 +227,12 @@ internal object NavigationModule {
): ProfileNavigator =
profileNavigatorImpl

@Provides
fun provideSubscriptionNavigator(
subscriptionNavigatorImpl: SubscriptionNavigatorImpl
): SubscriptionNavigator =
subscriptionNavigatorImpl

@Provides
fun provideSupportTicketNavigator(
supportTicketNavigatorImpl: SupportTicketNavigatorImpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package chat.sphinx.activitymain.navigation.navigators.detail
import chat.sphinx.activitymain.navigation.drivers.DetailNavigationDriver
import chat.sphinx.edit_contact.navigation.EditContactNavigator
import chat.sphinx.qr_code.navigation.ToQRCodeDetail
import chat.sphinx.subscription.navigation.ToSubscriptionDetail
import chat.sphinx.wrapper_common.dashboard.ContactId
import javax.inject.Inject

internal class EditContactNavigatorImpl @Inject constructor(
Expand All @@ -22,4 +24,10 @@ internal class EditContactNavigatorImpl @Inject constructor(
)
)
}

override suspend fun toSubscribeDetailScreen(contactId: ContactId) {
navigationDriver.submitNavigationRequest(
ToSubscriptionDetail(contactId)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package chat.sphinx.activitymain.navigation.navigators.detail

import chat.sphinx.activitymain.navigation.drivers.DetailNavigationDriver
import chat.sphinx.subscription.navigation.SubscriptionNavigator
import javax.inject.Inject

internal class SubscriptionNavigatorImpl @Inject constructor(
detailDriver: DetailNavigationDriver,
): SubscriptionNavigator(detailDriver) {

override suspend fun closeDetailScreen() {
(navigationDriver as DetailNavigationDriver).closeDetailScreen()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<include app:graph="@navigation/podcast_player_nav_graph" />
<include app:graph="@navigation/qr_code_nav_graph" />
<include app:graph="@navigation/scanner_nav_graph" />
<include app:graph="@navigation/subscription_nav_graph" />
<include app:graph="@navigation/support_ticket_nav_graph" />
<include app:graph="@navigation/transactions_nav_graph" />
<include app:graph="@navigation/tribe_detail_nav_graph" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_checked="true" android:state_window_focused="false"
android:drawable="@drawable/ic_check_box_on" />
<item android:state_checked="false" android:state_window_focused="false"
android:drawable="@drawable/ic_check_box_off" />

<item android:state_checked="true" android:state_pressed="true"
android:drawable="@drawable/ic_check_box_on" />
<item android:state_checked="false" android:state_pressed="true"
android:drawable="@drawable/ic_check_box_on" />

<item android:state_checked="true" android:state_focused="true"
android:drawable="@drawable/ic_check_box_on" />
<item android:state_checked="false" android:state_focused="true"
android:drawable="@drawable/ic_check_box_on" />

<item android:state_checked="false" android:drawable="@drawable/ic_check_box_off" />
<item android:state_checked="true" android:drawable="@drawable/ic_check_box_on" />

</selector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M19,5v14H5V5h14m0,-2H5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2V5c0,-1.1 -0.9,-2 -2,-2z"
android:fillColor="@color/secondaryText"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M19,3L5,3c-1.11,0 -2,0.9 -2,2v14c0,1.1 0.89,2 2,2h14c1.11,0 2,-0.9 2,-2L21,5c0,-1.1 -0.89,-2 -2,-2zM10,17l-5,-5 1.41,-1.41L10,14.17l7.59,-7.59L19,8l-9,9z"
android:fillColor="@color/primaryBlue"/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import java.util.*
inline fun String.toDateTime(): DateTime =
DateTime(DateTime.getFormatRelay().parse(this))

@Suppress("NOTHING_TO_INLINE")
@Throws(ParseException::class)
inline fun String.toDateTimeWithFormat(format: SimpleDateFormat): DateTime =
DateTime(format.parse(this))

@Suppress("NOTHING_TO_INLINE")
inline fun Long.toDateTime(): DateTime =
DateTime(Date(this))
Expand Down Expand Up @@ -95,6 +100,7 @@ value class DateTime(val value: Date) {
private const val FORMAT_EEE_DD = "EEE dd"
private const val FORMAT_EEE_MM_DD_H_MM_A = "EEE MMM dd, h:mm a"
private const val FORMAT_DD_MMM_HH_MM = "dd MMM, HH:mm"
private const val FORMAT_MMM_DD_YYYY = "MMM dd, yyyy"

private const val SIX_DAYS_IN_MILLISECONDS = 518_400_000L

Expand Down Expand Up @@ -241,6 +247,21 @@ value class DateTime(val value: Date) {
formatEEEdd = it
}
}

@Volatile
private var formatMMMddyyyy: SimpleDateFormat? = null
fun getFormatMMMddyyyy(timeZone: TimeZone = TimeZone.getDefault()): SimpleDateFormat =
formatMMMddyyyy?.also {
it.timeZone = timeZone
} ?: synchronized(this) {
formatMMMddyyyy?.also {
it.timeZone = timeZone
} ?: SimpleDateFormat(FORMAT_MMM_DD_YYYY, Locale.getDefault())
.also {
it.timeZone = timeZone
formatMMMddyyyy = it
}
}
}

override fun toString(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ inline fun Long.toContactId(): ContactId? =
}

@JvmInline
value class ContactId(override val value: Long): DashboardItemId {
value class ContactId(
override val value: Long
): DashboardItemId {
companion object {
const val NULL_CONTACT_ID = Long.MAX_VALUE
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package chat.sphinx.wrapper_common.subscription

@JvmInline
value class Cron(val value: String) {
init {
require(value.isNotEmpty()) {
"Subscription Cron cannot be empty"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package chat.sphinx.wrapper_common.subscription

@JvmInline
value class EndNumber(val value: Long) {
init {
require(value >= 0) {
"EndNumber must be greater than or equal to 0"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package chat.sphinx.wrapper_common.subscription

@JvmInline
value class SubscriptionCount(val value: Long) {
init {
require(value >= 0) {
"SubscriptionCount must be greater than or equal to 0"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package chat.sphinx.wrapper_subscription

import chat.sphinx.wrapper_common.DateTime
import chat.sphinx.wrapper_common.dashboard.ChatId
import chat.sphinx.wrapper_common.dashboard.ContactId
import chat.sphinx.wrapper_common.lightning.Sat
import chat.sphinx.wrapper_common.subscription.Cron
import chat.sphinx.wrapper_common.subscription.EndNumber
import chat.sphinx.wrapper_common.subscription.SubscriptionCount
import chat.sphinx.wrapper_common.subscription.SubscriptionId

data class Subscription(
val id: SubscriptionId,
val cron: Cron,
val amount: Sat,
val endNumber: EndNumber?,
val count: SubscriptionCount,
val endDate: DateTime?,
val ended: Boolean,
val paused: Boolean,
val createdAt: DateTime,
val updatedAt: DateTime,
val chatId: ChatId,
val contactId: ContactId
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import chat.sphinx.wrapper_common.lightning.LightningRouteHint;
import chat.sphinx.wrapper_common.lightning.Sat;
import chat.sphinx.wrapper_common.message.MessageId;
import chat.sphinx.wrapper_common.message.MessageUUID;
import chat.sphinx.wrapper_common.subscription.Cron;
import chat.sphinx.wrapper_common.subscription.EndNumber;
import chat.sphinx.wrapper_common.subscription.SubscriptionCount;
import chat.sphinx.wrapper_common.subscription.SubscriptionId;
import chat.sphinx.wrapper_contact.ContactAlias;
import chat.sphinx.wrapper_contact.ContactStatus;
import chat.sphinx.wrapper_contact.DeviceId;
Expand Down Expand Up @@ -741,3 +745,102 @@ WHERE id = ?;
messageMediaDeleteByChatId:
DELETE FROM messageMediaDbo
WHERE chat_id = ?;

CREATE TABLE subscriptionDbo(
id INTEGER AS SubscriptionId NOT NULL PRIMARY KEY,
cron TEXT AS Cron NOT NULL,
amount INTEGER AS Sat NOT NULL,
end_number INTEGER AS EndNumber,
count INTEGER AS SubscriptionCount NOT NULL,
end_date INTEGER AS DateTime,
ended INTEGER AS Boolean DEFAULT 0 NOT NULL,
paused INTEGER AS Boolean DEFAULT 0 NOT NULL,
created_at INTEGER AS DateTime NOT NULL,
updated_at INTEGER AS DateTime NOT NULL,
chat_id INTEGER AS ChatId NOT NULL,
contact_id INTEGER AS ContactId NOT NULL
);

subscriptionGetById:
SELECT *
FROM subscriptionDbo
WHERE id = ?;

subscriptionGetLastActiveByContactId:
SELECT *
FROM subscriptionDbo
WHERE ended = 0 AND contact_id = ?
ORDER BY id DESC
LIMIT 1;

subscriptionGetAllByChatId:
SELECT *
FROM subscriptionDbo
WHERE chat_id = ?;

subscriptionGetAll:
SELECT *
FROM subscriptionDbo;

subscriptionUpsert {
UPDATE subscriptionDbo
SET cron = :cron,
amount = :amount,
end_number = :end_number,
count = :count,
end_date = :end_date,
ended = :ended,
paused = :paused,
created_at = :created_at,
updated_at = :updated_at,
chat_id = :chat_id,
contact_id = :contact_id
WHERE id = :id;

INSERT OR IGNORE INTO subscriptionDbo(
id,
cron,
amount,
end_number,
count,
end_date,
ended,
paused,
created_at,
updated_at,
chat_id,
contact_id
)
VALUES (
:id,
:cron,
:amount,
:end_number,
:count,
:end_date,
:ended,
:paused,
:created_at,
:updated_at,
:chat_id,
:contact_id
);
}

subscriptionDeleteById:
DELETE FROM subscriptionDbo
WHERE id = ?;

subscriptionUpdatePaused:
UPDATE subscriptionDbo
SET paused = :paused
WHERE id = ?;

subscriptionUpdateEnded:
UPDATE subscriptionDbo
SET ended = :ended
WHERE id = ?;

subscriptionDeleteByContactId:
DELETE FROM subscriptionDbo
WHERE contact_id = ?;
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
import chat.sphinx.wrapper_common.DateTime;
import chat.sphinx.wrapper_common.dashboard.ChatId;
import chat.sphinx.wrapper_common.dashboard.ContactId;
import chat.sphinx.wrapper_common.lightning.Sat;
import chat.sphinx.wrapper_common.subscription.Cron;
import chat.sphinx.wrapper_common.subscription.EndNumber;
import chat.sphinx.wrapper_common.subscription.SubscriptionCount;
import chat.sphinx.wrapper_common.subscription.SubscriptionId;
import chat.sphinx.wrapper_message.MessageMUID;

ALTER TABLE messageDbo ADD COLUMN muid TEXT AS MessageMUID;
CREATE TABLE subscriptionDbo(
id INTEGER AS SubscriptionId NOT NULL PRIMARY KEY,
cron TEXT AS Cron NOT NULL,
amount INTEGER AS Sat NOT NULL,
end_number INTEGER AS EndNumber,
count INTEGER AS SubscriptionCount NOT NULL,
end_date INTEGER AS DateTime,
ended INTEGER AS Boolean DEFAULT 0 NOT NULL,
paused INTEGER AS Boolean DEFAULT 0 NOT NULL,
created_at INTEGER AS DateTime NOT NULL,
updated_at INTEGER AS DateTime NOT NULL,
chat_id INTEGER AS ChatId NOT NULL,
contact_id INTEGER AS ContactId NOT NULL
);

ALTER TABLE messageDbo ADD COLUMN muid TEXT AS MessageMUID;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Loading

0 comments on commit b2db8bb

Please sign in to comment.