Skip to content

Commit

Permalink
Merge pull request #7 from Parabox-App/develop
Browse files Browse the repository at this point in the history
1.0.10-beta
  • Loading branch information
ojhdt authored Jan 10, 2023
2 parents 87a8816 + ef7bf47 commit 4f796fd
Show file tree
Hide file tree
Showing 66 changed files with 7,071 additions and 1,535 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
.cxx
local.properties
app/release
.idea/gradle.xml
.idea/gradle.xml
.idea/deploymentTargetDropDown.xml
34 changes: 29 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ android {
applicationId "com.ojhdtapp.parabox"
minSdk 26
targetSdk 33
versionCode 11
versionName "1.0.9-beta"
versionCode 12
versionName "1.0.10-beta"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -64,7 +64,25 @@ android {
aaptOptions {
noCompress "tflite"
}
splits {
abi {
enable true
reset()
include 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' //select ABIs to build APKs for
universalApk true //generate an additional APK that contains all the ABIs
}
}

applicationVariants.all { variant ->
variant.outputs.all { output ->
def abi = output.getFilter(com.android.build.OutputFile.ABI)
if (abi == null) abi = "all"//兼容
def version = variant.versionName
outputFileName = "Parabox" +
"-${version}" +
"-${abi}" +
".apk"
}
kotlin.sourceSets {
getByName(variant.name) {
kotlin.srcDir("build/generated/ksp/${variant.name}/kotlin")
Expand Down Expand Up @@ -92,7 +110,13 @@ dependencies {
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation "androidx.compose.material:material-icons-extended:$compose_version"
implementation "com.google.android.material:material:1.8.0-alpha03"
implementation "com.google.android.material:material:1.8.0-beta01"

// Qiniu
implementation 'com.qiniu:qiniu-java-sdk:7.12.1'

// Tencent COS
implementation 'com.qcloud.cos:cos-android-lite-nobeacon:5.9.8'

// Firebase
implementation platform('com.google.firebase:firebase-bom:31.0.1')
Expand Down Expand Up @@ -167,8 +191,8 @@ dependencies {

// Compose Destinations
// implementation 'io.github.raamcosta.compose-destinations:core:1.5.6-beta'
implementation 'io.github.raamcosta.compose-destinations:animations-core:1.7.25-beta'
ksp 'io.github.raamcosta.compose-destinations:ksp:1.7.25-beta'
implementation 'io.github.raamcosta.compose-destinations:animations-core:1.7.30-beta'
ksp 'io.github.raamcosta.compose-destinations:ksp:1.7.30-beta'

// DataStore
implementation "androidx.datastore:datastore-preferences:1.0.0"
Expand Down
263 changes: 185 additions & 78 deletions app/src/main/java/com/ojhdtapp/parabox/MainActivity.kt

Large diffs are not rendered by default.

67 changes: 65 additions & 2 deletions app/src/main/java/com/ojhdtapp/parabox/core/util/AvatarUtil.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,72 @@
package com.ojhdtapp.parabox.core.util

import android.graphics.BitmapFactory
import android.content.Context
import android.graphics.*
import android.net.Uri
import android.util.Log
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.graphics.toArgb
import com.ojhdtapp.parabox.core.util.FileUtil.checkUriAvailable
import java.util.*

fun ByteArray.toAvatarBitmap(): ImageBitmap{

fun ByteArray.toAvatarBitmap(): ImageBitmap {
return BitmapFactory.decodeByteArray(this, 0, this.size).asImageBitmap()
}

object AvatarUtil {
fun getAvatar(
context: Context,
uri: Uri? = null,
url: String? = null,
name: String? = null,
backgroundColor: androidx.compose.ui.graphics.Color,
textColor: androidx.compose.ui.graphics.Color,
): Any {
return (if(uri?.checkUriAvailable(context) == true) uri else null) ?: url ?: createNamedAvatarBm(
backgroundColor = backgroundColor.toArgb(),
textColor = textColor.toArgb(),
name = name?.ifBlank { null }?.substring(0, 1)?.uppercase(Locale.getDefault())
).getCircledBitmap()
}

fun createNamedAvatarBm(
width: Int = 150, height: Int = 150,
backgroundColor: Int,
textColor: Int,
name: String?
): Bitmap {
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
val rect = Rect(0, 0, width, height)
val canvas = Canvas(bitmap)

val backgroundPaint = Paint()
backgroundPaint.color = backgroundColor
canvas.drawRect(rect, backgroundPaint)

val textPaint = Paint()
textPaint.color = textColor
textPaint.textSize = 72f
textPaint.textScaleX = 1f
textPaint.textAlign = Paint.Align.CENTER
if (name != null) {
val baselineY = rect.centerY() - (textPaint.descent() + textPaint.ascent()) / 2
canvas.drawText(name, rect.centerX().toFloat(), baselineY, textPaint)
}
return bitmap
}

fun Bitmap.getCircledBitmap(): Bitmap {
val output = Bitmap.createBitmap(this.width, this.height, Bitmap.Config.ARGB_8888)
val canvas = Canvas(output)
val paint = Paint()
val rect = Rect(0, 0, this.width, this.height)
paint.isAntiAlias = true
canvas.drawARGB(0, 0, 0, 0)
canvas.drawCircle(this.width / 2f, this.height / 2f, this.width / 2f, paint)
paint.xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC_IN)
canvas.drawBitmap(this, rect, rect, paint)
return output
}
}
27 changes: 27 additions & 0 deletions app/src/main/java/com/ojhdtapp/parabox/core/util/CacheUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,37 @@ package com.ojhdtapp.parabox.core.util

import android.content.Context
import android.os.Environment
import android.util.Log
import java.io.File


object CacheUtil {
fun getChatFilesSizeBeforeTimestamp(context: Context, timestamp: Long) : Long{
val chatFilesDir = context.getExternalFilesDir("chat")
return if (chatFilesDir?.exists() == true){
var size: Long = 0
chatFilesDir.listFiles()?.forEach {
if (it.lastModified() < timestamp){
size += it.length()
}
}
size
} else {
0
}
}

fun deleteChatFilesBeforeTimestamp(context: Context, timestamp: Long){
val chatFilesDir = context.getExternalFilesDir("chat")
if (chatFilesDir?.exists() == true){
chatFilesDir.listFiles()?.forEach {
if (it.lastModified() < timestamp){
it.delete()
}
}
}
}

fun getCacheSize(context: Context): Long {
var size: Long = 0
val cacheDir = context.cacheDir
Expand Down
18 changes: 17 additions & 1 deletion app/src/main/java/com/ojhdtapp/parabox/core/util/ContextExtra.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import android.content.Context
import android.content.Intent
import android.net.Uri
import android.provider.Settings
import android.util.Log
import android.util.TypedValue
import androidx.annotation.AttrRes
import androidx.annotation.ColorInt
import androidx.core.content.ContextCompat
import com.google.android.material.color.DynamicColors
import com.google.android.material.color.MaterialColors
import com.ojhdtapp.parabox.R


fun Context.launchPlayStore(pkg: String) {
Expand All @@ -31,10 +39,18 @@ fun Context.launchNotificationSetting() {
startActivity(intent)
}

fun Context.launchSetting(){
fun Context.launchSetting() {
val intent = Intent().apply {
action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS
data = Uri.fromParts("package", packageName, null)
}
startActivity(intent)
}

fun Context.getThemeColor(attrRes: Int): Int {
val dynamicColorContext = DynamicColors.wrapContextIfAvailable(this, com.google.android.material.R.style.ThemeOverlay_Material3_DynamicColors_DayNight)
val typedValue = dynamicColorContext.obtainStyledAttributes(intArrayOf(attrRes))
val color = typedValue.getColor(0, 0)
typedValue.recycle()
return color
}
24 changes: 19 additions & 5 deletions app/src/main/java/com/ojhdtapp/parabox/core/util/DataStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ object DataStoreKeys{
val SEND_MESSAGE_ID = longPreferencesKey("send_message_id")
val USER_NAME = stringPreferencesKey("user_name")
val USER_AVATAR = stringPreferencesKey("user_avatar")
val IS_FIRST_LAUNCH = booleanPreferencesKey("is_first_launch")

val SETTINGS_DEFAULT_BACKUP_SERVICE = intPreferencesKey("settings_default_backup_service")
val SETTINGS_WORKING_MODE = intPreferencesKey("settings_working_mode")
val SETTINGS_CLOUD_SERVICE = intPreferencesKey("settings_cloud_service")
val SETTINGS_AUTO_BACKUP = booleanPreferencesKey("settings_auto_backup")
val SETTINGS_AUTO_BACKUP_FILE_MAX_SIZE = floatPreferencesKey("settings_auto_backup_file_max_size")
val SETTINGS_AUTO_DELETE_LOCAL_FILE = booleanPreferencesKey("settings_auto_delete_local_file")
Expand All @@ -30,20 +32,32 @@ object DataStoreKeys{
val SETTINGS_ML_KIT_TRANSLATION = booleanPreferencesKey("settings_ml_kit_translation")
val SETTINGS_ALLOW_BUBBLE_HOME = booleanPreferencesKey("settings_allow_bubble_home")
val SETTINGS_ALLOW_FOREGROUND_NOTIFICATION = booleanPreferencesKey("settings_allow_foreground_notification")

val GOOGLE_MAIL = stringPreferencesKey("google_mail")
val GOOGLE_NAME = stringPreferencesKey("google_name")
val GOOGLE_LOGIN = booleanPreferencesKey("google_login")
// val GOOGLE_LOGIN = booleanPreferencesKey("google_login")
val GOOGLE_AVATAR = stringPreferencesKey("google_avatar")
val GOOGLE_WORK_FOLDER_ID = stringPreferencesKey("google_work_folder_id")
val GOOGLE_TOTAL_SPACE = longPreferencesKey("google_total_space")
val GOOGLE_USED_SPACE = longPreferencesKey("google_used_space")
val GOOGLE_APP_USED_SPACE = longPreferencesKey("google_app_used_space")

val CLOUD_TOTAL_SPACE = longPreferencesKey("cloud_total_space")
val CLOUD_USED_SPACE = longPreferencesKey("cloud_used_space")
val CLOUD_APP_USED_SPACE = longPreferencesKey("cloud_app_used_space")

val REQUEST_NOTIFICATION_PERMISSION_FIRST_TIME = booleanPreferencesKey("show_notification_first_time")

val FCM_TOKEN = stringPreferencesKey("fcm_token")
val FCM_TARGET_TOKENS = stringSetPreferencesKey("fcm_target_tokens")
val FCM_LOOPBACK_TOKEN = stringPreferencesKey("fcm_loopback_token")

val TENCENT_COS_SECRET_ID = stringPreferencesKey("tencent_cos_secret_id")
val TENCENT_COS_SECRET_KEY = stringPreferencesKey("tencent_cos_secret_key")
val TENCENT_COS_BUCKET = stringPreferencesKey("tencent_cos_bucket")
val TENCENT_COS_REGION = stringPreferencesKey("tencent_cos_region")

val QINIU_KODO_ACCESS_KEY = stringPreferencesKey("qiniu_kodo_access_key")
val QINIU_KODO_SECRET_KEY = stringPreferencesKey("qiniu_kodo_secret_key")
val QINIU_KODO_BUCKET = stringPreferencesKey("qiniu_kodo_bucket")
val QINIU_KODO_DOMAIN = stringPreferencesKey("qiniu_kodo_domain")

const val DEFAULT_USER_NAME = "Me"
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ class DownloadUtil @Inject constructor(
withContext(Dispatchers.IO) {
try {
val responseBody = downloadUtilService.downloadUrl(url).body()
val finalPath = File(savePath, fileName)
FileOutputStream(
File(savePath, fileName)
finalPath
).use { output ->
responseBody?.byteStream().use { input ->
input?.copyTo(output, DEFAULT_BUFFER_SIZE)
}
} ?: throw RuntimeException("failed to download: $url")
savePath
finalPath
} catch (e: Exception) {
e.printStackTrace()
null
Expand Down
Loading

0 comments on commit 4f796fd

Please sign in to comment.