Skip to content

Commit c835da3

Browse files
authored
Merge pull request #18 from odaridavid/share-app
Add share app intent
2 parents 8e0c657 + 9ce9154 commit c835da3

File tree

7 files changed

+44
-8
lines changed

7 files changed

+44
-8
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ android {
1212
defaultConfig {
1313

1414
def versionMajor = 1
15-
def versionMinor = 1
16-
def versionPatch = 2
15+
def versionMinor = 2
16+
def versionPatch = 0
1717

1818
applicationId "com.github.odaridavid.designpatterns"
1919
minSdkVersion 21

app/src/main/java/com/github/odaridavid/designpatterns/RatingManager.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ internal class RatingManager(private val sharedPreferences: SharedPreferences) :
2828
override fun hasGivenRating(): Boolean = sharedPreferences.getBoolean(RATING_PREF_KEY, false)
2929

3030
override fun giveRating() {
31-
with(sharedPreferences.edit()) {
32-
putBoolean(RATING_PREF_KEY, true)
33-
apply()
31+
setPreferenceValue { editor ->
32+
editor.putBoolean(RATING_PREF_KEY, true)
3433
}
3534
}
3635

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

4241
override fun updatePromptForRatingCounter() {
4342
val counter = sharedPreferences.getInt(PROMPT_COUNTER_PREF_KEY, 0) + 1
43+
setPreferenceValue { editor ->
44+
editor.putInt(PROMPT_COUNTER_PREF_KEY, counter)
45+
}
46+
}
47+
48+
49+
private fun setPreferenceValue(block: (SharedPreferences.Editor) -> Unit) {
4450
with(sharedPreferences.edit()) {
45-
putInt(PROMPT_COUNTER_PREF_KEY, counter)
51+
block(this)
4652
apply()
4753
}
4854
}

app/src/main/java/com/github/odaridavid/designpatterns/ui/AboutActivity.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ internal class AboutActivity : BaseActivity() {
5656
openBrowser(APP_REPO_URL)
5757
true
5858
}
59+
R.id.action_share_app -> {
60+
val sendIntent = Intent().apply {
61+
action = Intent.ACTION_SEND
62+
putExtra(
63+
Intent.EXTRA_TEXT,
64+
"Checkout Kotlin Design Patterns Samples\n\n https://play.google.com/store/apps/details?id=$packageName"
65+
)
66+
type = "text/plain"
67+
}
68+
startActivity(sendIntent)
69+
true
70+
}
5971
else -> super.onOptionsItemSelected(item)
6072
}
6173
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:tint="?attr/colorControlNormal"
5+
android:viewportWidth="24"
6+
android:viewportHeight="24">
7+
<path
8+
android:fillColor="@color/colorIconTint"
9+
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" />
10+
</vector>

app/src/main/res/menu/about_menu.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,11 @@
1717
android:id="@+id/action_open_source_code"
1818
android:icon="@drawable/ic_github_24dp"
1919
android:title="@string/menu_view_source_code"
20-
app:showAsAction="always" />
20+
app:showAsAction="ifRoom" />
21+
<item
22+
android:id="@+id/action_share_app"
23+
android:icon="@drawable/ic_share_24dp"
24+
android:title="@string/menu_share_app"
25+
app:showAsAction="ifRoom" />
26+
2127
</menu>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
<string name="title_rating_dialog">App Rating</string>
181181
<string name="label_dialog_negative_button">Later</string>
182182
<string name="label_dialog_positive_button">Rate</string>
183+
<string name="menu_share_app">Share App</string>
183184

184185

185186
</resources>

whatsnew/whatsnew-en-GB

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
- Enable theme settings icon changing on theme changes by the system.
1+
- Added prompt for user rating
2+
- Added share app action

0 commit comments

Comments
 (0)