-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from ukrainefield/feature/google-analytics
Feature/google analytics
- Loading branch information
Showing
16 changed files
with
224 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 46 additions & 1 deletion
47
app/app/src/main/java/nl/gardensnakes/ukrainefield/SettingsFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,67 @@ | ||
package nl.gardensnakes.ukrainefield | ||
|
||
import android.content.Intent | ||
import android.net.Uri | ||
import android.os.Bundle | ||
import android.preference.* | ||
import androidx.core.content.ContextCompat | ||
import androidx.preference.Preference | ||
import androidx.preference.PreferenceFragmentCompat | ||
import com.google.firebase.analytics.FirebaseAnalytics | ||
import nl.gardensnakes.ukrainefield.helper.BookmarkHelper | ||
import nl.gardensnakes.ukrainefield.helper.Consts | ||
import nl.gardensnakes.ukrainefield.helper.FirebaseHelper | ||
|
||
class SettingsFragment : PreferenceFragmentCompat() { | ||
|
||
private lateinit var mFirebaseAnalytics: FirebaseAnalytics | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
mFirebaseAnalytics = FirebaseAnalytics.getInstance(requireContext()); | ||
FirebaseHelper.updateCurrentScreen(mFirebaseAnalytics, this.requireActivity(), this.javaClass.simpleName, this.javaClass.simpleName) | ||
} | ||
|
||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { | ||
setPreferencesFromResource(R.xml.settings, rootKey) | ||
setupResetBookmarksClick() | ||
setupNewsSourcesClick() | ||
setupGithubReposClick() | ||
setupTwitterClick() | ||
} | ||
|
||
private fun setupResetBookmarksClick() { | ||
findPreference<Preference>("reset_bookmarks")?.setOnPreferenceClickListener { | ||
FirebaseHelper.logResetBookmarks(mFirebaseAnalytics) | ||
context?.let { context -> BookmarkHelper().resetBookmarks(context) } | ||
true | ||
} | ||
} | ||
|
||
private fun setupTwitterClick() { | ||
findPreference<Preference>("twitter_link")?.setOnPreferenceClickListener { | ||
FirebaseHelper.logVisitOfficialLink(mFirebaseAnalytics, Consts.TWITTER_LINK) | ||
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(Consts.TWITTER_LINK)) | ||
ContextCompat.startActivity(requireContext(), browserIntent, null) | ||
true | ||
} | ||
} | ||
|
||
private fun setupGithubReposClick() { | ||
findPreference<Preference>("github_link")?.setOnPreferenceClickListener { | ||
FirebaseHelper.logVisitOfficialLink(mFirebaseAnalytics, Consts.GITHUB_LINK) | ||
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(Consts.GITHUB_LINK)) | ||
ContextCompat.startActivity(requireContext(), browserIntent, null) | ||
true | ||
} | ||
} | ||
|
||
private fun setupNewsSourcesClick() { | ||
findPreference<Preference>("news_sources_link")?.setOnPreferenceClickListener { | ||
FirebaseHelper.logVisitOfficialLink(mFirebaseAnalytics, Consts.NEWSSOURCES_LINK) | ||
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(Consts.NEWSSOURCES_LINK)) | ||
ContextCompat.startActivity(requireContext(), browserIntent, null) | ||
true | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
app/app/src/main/java/nl/gardensnakes/ukrainefield/helper/Consts.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package nl.gardensnakes.ukrainefield.helper | ||
|
||
object Consts { | ||
val NEWSSOURCES_LINK: String = "https://github.com/ukrainefield/data-fetcher/blob/main/consts.json" | ||
val GITHUB_LINK: String = "https://github.com/ukrainefield" | ||
val TWITTER_LINK: String = "https://twitter.com/fieldukraine" | ||
} |
42 changes: 42 additions & 0 deletions
42
app/app/src/main/java/nl/gardensnakes/ukrainefield/helper/FirebaseHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package nl.gardensnakes.ukrainefield.helper | ||
|
||
import android.app.Activity | ||
import android.os.Bundle | ||
import com.google.firebase.analytics.FirebaseAnalytics | ||
|
||
class FirebaseHelper { | ||
companion object { | ||
fun updateCurrentScreen(firebase: FirebaseAnalytics, activity: Activity, activityName: String, className: String){ | ||
firebase.setCurrentScreen(activity, activityName, className); | ||
} | ||
fun logShareEvent(firebase: FirebaseAnalytics, messageUrl: String){ | ||
val params = Bundle() | ||
params.putString("share_message", messageUrl) | ||
firebase.logEvent("eventShareMessage", params) | ||
} | ||
fun logOpenInBrowserEvent(firebase: FirebaseAnalytics, messageUrl: String){ | ||
val params = Bundle() | ||
params.putString("open_message_in_browser", messageUrl) | ||
firebase.logEvent("eventOpenMessageInBrowser", params) | ||
} | ||
fun logBookmarkEvent(firebase: FirebaseAnalytics, messageId: String){ | ||
val params = Bundle() | ||
params.putString("message_id", messageId) | ||
firebase.logEvent("eventBookmarkMessage", params) | ||
} | ||
fun logUnbookmarkEvent(firebase: FirebaseAnalytics, messageUrl: String){ | ||
val params = Bundle() | ||
params.putString("message_id", messageUrl) | ||
firebase.logEvent("eventUnbookmarkMessage", params) | ||
} | ||
fun logVisitOfficialLink(firebase: FirebaseAnalytics, linkUrl: String){ | ||
val params = Bundle() | ||
params.putString("link_url", linkUrl) | ||
firebase.logEvent("eventVisitOfficialLink", params) | ||
} | ||
fun logResetBookmarks(firebase: FirebaseAnalytics){ | ||
val params = Bundle() | ||
firebase.logEvent("eventResetBookmarks", params) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.