Created
August 20, 2018 08:14
-
-
Save philipbjorge/d750602d95e0ff50aece73c3e54f5b12 to your computer and use it in GitHub Desktop.
Android Tutorial Snippets
This file contains hidden or 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
dependencies { | |
implementation 'com.mikepenz:actionitembadge:3.3.2@aar' | |
implementation 'com.mikepenz:iconics-core:3.0.4@aar' | |
implementation 'com.mikepenz:material-design-iconic-typeface:2.2.0.4@aar' | |
} |
This file contains hidden or 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
dependencies { | |
implementation 'com.appnouncements:appnouncements-android:0.1.0' | |
} |
This file contains hidden or 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
override fun onCreateOptionsMenu(menu: Menu?): Boolean { | |
menuInflater.inflate(R.menu.mainmenu, menu) | |
whatsNewToolbarButton = menu!!.findItem(R.id.whatsNewToolbarButton) | |
setWhatsNewBadge(appnouncementsClient?.unseenReleaseNotesCount ?: 0) | |
return true | |
} | |
override fun onOptionsItemSelected(item: MenuItem?): Boolean { | |
if (item?.itemId == R.id.whatsNewToolbarButton) { | |
if (appnouncementsClient != null) { | |
appnouncementsClient!!.showReleaseNotes(this) | |
setWhatsNewBadge(0) | |
} | |
return true | |
} | |
return super.onOptionsItemSelected(item) | |
} | |
override fun onAppnouncementsClientReady(client: Client?) { | |
appnouncementsClient = client | |
setWhatsNewBadge(client!!.unseenReleaseNotesCount) | |
} | |
private fun setWhatsNewBadge(count: Int) { | |
if (count > 0) { | |
ActionItemBadge.update(this, whatsNewToolbarButton, MaterialDesignIconic.Icon.gmi_notifications, ActionItemBadge.BadgeStyles.RED, count) | |
} else { | |
ActionItemBadge.update(this, whatsNewToolbarButton, MaterialDesignIconic.Icon.gmi_notifications_none, null) | |
} | |
} |
This file contains hidden or 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
class MainActivity : AppCompatActivity(), Client.Listener { | |
private var appnouncementsClient: Client? = null | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
Appnouncements.getClientAsync(this) | |
} | |
override fun onAppnouncementsClientReady(client: Client?) { | |
appnouncementsClient = client | |
} | |
override fun onAppnouncementsClientFailed(error: AppnouncementsException?) { | |
Toast.makeText(this, "Failed to get the appnouncements client... See logs.", Toast.LENGTH_LONG).show(); | |
} | |
} |
This file contains hidden or 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
class MyApplication : Application() { | |
override fun onCreate() { | |
super.onCreate() | |
Appnouncements.initialize(this, "c0748bcd-fc09-4a79-b7cb-5de7caf2e233") | |
} | |
} |
This file contains hidden or 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
allprojects { | |
repositories { | |
... | |
maven { url 'https://jitpack.io' } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment