Skip to content

Commit 5a2cff0

Browse files
Merge pull request #13 from DevelopersBreach/v1.1.0
Improved view model usage, made changes for all fragments.
2 parents ba52850 + 02b5a01 commit 5a2cff0

Some content is hidden

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

53 files changed

+1247
-523
lines changed

.idea/misc.xml

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

.idea/render.experimental.xml

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

app/build.gradle

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ android {
1414

1515
defaultConfig {
1616
applicationId "com.developerbreach.developerbreach"
17-
minSdkVersion 21
17+
minSdkVersion 24
1818
targetSdkVersion 31
1919
versionCode 2
2020
versionName "1.1.0"
@@ -49,13 +49,13 @@ dependencies {
4949
implementation 'androidx.core:core-ktx:1.7.0'
5050

5151
// Degrade on older versions of Android
52-
implementation 'androidx.appcompat:appcompat:1.3.1'
52+
implementation 'androidx.appcompat:appcompat:1.4.0'
5353

5454
// Support library
5555
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
5656

5757
// Constraint Layout
58-
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
58+
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
5959

6060
// Navigation Component
6161
implementation "androidx.navigation:navigation-fragment-ktx:2.3.5"
@@ -78,7 +78,7 @@ dependencies {
7878
implementation 'androidx.preference:preference-ktx:1.1.1'
7979

8080
// Fragment
81-
implementation "androidx.fragment:fragment-ktx:1.3.6"
81+
implementation "androidx.fragment:fragment-ktx:1.4.0"
8282

8383
// Glide
8484
implementation 'com.github.bumptech.glide:glide:4.11.0'
@@ -92,9 +92,6 @@ dependencies {
9292
implementation "androidx.room:room-runtime:2.3.0"
9393
kapt "androidx.room:room-compiler:2.3.0"
9494

95-
// Work Manager
96-
implementation "androidx.work:work-runtime-ktx:2.7.0"
97-
9895
// Firebase
9996
implementation 'com.google.firebase:firebase-messaging:23.0.0'
10097
implementation 'com.google.firebase:firebase-analytics:20.0.0'

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.developerbreach.developerbreach">
44

5+
<uses-permission android:name="android.permission.INTERNET" />
6+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
7+
58
<application
69
android:name="com.developerbreach.developerbreach.DevelopersBreachApp"
710
android:allowBackup="false"
Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,16 @@
11
package com.developerbreach.developerbreach
22

33
import android.app.Application
4-
import android.os.Build
5-
import androidx.work.*
6-
import com.developerbreach.developerbreach.worker.ArticleRefreshWorker
7-
import kotlinx.coroutines.CoroutineScope
8-
import kotlinx.coroutines.Dispatchers
9-
import kotlinx.coroutines.launch
104
import timber.log.Timber
11-
import java.util.concurrent.TimeUnit
125

136
@Suppress("unused")
147
class DevelopersBreachApp : Application() {
158

16-
private val applicationScope = CoroutineScope(Dispatchers.Default)
17-
189
override fun onCreate() {
1910
super.onCreate()
20-
delayedInit()
2111

2212
if (BuildConfig.DEBUG) {
2313
Timber.plant(Timber.DebugTree())
2414
}
2515
}
26-
27-
private fun setupRecurringWork() {
28-
29-
val constraints = Constraints.Builder()
30-
.setRequiredNetworkType(NetworkType.UNMETERED)
31-
.apply {
32-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
33-
setRequiresDeviceIdle(true)
34-
}
35-
}.build()
36-
37-
// creates and executes the same work once a day.
38-
val repeatingRequest: PeriodicWorkRequest =
39-
PeriodicWorkRequestBuilder<ArticleRefreshWorker>(1, TimeUnit.DAYS)
40-
.setConstraints(constraints)
41-
.build()
42-
43-
/**
44-
* Create an instance for [WorkManager] with context and work properties which are
45-
* required by work manager do complete the task.
46-
*/
47-
WorkManager.getInstance(applicationContext).enqueueUniquePeriodicWork(
48-
ArticleRefreshWorker.WORKER_NAME,
49-
ExistingPeriodicWorkPolicy.KEEP,
50-
repeatingRequest
51-
)
52-
}
53-
54-
private fun delayedInit() {
55-
applicationScope.launch {
56-
setupRecurringWork()
57-
}
58-
}
5916
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,11 @@ class AppNavDirections(
114114
fun optionsToIntro() {
115115
navController.navigate(OptionsFragmentDirections.optionsToIntro())
116116
}
117+
118+
/** NetworkFragment **/
119+
120+
fun toNetworkFragment() {
121+
navController.navigate(R.id.networkFragment)
122+
}
117123
}
118124

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,23 @@ import android.os.Build
66
import android.os.Bundle
77
import androidx.appcompat.app.AppCompatActivity
88
import androidx.databinding.DataBindingUtil
9+
import androidx.navigation.NavController
910
import androidx.navigation.Navigation
1011
import com.developerbreach.developerbreach.R
1112
import com.developerbreach.developerbreach.databinding.ActivityMainBinding
13+
import com.developerbreach.developerbreach.view.network.NetworkManager
14+
1215

1316
class MainActivity : AppCompatActivity() {
1417

18+
private lateinit var navController: NavController
19+
1520
override fun onCreate(savedInstanceState: Bundle?) {
1621
super.onCreate(savedInstanceState)
1722
DataBindingUtil.setContentView<ActivityMainBinding>(this, R.layout.activity_main)
1823

1924
// NavigationController to set default NavHost as nav_host_fragment.
20-
val navController = Navigation.findNavController(this, R.id.nav_host_fragment)
25+
navController = Navigation.findNavController(this, R.id.nav_host_fragment)
2126

2227
navController.addOnDestinationChangedListener { controller, destination, _ ->
2328
onDestinationChanged(destination, controller)
@@ -27,6 +32,16 @@ class MainActivity : AppCompatActivity() {
2732
setNotificationChannel()
2833
}
2934

35+
override fun onResume() {
36+
super.onResume()
37+
val connected = NetworkManager(applicationContext).isConnected
38+
connected.observe(this, { available ->
39+
if (!available) {
40+
AppNavDirections(navController).toNetworkFragment()
41+
}
42+
})
43+
}
44+
3045
private fun setNotificationChannel() {
3146
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
3247
// Create channel to show notifications.
Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,11 @@
11
package com.developerbreach.developerbreach.model
22

3-
import android.content.Context
43
import android.graphics.drawable.Drawable
5-
import androidx.core.content.ContextCompat
6-
import com.developerbreach.developerbreach.R
74

85

96
data class Intro(
107
val id: Int,
118
val subtitle: String,
129
val banner: Drawable?,
1310
val background: Drawable?
14-
) {
15-
16-
companion object {
17-
18-
fun addIntroData(
19-
context: Context,
20-
): List<Intro> = listOf(
21-
Intro(
22-
1,
23-
context.getString(R.string.intro_pager_first_subtitle_text),
24-
ContextCompat.getDrawable(context, R.drawable.ic_logo),
25-
ContextCompat.getDrawable(context, R.drawable.ic_one_pager_intro)
26-
),
27-
Intro(
28-
2,
29-
context.getString(R.string.intro_pager_second_subtitle_text),
30-
ContextCompat.getDrawable(context, R.drawable.ic_mobile_apps),
31-
ContextCompat.getDrawable(context, R.drawable.ic_two_pager_intro)
32-
),
33-
Intro(
34-
3,
35-
context.getString(R.string.intro_pager_third_subtitle_text),
36-
ContextCompat.getDrawable(context, R.drawable.ic_developer_activity),
37-
ContextCompat.getDrawable(context, R.drawable.ic_three_pager_intro)
38-
),
39-
Intro(
40-
4,
41-
context.getString(R.string.intro_pager_fourth_subtitle_text),
42-
ContextCompat.getDrawable(context, R.drawable.ic_content_creation),
43-
ContextCompat.getDrawable(context, R.drawable.ic_four_pager_intro)
44-
)
45-
)
46-
}
47-
}
11+
)
Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,8 @@
11
package com.developerbreach.developerbreach.model
22

3-
import android.content.Context
4-
import com.developerbreach.developerbreach.R
53

64
data class Options(
75
val optionsId: Int,
86
val optionsTitle: String,
97
val optionsIcon: Int,
10-
) {
11-
12-
companion object {
13-
14-
fun addOptionsData(
15-
context: Context,
16-
): List<Options> = listOf(
17-
Options(1, context.getString(R.string.item_options_favorites), R.drawable.ic_favorite_add),
18-
Options(2, context.getString(R.string.item_options_search), R.drawable.ic_search),
19-
Options(3, context.getString(R.string.item_options_authors), R.drawable.ic_author),
20-
Options(4, context.getString(R.string.item_options_settings), R.drawable.ic_settings),
21-
Options(5, context.getString(R.string.item_options_about), R.drawable.ic_about)
22-
)
23-
}
24-
}
8+
)

app/src/main/java/com/developerbreach/developerbreach/repository/AppRepository.kt

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.developerbreach.developerbreach.repository
22

3-
import android.content.Context
43
import androidx.lifecycle.LiveData
54
import androidx.lifecycle.Transformations
65
import com.developerbreach.developerbreach.model.*
@@ -11,7 +10,6 @@ import com.developerbreach.developerbreach.repository.network.*
1110
import com.developerbreach.developerbreach.repository.network.getArticles
1211
import kotlinx.coroutines.Dispatchers
1312
import kotlinx.coroutines.withContext
14-
import java.io.IOException
1513

1614

1715
class AppRepository(
@@ -83,17 +81,6 @@ class AppRepository(
8381
favoritesEntityList.asDomainModel()
8482
}
8583

86-
suspend fun refreshArticles() {
87-
withContext(Dispatchers.IO) {
88-
try {
89-
//val articlesList: List<Article> = getArticles()
90-
91-
} catch (e: IOException) {
92-
e.printStackTrace()
93-
}
94-
}
95-
}
96-
9784
suspend fun insertArticleToFavorites(
9885
article: Article
9986
) {
@@ -109,8 +96,4 @@ class AppRepository(
10996
database.favoriteDao.deleteFavoriteArticle(article.asDatabaseModel())
11097
}
11198
}
112-
113-
fun optionsList(context: Context): List<Options> {
114-
return Options.addOptionsData(context)
115-
}
11699
}

0 commit comments

Comments
 (0)