Skip to content

Commit

Permalink
Merge pull request #41 from roozbehzarei/dev
Browse files Browse the repository at this point in the history
Release v2.3.1
  • Loading branch information
roozbehzarei authored Feb 3, 2024
2 parents 656ceea + ea3de1c commit 50bce97
Show file tree
Hide file tree
Showing 21 changed files with 196 additions and 139 deletions.
24 changes: 12 additions & 12 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ plugins {
id("org.jetbrains.kotlin.android")
id("androidx.navigation.safeargs.kotlin")
id("com.google.devtools.ksp")
id("com.google.gms.google-services")
id("com.google.firebase.crashlytics")
id("com.google.firebase.firebase-perf")
}

android {
Expand All @@ -16,8 +13,8 @@ android {
applicationId = "com.roozbehzarei.filester"
minSdk = 21
targetSdk = 34
versionCode = 6
versionName = "2.3.0"
versionCode = 7
versionName = "2.3.1"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -55,6 +52,7 @@ dependencies {
val workVersion = "2.8.1"
val roomVersion = "2.5.2"
val preferenceVersion = "1.2.0"
val acraVersion = "5.11.3"

implementation("androidx.core:core-ktx:1.10.1")
implementation("androidx.appcompat:appcompat:1.6.1")
Expand All @@ -68,8 +66,11 @@ dependencies {
// ViewModel
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion")
implementation("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion")
// Retrofit with Scalars Converter
// Retrofit 2
implementation("com.squareup.retrofit2:converter-scalars:$retrofitVersion")
implementation("com.squareup.retrofit2:converter-moshi:$retrofitVersion")
// Moshi
implementation("com.squareup.moshi:moshi-kotlin:1.15.0")
// WorkManager
implementation("androidx.work:work-runtime-ktx:$workVersion")
// Room
Expand All @@ -81,14 +82,13 @@ dependencies {
implementation("androidx.activity:activity-ktx:$activityVersion")
// SplashScreen
implementation("androidx.core:core-splashscreen:1.0.1")
// Firebase
implementation(platform("com.google.firebase:firebase-bom:32.2.0"))
implementation("com.google.firebase:firebase-messaging")
implementation("com.google.firebase:firebase-analytics-ktx")
implementation("com.google.firebase:firebase-crashlytics-ktx")
implementation("com.google.firebase:firebase-perf-ktx")
// Preference
implementation("androidx.preference:preference-ktx:$preferenceVersion")
// Webkit
implementation("androidx.webkit:webkit:1.10.0")
// Aptabase
implementation("com.aptabase:aptabase:0.0.6")
// ACRA
implementation("ch.acra:acra-mail:$acraVersion")
implementation("ch.acra:acra-notification:$acraVersion")
}
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 6,
"versionName": "2.3.0",
"versionCode": 7,
"versionName": "2.3.1",
"outputFile": "app-release.apk"
}
],
Expand Down
16 changes: 0 additions & 16 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,6 @@
android:value="true" />
</service>

<service
android:name=".FilesterFirebaseMsgService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>

<meta-data
android:name="firebase_performance_logcat_enabled"
android:value="true" />

<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_notification" />

<activity
android:name=".ui.MainActivity"
android:exported="true"
Expand Down
44 changes: 42 additions & 2 deletions app/src/main/java/com/roozbehzarei/filester/BaseApplication.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,53 @@
package com.roozbehzarei.filester

import android.app.Application
import android.content.Context
import com.aptabase.Aptabase
import com.roozbehzarei.filester.database.FileDatabase
import org.acra.config.mailSender
import org.acra.config.notification
import org.acra.data.StringFormat
import org.acra.ktx.initAcra

private const val APTABASE_KEY = "A-EU-5566501326"

class BaseApplication : Application() {
// Using by lazy so the database is only created when needed
// rather than when the application starts
// Create database when needed
val database: FileDatabase by lazy {
FileDatabase.getDatabase(this)
}


override fun onCreate() {
super.onCreate()
// Initialize Aptabase SDK
Aptabase.instance.initialize(applicationContext, APTABASE_KEY)
// Track app launch on startup
Aptabase.instance.trackEvent("app_started")
}

/**
* Configure ACRA
*/
override fun attachBaseContext(base: Context?) {
super.attachBaseContext(base)
initAcra {
buildConfigClass = BuildConfig::class.java
reportFormat = StringFormat.KEY_VALUE_LIST
notification {
title = getString(R.string.crash_notification_title)
text = getString(R.string.crash_notification_text)
channelName = getString(R.string.notification_channel_id)
resIcon = R.drawable.ic_notification
sendButtonText = getString(R.string.send)
discardButtonText = getString(R.string.button_cancel)
sendOnClick = true
}
mailSender {
mailTo = "contact@roozbehzarei.me"
subject = getString(R.string.crash_mail_subject)
body = getString(R.string.crash_mail_body)
}
}
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.roozbehzarei.filester.database

data class MainUiState(
// A pair of file name and its deletion status
val appVersion: Version? = null,
val isFileDeleted: Boolean = false
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.roozbehzarei.filester.database

import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class Version(
val code: Int, val url: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.roozbehzarei.filester.network

import com.roozbehzarei.filester.database.Version
import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory
import retrofit2.http.GET

private const val BASE_URL = "https://api.roozbehzarei.me/filester/"

private val moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()

/**
* The Retrofit object with [moshi] converter
*/
private val retrofit: Retrofit =
Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(MoshiConverterFactory.create(moshi))
.build()

interface FilesterApiService {
@GET("version.json")
suspend fun getVersion(): Response<Version>
}

/**
* A public Api object that exposes the lazy-initialized Retrofit service
*/
object FilesterApi {
val retrofitService: FilesterApiService by lazy { retrofit.create(FilesterApiService::class.java) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ private const val BASE_URL = "https://transfer.sh"
/**
* The Retrofit object with the Scalars converter.
*/
val retrofit: Retrofit = Retrofit.Builder()
private val retrofit: Retrofit = Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(ScalarsConverterFactory.create())
.build()
Expand Down
25 changes: 0 additions & 25 deletions app/src/main/java/com/roozbehzarei/filester/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.setupWithNavController
import com.google.android.material.appbar.AppBarLayout
import com.roozbehzarei.filester.FilesterFirebaseMsgService
import com.roozbehzarei.filester.R
import com.roozbehzarei.filester.databinding.ActivityMainBinding
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -84,33 +83,9 @@ class MainActivity : AppCompatActivity() {
// Set up the app bar for use with the NavController
binding.appBar.setupWithNavController(navController)

handleFirebaseUpdateMessage()
createNotificationChannel()
}

/**
* 1. Show [UpdateDialog] if [FilesterFirebaseMsgService.KEY_UPDATE] is passed
* as intent extra (app is in background)
* 2. Observe incoming Firebase update messages exposed via [FilesterFirebaseMsgService.incomingMessage]
* to open [UpdateDialog] (app is in foreground)
*/
private fun handleFirebaseUpdateMessage() {
// 1.
if (intent.extras?.getString(FilesterFirebaseMsgService.KEY_UPDATE).isNullOrEmpty().not())
showUpdateDialog()
// 2.
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.RESUMED) {
FilesterFirebaseMsgService.incomingMessage.collect { message ->
if (!message.isShown) {
showUpdateDialog()
FilesterFirebaseMsgService.incomingMessageShown()
}
}
}
}
}

private fun showUpdateDialog() {
val updateDialog = UpdateDialog()
if (!updateDialog.isAdded) updateDialog.show(
Expand Down
25 changes: 19 additions & 6 deletions app/src/main/java/com/roozbehzarei/filester/ui/MainFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.navigation.fragment.findNavController
import androidx.work.WorkInfo
import com.aptabase.Aptabase
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
import com.roozbehzarei.filester.BaseApplication
import com.roozbehzarei.filester.BuildConfig
import com.roozbehzarei.filester.HistoryListAdapter
import com.roozbehzarei.filester.R
import com.roozbehzarei.filester.databinding.FragmentMainBinding
import com.roozbehzarei.filester.ui.UpdateDialog.Companion.VER_URL_KEY
import com.roozbehzarei.filester.viewmodel.FilesterViewModel
import com.roozbehzarei.filester.viewmodel.FilesterViewModelFactory
import com.roozbehzarei.filester.viewmodel.KEY_FILE_URI
Expand Down Expand Up @@ -67,9 +70,8 @@ class MainFragment : Fragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requestPermissionLauncher =
registerForActivityResult(ActivityResultContracts.RequestPermission()) { _ ->
fileSelector.launch("*/*")
}
registerForActivityResult(ActivityResultContracts.RequestPermission()) { _ -> }
viewModel.getAppVersion()
}

override fun onCreateView(
Expand Down Expand Up @@ -150,8 +152,7 @@ class MainFragment : Fragment() {
}

// Ask user to grant notification permission
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
checkNotificationPermission()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) checkNotificationPermission()

return binding.root
}
Expand All @@ -172,8 +173,11 @@ class MainFragment : Fragment() {
getString(R.string.snackbar_delete_successful),
Snackbar.LENGTH_LONG
).show()
viewModel.uiStateConsumed()
}
if (state.appVersion != null) {
if (state.appVersion.code > BuildConfig.VERSION_CODE) showUpdateDialog(state.appVersion.url)
}
viewModel.uiStateConsumed()
}
}
}
Expand Down Expand Up @@ -203,6 +207,7 @@ class MainFragment : Fragment() {
viewModel.clearWorkQueue()
isUploadInProgress(false)
ongoingUploadSnackbar?.dismiss()
Aptabase.instance.trackEvent("file_uploaded")
} else {
showUploadDialog(false, null)
viewModel.clearWorkQueue()
Expand Down Expand Up @@ -288,4 +293,12 @@ class MainFragment : Fragment() {
}
}

private fun showUpdateDialog(url: String) {
val updateDialog = UpdateDialog()
val args = Bundle()
args.putString(VER_URL_KEY, url)
updateDialog.arguments = args
if (!updateDialog.isAdded) updateDialog.show(parentFragmentManager, UpdateDialog.TAG)
}

}
Loading

0 comments on commit 50bce97

Please sign in to comment.