Skip to content

Commit fb8f707

Browse files
Merge pull request #15 from DevelopersBreach/v1.1.0
Improved layouts design, dark/light theme support.
2 parents 0f98e51 + 67ff86c commit fb8f707

File tree

98 files changed

+1414
-1671
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+1414
-1671
lines changed

.idea/misc.xml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ plugins {
55
id 'kotlin-parcelize'
66
id 'androidx.navigation.safeargs.kotlin'
77
id 'com.google.gms.google-services'
8+
id 'com.google.firebase.crashlytics'
89
}
910

1011
android {
@@ -94,6 +95,7 @@ dependencies {
9495

9596
// Firebase
9697
implementation 'com.google.firebase:firebase-messaging:23.0.0'
98+
implementation 'com.google.firebase:firebase-crashlytics-ktx:18.2.4'
9799
implementation 'com.google.firebase:firebase-analytics:20.0.0'
98100

99101
// Library to zoom view

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
77

88
<application
9-
android:name="com.developerbreach.developerbreach.DevelopersBreachApp"
9+
android:name=".DevelopersBreachApp"
1010
android:allowBackup="false"
1111
android:icon="@mipmap/ic_launcher"
1212
android:label="@string/app_name"
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
11
package com.developerbreach.developerbreach
22

33
import android.app.Application
4+
import com.developerbreach.developerbreach.repository.AppRepository
5+
import com.developerbreach.developerbreach.repository.database.DatabaseRepository
6+
import com.developerbreach.developerbreach.repository.local.LocalRepository
7+
import com.developerbreach.developerbreach.repository.network.NetworkRepository
48
import timber.log.Timber
59

6-
@Suppress("unused")
710
class DevelopersBreachApp : Application() {
811

12+
lateinit var databaseRepository: DatabaseRepository
13+
lateinit var networkRepository: NetworkRepository
14+
lateinit var localRepository: LocalRepository
15+
916
override fun onCreate() {
1017
super.onCreate()
1118

19+
initializeRepository()
20+
1221
if (BuildConfig.DEBUG) {
1322
Timber.plant(Timber.DebugTree())
1423
}
1524
}
25+
26+
private fun initializeRepository() {
27+
val repository = AppRepository(applicationContext)
28+
databaseRepository = repository.databaseRepository
29+
networkRepository = repository.networkRepository
30+
localRepository = repository.localRepository
31+
}
1632
}

app/src/main/java/com/developerbreach/developerbreach/controller/AppNavDirections.kt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ import com.google.android.material.card.MaterialCardView
2121

2222

2323
class AppNavDirections(
24-
private val navController: NavController,
24+
private val navController: NavController
2525
) {
2626

27-
private fun navigate(directions: NavDirections) {
27+
private fun navigate(
28+
directions: NavDirections
29+
) {
2830
navController.navigate(directions)
2931
}
3032

@@ -55,7 +57,10 @@ class AppNavDirections(
5557
fun toNetworkFragment() = navigate(NetworkFragmentDirections.toNetworkFragmentGlobal())
5658

5759
/** SearchFragment */
58-
fun searchToDetail(articleId: Int, view: TextView) {
60+
fun searchToDetail(
61+
articleId: Int,
62+
view: TextView
63+
) {
5964
navigateWithExtras(
6065
ArticleDetailFragmentDirections.toDetailFragmentGlobal(articleId),
6166
FragmentNavigatorExtras(view to articleId.toString())
@@ -78,19 +83,26 @@ class AppNavDirections(
7883
}
7984

8085
/** DetailFragment */
81-
fun detailToArticleWebView(articleUrlLink: String?) {
86+
fun detailToArticleWebView(
87+
articleUrlLink: String?
88+
) {
8289
navigate(ArticleDetailFragmentDirections.detailToArticleWebView(articleUrlLink))
8390
}
8491

85-
fun detailToBanner(bannerUrl: String?, view: ImageView) {
92+
fun detailToBanner(
93+
bannerUrl: String?,
94+
view: ImageView
95+
) {
8696
navigateWithExtras(
8797
ArticleDetailFragmentDirections.detailToBanner(bannerUrl),
8898
FragmentNavigatorExtras(view as View to bannerUrl.toString())
8999
)
90100
}
91101

92102
/** SettingsFragment */
93-
fun settingsToCommonWebView(webUrl: String) {
103+
fun settingsToCommonWebView(
104+
webUrl: String
105+
) {
94106
navigate(SettingsFragmentDirections.settingsToCommonWebView(webUrl))
95107
}
96108
}
Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,32 @@
11
package com.developerbreach.developerbreach.controller
22

3-
import android.app.NotificationChannel
4-
import android.app.NotificationManager
5-
import android.os.Build
63
import android.os.Bundle
74
import androidx.appcompat.app.AppCompatActivity
85
import androidx.databinding.DataBindingUtil
96
import androidx.navigation.NavController
107
import androidx.navigation.Navigation
118
import com.developerbreach.developerbreach.R
129
import com.developerbreach.developerbreach.databinding.ActivityMainBinding
13-
import com.developerbreach.developerbreach.view.network.NetworkManager
10+
import com.developerbreach.developerbreach.fcm.setNotificationChannel
11+
import com.developerbreach.developerbreach.networkManager.NetworkManager
1412

1513

1614
class MainActivity : AppCompatActivity() {
1715

18-
private lateinit var navController: NavController
16+
lateinit var navController: NavController
1917

2018
override fun onCreate(savedInstanceState: Bundle?) {
2119
super.onCreate(savedInstanceState)
2220
DataBindingUtil.setContentView<ActivityMainBinding>(this, R.layout.activity_main)
2321

2422
// NavigationController to set default NavHost as nav_host_fragment.
2523
navController = Navigation.findNavController(this, R.id.nav_host_fragment)
26-
27-
navController.addOnDestinationChangedListener { controller, destination, _ ->
28-
onDestinationChanged(destination, controller)
24+
navController.addOnDestinationChangedListener { _, destination, _ ->
25+
onDestinationChanged(destination)
2926
}
3027

31-
// Creates a notification channel based on version
32-
setNotificationChannel()
28+
// Creates a notification channel based on SDK level
29+
setNotificationChannel(applicationContext)
3330
}
3431

3532
override fun onResume() {
@@ -41,19 +38,4 @@ class MainActivity : AppCompatActivity() {
4138
}
4239
})
4340
}
44-
45-
private fun setNotificationChannel() {
46-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
47-
// Create channel to show notifications.
48-
val channelId = getString(R.string.default_notification_channel_id)
49-
val channelName = getString(R.string.default_notification_channel_name)
50-
val notificationManager = getSystemService(NotificationManager::class.java)
51-
notificationManager?.createNotificationChannel(
52-
NotificationChannel(
53-
channelId,
54-
channelName, NotificationManager.IMPORTANCE_LOW
55-
)
56-
)
57-
}
58-
}
5941
}

app/src/main/java/com/developerbreach/developerbreach/controller/MainActivityBindingAdapter.kt

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.developerbreach.developerbreach.controller
2+
3+
import androidx.activity.OnBackPressedCallback
4+
import androidx.core.content.ContextCompat
5+
import androidx.navigation.NavDestination
6+
import com.developerbreach.developerbreach.R
7+
8+
9+
fun MainActivity.onDestinationChanged(
10+
destination: NavDestination,
11+
) {
12+
when (destination.id) {
13+
14+
R.id.introFragment -> {
15+
navigateUpOnBackPress()
16+
setSystemUIColor(R.color.colorLowWave)
17+
}
18+
19+
R.id.homeFragment -> {
20+
finishActivityOnBackPress()
21+
setSystemUIColor(R.color.colorBackground)
22+
}
23+
24+
R.id.articleDetailFragment -> {
25+
navigateUpOnBackPress()
26+
setSystemUIColor(R.color.surfaceColor)
27+
}
28+
29+
R.id.searchFragment, R.id.articleWebViewFragment, R.id.bannerFragment,
30+
R.id.commonWebViewFragment, R.id.favoritesFragment, R.id.authorsFragment,
31+
R.id.articleListFragment, R.id.settingsFragment, R.id.optionsFragment -> {
32+
navigateUpOnBackPress()
33+
}
34+
}
35+
}
36+
37+
private fun MainActivity.setSystemUIColor(
38+
navigationBarColor: Int
39+
) {
40+
window.navigationBarColor = ContextCompat.getColor(applicationContext, navigationBarColor)
41+
}
42+
43+
private fun MainActivity.finishActivityOnBackPress() {
44+
onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) {
45+
override fun handleOnBackPressed() {
46+
finish()
47+
}
48+
})
49+
}
50+
51+
private fun MainActivity.navigateUpOnBackPress() {
52+
val activity = this
53+
onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) {
54+
override fun handleOnBackPressed() {
55+
activity.navController.navigateUp()
56+
}
57+
})
58+
}
Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
package com.developerbreach.developerbreach.fcm
22

3-
import android.annotation.SuppressLint
4-
import android.app.NotificationChannel
5-
import android.app.NotificationManager
6-
import android.app.PendingIntent
7-
import android.content.Context
8-
import android.content.Intent
9-
import android.media.RingtoneManager
10-
import android.os.Build
11-
import androidx.core.app.NotificationCompat
12-
import com.developerbreach.developerbreach.R
13-
import com.developerbreach.developerbreach.controller.MainActivity
143
import com.google.firebase.messaging.FirebaseMessagingService
154
import com.google.firebase.messaging.RemoteMessage
165

@@ -19,49 +8,12 @@ class AppFirebaseService : FirebaseMessagingService() {
198

209
override fun onMessageReceived(remoteMessage: RemoteMessage) {
2110
super.onMessageReceived(remoteMessage)
22-
val title: String? = remoteMessage.notification!!.title
23-
val body: String? = remoteMessage.notification!!.body
24-
sendNotification(title!!, body!!)
11+
val title: String? = remoteMessage.notification?.title
12+
val body: String? = remoteMessage.notification?.body
13+
sendFirebaseNotification(title, body, applicationContext)
2514
}
2615

27-
override fun onNewToken(token: String) {}
28-
29-
/**
30-
* Create and show a simple notification containing the received FCM message.
31-
*
32-
* @param body FCM message body received.
33-
*/
34-
@SuppressLint("UnspecifiedImmutableFlag")
35-
private fun sendNotification(title: String, body: String) {
36-
37-
val intent = Intent(this, MainActivity::class.java)
38-
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
39-
val pendingIntent = PendingIntent.getActivity(
40-
this, 0, intent, PendingIntent.FLAG_ONE_SHOT
41-
)
42-
val channelId = getString(R.string.default_notification_channel_id)
43-
val channelName = getString(R.string.default_notification_channel_name)
44-
val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
45-
46-
val notificationBuilder = NotificationCompat
47-
.Builder(this, channelId)
48-
.setSmallIcon(R.drawable.ic_logo)
49-
.setContentTitle(title)
50-
.setContentText(body)
51-
.setAutoCancel(true)
52-
.setSound(defaultSoundUri)
53-
.setContentIntent(pendingIntent)
54-
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE)
55-
as NotificationManager
56-
57-
// Since android Oreo notification channel is needed.
58-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
59-
val channel = NotificationChannel(
60-
channelId, channelName,
61-
NotificationManager.IMPORTANCE_DEFAULT
62-
)
63-
notificationManager.createNotificationChannel(channel)
64-
}
65-
notificationManager.notify(0, notificationBuilder.build())
16+
override fun onNewToken(token: String) {
17+
// Triggers when a new token is generated.
6618
}
6719
}

0 commit comments

Comments
 (0)