Skip to content

Commit

Permalink
Merge pull request #18 from odaridavid/share-app
Browse files Browse the repository at this point in the history
Add share app intent
  • Loading branch information
odaridavid authored May 27, 2020
2 parents 8e0c657 + 9ce9154 commit c835da3
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
defaultConfig {

def versionMajor = 1
def versionMinor = 1
def versionPatch = 2
def versionMinor = 2
def versionPatch = 0

applicationId "com.github.odaridavid.designpatterns"
minSdkVersion 21
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ internal class RatingManager(private val sharedPreferences: SharedPreferences) :
override fun hasGivenRating(): Boolean = sharedPreferences.getBoolean(RATING_PREF_KEY, false)

override fun giveRating() {
with(sharedPreferences.edit()) {
putBoolean(RATING_PREF_KEY, true)
apply()
setPreferenceValue { editor ->
editor.putBoolean(RATING_PREF_KEY, true)
}
}

Expand All @@ -41,8 +40,15 @@ internal class RatingManager(private val sharedPreferences: SharedPreferences) :

override fun updatePromptForRatingCounter() {
val counter = sharedPreferences.getInt(PROMPT_COUNTER_PREF_KEY, 0) + 1
setPreferenceValue { editor ->
editor.putInt(PROMPT_COUNTER_PREF_KEY, counter)
}
}


private fun setPreferenceValue(block: (SharedPreferences.Editor) -> Unit) {
with(sharedPreferences.edit()) {
putInt(PROMPT_COUNTER_PREF_KEY, counter)
block(this)
apply()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ internal class AboutActivity : BaseActivity() {
openBrowser(APP_REPO_URL)
true
}
R.id.action_share_app -> {
val sendIntent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(
Intent.EXTRA_TEXT,
"Checkout Kotlin Design Patterns Samples\n\n https://play.google.com/store/apps/details?id=$packageName"
)
type = "text/plain"
}
startActivity(sendIntent)
true
}
else -> super.onOptionsItemSelected(item)
}
}
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_share_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/colorIconTint"
android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z" />
</vector>
8 changes: 7 additions & 1 deletion app/src/main/res/menu/about_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,11 @@
android:id="@+id/action_open_source_code"
android:icon="@drawable/ic_github_24dp"
android:title="@string/menu_view_source_code"
app:showAsAction="always" />
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_share_app"
android:icon="@drawable/ic_share_24dp"
android:title="@string/menu_share_app"
app:showAsAction="ifRoom" />

</menu>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
<string name="title_rating_dialog">App Rating</string>
<string name="label_dialog_negative_button">Later</string>
<string name="label_dialog_positive_button">Rate</string>
<string name="menu_share_app">Share App</string>


</resources>
3 changes: 2 additions & 1 deletion whatsnew/whatsnew-en-GB
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Enable theme settings icon changing on theme changes by the system.
- Added prompt for user rating
- Added share app action

0 comments on commit c835da3

Please sign in to comment.