Skip to content

Commit 97ccee1

Browse files
authored
Fixes (#44)
- Add Fix for API 26-30 Dynamic Color - Add Fix for Back Press in WebView - Add Database Migration
1 parent cbcf3fc commit 97ccee1

File tree

7 files changed

+32
-7
lines changed

7 files changed

+32
-7
lines changed

app/src/main/java/com/djangofiles/djangofiles/db/ServerDao.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import androidx.room.Query
1111
import androidx.room.Room
1212
import androidx.room.RoomDatabase
1313
import androidx.room.Upsert
14+
import androidx.room.migration.Migration
15+
import androidx.sqlite.db.SupportSQLiteDatabase
1416

1517

1618
@Dao
@@ -61,13 +63,25 @@ abstract class ServerDatabase : RoomDatabase() {
6163
@Volatile
6264
private var instance: ServerDatabase? = null
6365

66+
private val MIGRATION_1_2 = object : Migration(1, 2) {
67+
override fun migrate(database: SupportSQLiteDatabase) {
68+
database.execSQL("ALTER TABLE Server ADD COLUMN size INTEGER")
69+
database.execSQL("ALTER TABLE Server ADD COLUMN count INTEGER")
70+
database.execSQL("ALTER TABLE Server ADD COLUMN shorts INTEGER")
71+
database.execSQL("ALTER TABLE Server ADD COLUMN humanSize TEXT")
72+
}
73+
}
74+
6475
fun getInstance(context: Context): ServerDatabase =
6576
instance ?: synchronized(this) {
6677
instance ?: Room.databaseBuilder(
6778
context.applicationContext,
6879
ServerDatabase::class.java,
6980
"server-database"
70-
).build().also { instance = it }
81+
)
82+
//.fallbackToDestructiveMigration(true) // Destructive Operation
83+
.addMigrations(MIGRATION_1_2)
84+
.build().also { instance = it }
7185
}
7286
}
7387
}

app/src/main/java/com/djangofiles/djangofiles/ui/home/HomeFragment.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import android.view.ViewGroup
1313
import android.webkit.CookieManager
1414
import android.webkit.JavascriptInterface
1515
import android.webkit.ValueCallback
16+
import android.webkit.WebBackForwardList
1617
import android.webkit.WebChromeClient
1718
import android.webkit.WebResourceError
1819
import android.webkit.WebResourceRequest
@@ -135,9 +136,16 @@ class HomeFragment : Fragment() {
135136

136137
val callback = object : OnBackPressedCallback(true) {
137138
override fun handleOnBackPressed() {
138-
if (binding.webView.canGoBack()) {
139+
val mWebBackForwardList: WebBackForwardList = binding.webView.copyBackForwardList()
140+
val historyUrl: String? =
141+
mWebBackForwardList.getItemAtIndex(mWebBackForwardList.currentIndex - 1)?.url
142+
Log.d("Home[OnBackPressedCallback]", "historyUrl: $historyUrl")
143+
Log.d("Home[OnBackPressedCallback]", "currentUrl: $currentUrl")
144+
if (binding.webView.canGoBack() && historyUrl?.startsWith(currentUrl) == true) {
145+
Log.d("Home[OnBackPressedCallback]", "binding.webView.goBack")
139146
binding.webView.goBack()
140147
} else {
148+
Log.d("Home[OnBackPressedCallback]", "onBackPressedDispatcher.onBackPressed")
141149
isEnabled = false
142150
requireActivity().onBackPressedDispatcher.onBackPressed()
143151

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<shape xmlns:android="http://schemas.android.com/apk/res/android">
33
<solid android:color="@android:color/transparent" />
4-
<stroke android:width="3dp" android:color="@color/material_dynamic_primary80" />
4+
<stroke android:width="3dp" android:color="@color/selected_border" />
55
<corners android:radius="4dp" />
66
</shape>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<shape xmlns:android="http://schemas.android.com/apk/res/android">
33
<solid android:color="@android:color/transparent" />
4-
<stroke android:width="2dp" android:color="@color/material_dynamic_primary80" />
4+
<stroke android:width="2dp" android:color="@color/selected_border" />
55
<corners android:radius="6dp" />
66
</shape>

app/src/main/res/layout/activity_main.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
45
android:id="@+id/drawer_layout"
56
android:layout_width="match_parent"
67
android:layout_height="match_parent"
7-
android:fitsSystemWindows="true">
8+
android:fitsSystemWindows="true"
9+
tools:openDrawer="start">
810

911
<androidx.fragment.app.FragmentContainerView
1012
android:id="@+id/nav_host_fragment"
@@ -19,7 +21,6 @@
1921
android:layout_width="wrap_content"
2022
android:layout_height="match_parent"
2123
android:layout_gravity="start"
22-
android:fitsSystemWindows="true"
2324
app:headerLayout="@layout/nav_header_main"
2425
app:menu="@menu/drawer_menu" />
2526
</androidx.drawerlayout.widget.DrawerLayout>

app/src/main/res/layout/widget_layout.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
android:layout_width="0dp"
1616
android:layout_height="wrap_content"
1717
android:layout_weight="1"
18-
android:layout_marginStart="16dp"
18+
android:layout_marginStart="10dp"
1919
android:columnCount="2">
2020

2121
<ImageView

app/src/main/res/values/colors.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44

55
<color name="header_start">#7D81D1</color>
66
<color name="header_end">#A4A7E0</color>
7+
8+
<color name="selected_border">#87b3f4</color>
79
</resources>

0 commit comments

Comments
 (0)