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

Introduce daifuku and puree #10

Merged
merged 5 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions .github/workflows/call-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,10 @@ jobs:
- name: Setup Android SDK
uses: android-actions/setup-android@v2

- name: Restore bundle cache
uses: actions/cache@v3
- name: Setup Ruby
uses: ruby/setup-ruby@cd48c8e22733480b66887b42bfeb6c0b88ea1a56
with:
path: vendor/bundle
key: bundle-${{ hashFiles('**/Gemfile.lock') }}

- name: Restore gradle cache
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle', '**/*.gradle.kts') }}
bundler-cache: true

- name: Create release keystore
run: echo "${{ secrets.RELEASE_KEYSTORE }}" | base64 -d > gradle/keystore/release.jks
Expand Down
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem "daifuku"
19 changes: 19 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
GEM
remote: https://rubygems.org/
specs:
daifuku (0.9.0)
nokogiri (~> 1.15)
redcarpet (~> 3.6)
nokogiri (1.15.5-arm64-darwin)
racc (~> 1.4)
racc (1.7.3)
redcarpet (3.6.0)

PLATFORMS
arm64-darwin-22

DEPENDENCIES
daifuku

BUNDLED WITH
2.4.22
7 changes: 5 additions & 2 deletions README-JA.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ FANBOX には Web 版しかなく、スマートフォンで投稿を閲覧す
- 画像 / ファイル / GIF 形式でダウンロード
- 投稿に含まれるすべての画像をダウンロード
- ファンカードのダウンロード
- クリエイター単位での一括ダウンロード機能
- 広告
- AdMob Native 広告

#### Not Ready...

- クリエイター単位での一括ダウンロード機能
- Pixiv 連携機能
- ウィジェット機能
- 広告系全般

## Architecture
アプリのアーキテクチャ図を示します。 だいぶ複雑になっているので、一部のモジュールや依存関係は省略し、概略を掴める形にしています。
Expand Down Expand Up @@ -120,6 +121,8 @@ graph LR

## Contribute

セットアップはとても簡単で、このリポジトリをクローン氏 `bundle install` するだけです。このアプリは [daifuku](https://github.com/cookpad/daifuku) と [Puree](https://github.com/cookpad/puree-kotlin) を用いてログ基盤を作成しています。詳しくはライブラリのドキュメントまたは `./scripts/daifuku` 以下をご覧ください。

このアプリは Gradle の Convention Plugins を用いてビルドのロジックを共通化しており、`build-logic` というモジュールに全てのロジックが記述されています。このアプローチに関しては、[nowinandroid](https://github.com/matsumo0922/nowinandroid/tree/main/build-logic) をご覧ください。

何か不具合を発見したり機能を改善したい場合、機能を新たに開発したい場合は、まず issue を書いてください。その上であなた自身を assign し、開発に取り組んでください。pull request はいつでも歓迎です :smile:
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ There was only a web version of FANBOX, which was a bit inconvenient for viewing
- Download in image/file/GIF format.
- Download all images included in a post.
- Download fan cards.
- Bulk download function for individual creators.
- Ads
- AdMob Native Ads

#### Not Ready...

- Bulk download function for individual creators.
- Pixiv integration feature.
- Widget functionality.
- All advertising-related features.

## Architecture
Shows the architecture diagram of the app. It's quite complex, so I've omitted some modules and dependencies to give you an overview.
Expand Down Expand Up @@ -122,11 +123,13 @@ graph LR

## Contribute

Setup is very easy, just clone this repository and `bundle install`. This app uses [daifuku](https:github.comcookpaddaifuku) and [Puree](https:github.comcookpadpuree-kotlin) to create the log infrastructure. For more information, please see the library documentation or `./scripts/daifuku`.

This app uses Gradle's Convention Plugins to standardize the build logic, and all the logic is written in a module called `build-logic`. For information on this approach, see [nowinandroid](https://github.com/matsumo0922/nowinandroid/tree/main/build-logic).

If you find a bug, want to improve a feature, or want to develop a new feature, please first write an issue. Then assign yourself and work on the development. Pull requests are always welcome :smile:

This app is monetized using AdMob. When building manually from GitHub, you need to write the AdMob App ID in `local.properties`. By default it contains a dummy ID, which causes it to crash on startup. Alternatively, please delete the AdMob code and build the app. In addition, various IDs are described in `local.properties`. See `appbuild.gradle.kts` or `PixiViewConfig` for details.
This app is monetized using AdMob. When building manually from GitHub, you need to write the AdMob App ID in `local.properties`. By default it contains a dummy ID, which causes it to crash on startup. Alternatively, please delete the AdMob code and build the app. In addition, various IDs are described in `local.properties`. See `app/build.gradle.kts` or `PixiViewConfig` for details.

## License

Expand Down
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ dependencies {
implementation(project(":core:repository"))
implementation(project(":core:ui"))
implementation(project(":core:billing"))
implementation(project(":core:logs"))

implementation(project(":feature:report"))
implementation(project(":feature:library"))
Expand All @@ -139,6 +140,8 @@ dependencies {
implementation(libs.bundles.ktor)

implementation(libs.androidx.core.splashscreen)
implementation(libs.play.review)
implementation(libs.play.update)
implementation(libs.play.service.oss)
implementation(libs.play.service.ads)
implementation(libs.google.material)
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/java/caios/android/fanbox/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ import caios.android.fanbox.core.ui.view.LoadingView
import caios.android.fanbox.feature.post.service.PostDownloadService
import caios.android.fanbox.ui.PixiViewApp
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import com.google.android.play.core.review.ReviewManagerFactory
import dagger.hilt.android.AndroidEntryPoint
import timber.log.Timber

@AndroidEntryPoint
class MainActivity : FragmentActivity(), PostDownloader {
Expand Down Expand Up @@ -192,6 +194,7 @@ class MainActivity : FragmentActivity(), PostDownloader {

override fun onDownloadImages(imageItems: List<FanboxPostDetail.ImageItem>) {
if (isPostDownloadServiceBound) {
showReviewDialog()
startForegroundService(Intent(this, PostDownloadService::class.java))
postDownloadService.downloadImages(imageItems)
} else {
Expand All @@ -201,6 +204,7 @@ class MainActivity : FragmentActivity(), PostDownloader {

override fun onDownloadFile(fileItem: FanboxPostDetail.FileItem) {
if (isPostDownloadServiceBound) {
showReviewDialog()
startForegroundService(Intent(this, PostDownloadService::class.java))
postDownloadService.downloadFile(fileItem)
} else {
Expand All @@ -210,6 +214,7 @@ class MainActivity : FragmentActivity(), PostDownloader {

override fun onDownloadPosts(posts: List<FanboxPost>, isIgnoreFree: Boolean, isIgnoreFile: Boolean) {
if (isPostDownloadServiceBound) {
showReviewDialog()
startForegroundService(Intent(this, PostDownloadService::class.java))
postDownloadService.downloadPosts(posts, isIgnoreFree, isIgnoreFile)
} else {
Expand All @@ -226,6 +231,26 @@ class MainActivity : FragmentActivity(), PostDownloader {
}
}

private fun showReviewDialog() {
if (!viewModel.isAbleToRequestReview()) return

val manager = ReviewManagerFactory.create(this)
val request = manager.requestReviewFlow()

request.addOnCompleteListener {
if (it.isSuccessful) {
val reviewInfo = it.result
val flow = manager.launchReviewFlow(this, reviewInfo)

flow.addOnCanceledListener {
ToastUtil.show(this, R.string.home_review_success)
}
} else {
Timber.d("Review request failed: ${it.exception}")
}
}
}

@Composable
private fun shouldUseDarkTheme(screenState: ScreenState<MainUiState>): Boolean {
return when (screenState) {
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/caios/android/fanbox/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import caios.android.fanbox.core.billing.BillingClient
import caios.android.fanbox.core.common.util.suspendRunCatching
import caios.android.fanbox.core.datastore.PreferenceLaunchLog
import caios.android.fanbox.core.model.ScreenState
import caios.android.fanbox.core.model.UserData
import caios.android.fanbox.core.model.fanbox.FanboxMetaData
Expand All @@ -20,6 +21,7 @@ import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import java.time.OffsetDateTime
import java.util.Timer
import java.util.UUID
import javax.inject.Inject
Expand All @@ -33,6 +35,7 @@ class MainViewModel @Inject constructor(
billingClient: BillingClient,
private val userDataRepository: UserDataRepository,
private val fanboxRepository: FanboxRepository,
private val launchLog: PreferenceLaunchLog,
) : ViewModel() {

private val _isLoggedInFlow: MutableSharedFlow<Boolean> = MutableSharedFlow(replay = 1)
Expand Down Expand Up @@ -62,6 +65,7 @@ class MainViewModel @Inject constructor(
)

init {
launchLog.save(OffsetDateTime.now())
billingClient.initialize()

viewModelScope.launch {
Expand Down Expand Up @@ -104,6 +108,10 @@ class MainViewModel @Inject constructor(
_isAppLockedFlow.emit(isAppLock)
}
}

fun isAbleToRequestReview(): Boolean {
return launchLog.get().size >= 3
}
}

@Stable
Expand Down
20 changes: 19 additions & 1 deletion app/src/main/java/caios/android/fanbox/PixiViewApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import android.content.Intent
import android.os.Build
import caios.android.fanbox.core.common.PixiViewConfig
import caios.android.fanbox.core.common.PixiViewDebugTree
import caios.android.fanbox.core.logs.puree.PureeConfigurator
import caios.android.fanbox.core.repository.UserDataRepository
import caios.android.fanbox.feature.report.CrashReportActivity
import coil.Coil
import coil.ImageLoader
Expand All @@ -17,12 +19,18 @@ import com.google.android.material.color.DynamicColors
import com.google.firebase.FirebaseApp
import com.google.firebase.FirebaseOptions
import dagger.hilt.android.HiltAndroidApp
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject

@HiltAndroidApp
class PixiViewApplication : Application() {

@Inject
lateinit var userDataRepository: UserDataRepository

@Inject
lateinit var pixiViewConfig: PixiViewConfig

Expand All @@ -39,8 +47,8 @@ class PixiViewApplication : Application() {
startCrushReportActivity(e)
}

setupLogger()
setupCoil()

setupFirebase()
}

Expand Down Expand Up @@ -101,4 +109,14 @@ class PixiViewApplication : Application() {

FirebaseApp.initializeApp(this, builder.build())
}

private fun setupLogger() {
MainScope().launch {
PureeConfigurator.configure(
context = this@PixiViewApplication,
pixiViewConfig = pixiViewConfig,
userData = userDataRepository.userData.first(),
)
}
}
}
1 change: 1 addition & 0 deletions core/billing/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies {
implementation(project(":core:common"))
implementation(project(":core:repository"))
implementation(project(":core:datastore"))
implementation(project(":core:logs"))

api(libs.bundles.billing)
}
1 change: 1 addition & 0 deletions core/datastore/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ protobuf {
dependencies {
implementation(project(":core:common"))
implementation(project(":core:model"))
implementation(project(":core:logs"))

implementation(libs.androidx.datastore)
implementation(libs.protobuf.kotlin.lite)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class PixiViewPreferencesDataStore(
isGridMode = if (it.hasIsGridMode()) it.isGridMode else false,
isFollowTabDefaultHome = if (it.hasIsFollowTabDefaultHome()) it.isFollowTabDefaultHome else false,
isHideAdultContents = if (it.hasIsHideAdultContents()) it.isHideAdultContents else true,
isOverrideAdultContents = if (it.hasIsOverrideAdultContents()) it.isOverrideAdultContents else false,
isOverrideAdultContents = if (it.hasIsOverrideAdultContents()) it.isOverrideAdultContents else true,
isPlusMode = if (it.hasIsPlusMode()) it.isPlusMode else false,
isAgreedPrivacyPolicy = if (it.hasIsAgreedPrivacyPolicy()) it.isAgreedPrivacyPolicy else false,
isAgreedTermsOfService = if (it.hasIsAgreedTermsOfService()) it.isAgreedTermsOfService else false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package caios.android.fanbox.core.datastore

import android.content.Context
import caios.android.fanbox.core.common.serializer.OffsetDateTimeSerializer
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.json.Json
import java.io.File
import java.time.OffsetDateTime
import javax.inject.Inject

class PreferenceLaunchLog @Inject constructor(
@ApplicationContext private val context: Context,
) {
private val logFile get() = File(context.filesDir, FILE_NAME)

fun save(time: OffsetDateTime) {
val logs = get().toMutableList()
val serializer = ListSerializer(OffsetDateTimeSerializer())

Json.encodeToString(serializer, logs.apply { add(time) }).also {
logFile.writeText(it)
}
}

fun get(): List<OffsetDateTime> {
if (!logFile.exists()) return emptyList()

return logFile.readText().let {
Json.decodeFromString(ListSerializer(OffsetDateTimeSerializer()), it)
}
}

companion object {
private const val FILE_NAME = "LaunchLog.json"
}
}
1 change: 1 addition & 0 deletions core/logs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
18 changes: 18 additions & 0 deletions core/logs/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
plugins {
id("pixiview.library")
id("pixiview.detekt")
id("pixiview.hilt")
id("pixiview.firebase")
alias(libs.plugins.protobuf)
}

android {
namespace = "caios.android.fanbox.core.logs"
}

dependencies {
implementation(project(":core:common"))
implementation(project(":core:model"))

implementation(libs.puree)
}
4 changes: 4 additions & 0 deletions core/logs/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Loading
Loading