diff --git a/app/src/main/java/com/nominalista/expenses/settings/presentation/SettingsFragment.kt b/app/src/main/java/com/nominalista/expenses/settings/presentation/SettingsFragment.kt index 5191a28..f551742 100644 --- a/app/src/main/java/com/nominalista/expenses/settings/presentation/SettingsFragment.kt +++ b/app/src/main/java/com/nominalista/expenses/settings/presentation/SettingsFragment.kt @@ -22,6 +22,7 @@ import com.google.android.material.snackbar.Snackbar import android.content.Intent import androidx.lifecycle.Observer import androidx.work.WorkManager +import com.nominalista.expenses.util.extensions.startActivitySafely import com.nominalista.expenses.util.isGranted import com.nominalista.expenses.util.isPermissionGranted import java.util.* @@ -96,9 +97,12 @@ class SettingsFragment : Fragment() { compositeDisposable += model.showExpensesDeletionMessage .toObservable() .subscribe { showExpenseDeletionMessage(it) } - compositeDisposable += model.showWebsite + compositeDisposable += model.showActivity .toObservable() - .subscribe { showWebsite(it) } + .subscribe { showActivity(it) } + compositeDisposable += model.shareData + .toObservable() + .subscribe { shareData(it) } compositeDisposable += model.requestWriteExternalStoragePermission .toObservable() @@ -132,9 +136,18 @@ class SettingsFragment : Fragment() { Snackbar.make(containerLayout, messageId, Snackbar.LENGTH_LONG).show() } - private fun showWebsite(uri: Uri) { - val browserIntent = Intent(Intent.ACTION_VIEW, uri) - startActivity(browserIntent) + private fun showActivity(uri: Uri) { + val intent = Intent(Intent.ACTION_VIEW, uri) + requireActivity().startActivitySafely(intent) + } + + private fun shareData(text: String) { + val sharingIntent = Intent(Intent.ACTION_SEND).apply { + type = "text/plain" + putExtra(Intent.EXTRA_TEXT, text) + } + + startActivity(Intent.createChooser(sharingIntent, getString(R.string.share_with))) } private fun requestWriteExternalStoragePermission(requestCode: Int) { diff --git a/app/src/main/java/com/nominalista/expenses/settings/presentation/SettingsFragmentModel.kt b/app/src/main/java/com/nominalista/expenses/settings/presentation/SettingsFragmentModel.kt index da593e6..f5a0eb5 100644 --- a/app/src/main/java/com/nominalista/expenses/settings/presentation/SettingsFragmentModel.kt +++ b/app/src/main/java/com/nominalista/expenses/settings/presentation/SettingsFragmentModel.kt @@ -31,7 +31,8 @@ class SettingsFragmentModel( val showExpenseExportMessage = DataEvent() val showExpensesDeletionMessage = DataEvent() - val showWebsite = DataEvent() + val showActivity = DataEvent() + val shareData = DataEvent() val requestWriteExternalStoragePermission = DataEvent() @@ -114,6 +115,9 @@ class SettingsFragmentModel( itemModels += createGeneralHeader(context) itemModels += createViewSourceCode(context) + itemModels += createShareApp(context) + itemModels += createRateApp(context) + itemModels += createContactMe(context) return itemModels } @@ -125,7 +129,32 @@ class SettingsFragmentModel( val title = context.getString(R.string.view_source_code) return ActionSettingItemModel(title).apply { - click = { showWebsite.next(GITHUB_URI) } + click = { showActivity.next(GITHUB_URI) } + } + } + + private fun createShareApp(context: Context): SettingItemModel { + val title = context.getString(R.string.share_app) + + return ActionSettingItemModel(title).apply { + click = { shareData.next(GOOGLE_PLAY_URI.toString()) } + } + } + + private fun createRateApp(context: Context): SettingItemModel { + val title = context.getString(R.string.rate_app) + + return ActionSettingItemModel(title).apply { + click = { showActivity.next(GOOGLE_PLAY_URI) } + } + } + + private fun createContactMe(context: Context): SettingItemModel { + val title = context.getString(R.string.contact_me) + val summary = context.getString(R.string.feedback_is_welcome) + + return SummaryActionSettingItemModel(title, summary).apply { + click = { showActivity.next(EMAIL_URI) } } } @@ -213,6 +242,13 @@ class SettingsFragmentModel( private const val REQUEST_CODE_WRITE_EXTERNAL_STORAGE = 1 - private val GITHUB_URI = Uri.parse("https://github.com/Nominalista/Expenses") + private val GITHUB_URI = + Uri.parse("https://github.com/Nominalista/Expenses") + + private val GOOGLE_PLAY_URI = + Uri.parse("https://play.google.com/store/apps/details?id=com.nominalista.expenses") + + private val EMAIL_URI = + Uri.parse("mailto:the.nominalista@gmail.com") } } \ No newline at end of file diff --git a/app/src/main/java/com/nominalista/expenses/util/extensions/Activity.kt b/app/src/main/java/com/nominalista/expenses/util/extensions/Activity.kt index 8b46e3b..fa1d35e 100644 --- a/app/src/main/java/com/nominalista/expenses/util/extensions/Activity.kt +++ b/app/src/main/java/com/nominalista/expenses/util/extensions/Activity.kt @@ -2,6 +2,7 @@ package com.nominalista.expenses.util.extensions import android.app.Activity import android.content.Context +import android.content.Intent import android.view.View import android.view.inputmethod.InputMethodManager @@ -28,4 +29,11 @@ private fun Activity.getCurrentFocusOrPlaceholder() = currentFocus ?: View(this) fun Activity.toggleKeyboard() { val imm = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager imm.toggleSoftInput(0, 0) +} + +/** + * Try to start activity if no sure that this activity exits. + */ +fun Activity.startActivitySafely(intent: Intent) { + if (intent.resolveActivity(packageManager) != null) startActivity(intent) } \ No newline at end of file diff --git a/app/src/main/res/values-pl-rPL/strings.xml b/app/src/main/res/values-pl-rPL/strings.xml index 8957654..27900ce 100644 --- a/app/src/main/res/values-pl-rPL/strings.xml +++ b/app/src/main/res/values-pl-rPL/strings.xml @@ -17,6 +17,7 @@ Tagi Tytuł Potwierdź + Skontaktuj się ze mną Usuń Domyślna waluta Usuń wszystkie @@ -30,6 +31,7 @@ Pomyślnie wyeksportowano wydatki do folderu Pobrane. Wydatki Eksportuj do Excela (.xls) + Opinia mile widziana! Filtruj Filtruj tagi Ogólne @@ -41,10 +43,13 @@ Brak tagów Notatki Notatki (opcjonalnie) + Oceń aplikację (4.8 🌟) Zapisz Wybierz walutę Wybierz tagi Ustawienia + Podziel się aplikacją + Udostępnij przez Wydałaś/eś OK Ten miesiąc diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0b29da8..5c97b19 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -16,6 +16,7 @@ Tags Title Confirm + Contact me %1$s\u0020\u0020%2$s Delete Default currency @@ -31,6 +32,7 @@ Expenses exported successfully into Downloads folder. Expenses Export to Excel (.xls) + Feedback is welcome! Filter Filter tags General @@ -42,10 +44,13 @@ No tags Notes Notes (optional) + Rate the app (4.8 🌟) Save Select currency Select tags Settings + Share app + Share with You spent OK This month