Skip to content

Commit 4e15721

Browse files
author
Edd
committed
worked on ui and ui rendering using recycler view for a better and responsive app
1 parent 26a1d87 commit 4e15721

File tree

117 files changed

+1901
-362
lines changed

Some content is hidden

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

117 files changed

+1901
-362
lines changed

app/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ android {
3232
jvmTarget = "1.8"
3333
}
3434

35+
testOptions {
36+
unitTests.returnDefaultValues = true
37+
}
38+
3539
}
3640

3741
kapt {
@@ -47,10 +51,12 @@ dependencies {
4751
implementation Deps.coordinator
4852
implementation Deps.recyclerView
4953
implementation Deps.swipeRefreshLayout
54+
implementation Deps.preference
5055
implementation Deps.design
5156
implementation Deps.cardview
5257
implementation Deps.core
5358
implementation Deps.coroutines
59+
implementation Deps.googlePlayServices
5460

5561
//lifecycle
5662
implementation Deps.viewmodel
@@ -71,7 +77,9 @@ dependencies {
7177

7278
testImplementation Deps.mockk
7379
testImplementation Deps.mockito
80+
testImplementation Deps.mockitoInline
7481
testImplementation Deps.junit
82+
testImplementation Deps.coreTesting
7583

7684

7785
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<resources>
2+
<!--
3+
TODO: Before you run your application, you need a Google Maps API key.
4+
5+
To get one, follow this link, follow the directions and press "Create" at the end:
6+
7+
https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=FE:8D:A5:ED:A4:8A:C3:BB:2D:B8:D6:E8:80:C0:30:33:7B:38:82:49%3Bcom.github.amazingweather.presentation.ui.map
8+
9+
You can also add your credentials to an existing key, using these values:
10+
11+
Package name:
12+
com.github.amazingweather.presentation.ui.map
13+
14+
SHA-1 certificate fingerprint:
15+
FE:8D:A5:ED:A4:8A:C3:BB:2D:B8:D6:E8:80:C0:30:33:7B:38:82:49
16+
17+
Alternatively, follow the directions here:
18+
https://developers.google.com/maps/documentation/android/start#get-key
19+
20+
Once you have your key (it starts with "AIza"), replace the "google_maps_key"
21+
string in this file.
22+
-->
23+
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">AIzaSyDkSlAi6_akVSwherQ2eximZ2UqGc_uTf8</string>
24+
</resources>

app/src/main/AndroidManifest.xml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,44 @@
1+
<?xml version="1.0" encoding="utf-8"?>
12
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
23
package="com.github.amazingweather">
34

5+
<!--
6+
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
7+
Google Maps Android API v2, but you must specify either coarse or fine
8+
location permissions for the 'MyLocation' functionality.
9+
-->
10+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
411
<uses-permission android:name="android.permission.INTERNET" />
512

613
<application
7-
android:name="App"
14+
android:name=".App"
815
android:allowBackup="true"
916
android:icon="@mipmap/ic_launcher"
1017
android:label="@string/app_name"
1118
android:roundIcon="@mipmap/ic_launcher_round"
1219
android:supportsRtl="true"
1320
android:theme="@style/AppTheme">
1421

15-
<activity android:name=".presentation.FragmentContainerActivity">
22+
<!--
23+
The API key for Google Maps-based APIs is defined as a string resource.
24+
(See the file "res/values/google_maps_api.xml").
25+
Note that the API key is linked to the encryption key used to sign the APK.
26+
You need a different API key for each encryption key, including the release key that is used to
27+
sign the APK for publishing.
28+
You can define the keys for the debug and release targets in src/debug/ and src/release/.
29+
-->
30+
<meta-data
31+
android:name="com.google.android.geo.API_KEY"
32+
android:value="@string/google_maps_key" />
33+
34+
<activity android:name="com.github.amazingweather.presentation.ui.activity.FragmentContainerActivity">
1635
<intent-filter>
1736
<action android:name="android.intent.action.MAIN" />
1837

1938
<category android:name="android.intent.category.LAUNCHER" />
2039
<category android:name="android.intent.category.DEFAULT" />
2140
</intent-filter>
2241
</activity>
23-
2442
</application>
25-
</manifest>
43+
44+
</manifest>

app/src/main/java/com/github/amazingweather/App.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.amazingweather
22

3+
import com.github.amazingweather.core.ext.setDefaultUiMode
34
import com.github.amazingweather.di.DaggerAppComponent
45
import dagger.android.AndroidInjector
56
import dagger.android.DaggerApplication
@@ -8,7 +9,7 @@ class App : DaggerApplication() {
89

910
override fun onCreate() {
1011
super.onCreate()
11-
12+
setDefaultUiMode()
1213
}
1314

1415
override fun applicationInjector(): AndroidInjector<out DaggerApplication> {

app/src/main/java/com/github/amazingweather/core/CoreExt.kt

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.github.amazingweather.core.ext
2+
3+
import android.content.pm.PackageManager
4+
import android.os.Bundle
5+
import androidx.fragment.app.Fragment
6+
import androidx.lifecycle.lifecycleScope
7+
import com.github.amazingweather.R
8+
import com.github.amazingweather.presentation.ui.activity.FragmentContainerActivity
9+
10+
fun FragmentContainerActivity.openFragment(
11+
fragment: Fragment,
12+
replace: Boolean,
13+
addToBackStack: Boolean,
14+
bundle: Bundle? = null
15+
) {
16+
if (bundle == null)
17+
lifecycleScope.launchWhenStarted {
18+
hideSearch()
19+
supportFragmentManager.beginTransaction().apply {
20+
if (replace)
21+
replace(R.id.container, fragment, fragment.javaClass.simpleName)
22+
else
23+
add(R.id.container, fragment, fragment.javaClass.simpleName)
24+
25+
if (addToBackStack)
26+
addToBackStack(fragment.javaClass.simpleName)
27+
commit()
28+
}
29+
}
30+
}
31+
32+
fun IntArray.areAllGranted() = all { it == PackageManager.PERMISSION_GRANTED }

app/src/main/java/com/github/amazingweather/network/ApiExt.kt renamed to app/src/main/java/com/github/amazingweather/core/ext/ApiExt.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
package com.github.amazingweather.network
1+
package com.github.amazingweather.core.ext
22

33
import com.github.amazingweather.core.EitherErrorOr
44
import com.github.amazingweather.core.Result
5-
import com.github.amazingweather.core.toResultError
65
import kotlinx.coroutines.Dispatchers
76
import kotlinx.coroutines.withContext
87
import retrofit2.Call
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.github.amazingweather.core.ext
2+
3+
import android.content.Context
4+
import androidx.appcompat.app.AppCompatDelegate
5+
import androidx.preference.PreferenceManager
6+
import com.github.amazingweather.R
7+
import com.github.amazingweather.core.Result
8+
import java.net.SocketTimeoutException
9+
import java.net.UnknownHostException
10+
import javax.net.ssl.SSLException
11+
12+
fun Exception.toResultError() = when (this) {
13+
is UnknownHostException, is SocketTimeoutException, is SSLException -> Result.Error.NetworkError
14+
else -> Result.Error.Exception(this)
15+
}
16+
17+
fun Context.setDefaultUiMode(uiMode: String? = null) {
18+
when (
19+
uiMode ?: PreferenceManager.getDefaultSharedPreferences(this.applicationContext).getString(getString(R.string.app_theme), "2")
20+
) {
21+
"0" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
22+
"1" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
23+
else -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
24+
}
25+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.github.amazingweather.core.ext
2+
3+
import java.text.SimpleDateFormat
4+
import java.util.*
5+
6+
fun Long.getDayOfTheWeek(): String {
7+
return SimpleDateFormat("EEE", Locale.US).format(Date(this * 1000))
8+
}

app/src/main/java/com/github/amazingweather/core/FragmentExt.kt renamed to app/src/main/java/com/github/amazingweather/core/ext/FragmentExt.kt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
package com.github.amazingweather.core
1+
package com.github.amazingweather.core.ext
22

3+
import android.view.View
4+
import androidx.annotation.StringRes
35
import androidx.core.os.bundleOf
46
import androidx.fragment.app.Fragment
57
import androidx.lifecycle.LiveData
68
import androidx.lifecycle.Observer
7-
import androidx.lifecycle.ViewModelProvider.Factory
8-
import androidx.lifecycle.ViewModel
9-
import androidx.lifecycle.ViewModelProvider
10-
import com.github.amazingweather.presentation.ViewModelFactory
9+
import com.google.android.material.snackbar.Snackbar
1110

1211
fun <T : Any, L : LiveData<T>> Fragment.observe(liveData: L, body: (T) -> Unit) {
1312
liveData.observe(viewLifecycleOwner, Observer(body))
@@ -21,4 +20,17 @@ inline fun <reified T : Fragment> newFragment(vararg params: Pair<String, Any>):
2120

2221
inline fun <reified T> Fragment.args(key: String, default: T) = lazy {
2322
(arguments?.get(key) ?: default) as T
24-
}
23+
}
24+
25+
fun View.snackbar(@StringRes text: Int, @StringRes buttonText: Int, action: () -> Unit) {
26+
Snackbar
27+
.make(this, text, Snackbar.LENGTH_LONG)
28+
.setAction(buttonText) { action() }
29+
.show()
30+
}
31+
32+
fun View.snackbar(@StringRes text: Int) {
33+
Snackbar
34+
.make(this, text, Snackbar.LENGTH_LONG)
35+
.show()
36+
}

0 commit comments

Comments
 (0)