Skip to content

Commit

Permalink
add pull to refresh feature; add save to bookmark for context link.
Browse files Browse the repository at this point in the history
  • Loading branch information
plateaukao committed Jun 28, 2021
1 parent 0dc3638 commit 04a7e5b
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 186 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ dependencies {

// for epub saving: html processing
implementation 'org.jsoup:jsoup:1.13.1'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'

def room_version = "2.3.0"
implementation "androidx.room:room-runtime:$room_version"
Expand Down
37 changes: 34 additions & 3 deletions app/src/main/java/de/baumann/browser/activity/BrowserActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import android.widget.TextView.OnEditorActionListener
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import androidx.preference.PreferenceManager
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import de.baumann.browser.Ninja.R
import de.baumann.browser.Ninja.databinding.*
import de.baumann.browser.browser.*
Expand All @@ -51,6 +52,7 @@ import de.baumann.browser.view.viewControllers.TranslationViewController
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.io.*
import java.lang.reflect.Field
import java.util.*
import kotlin.math.floor
import kotlin.math.roundToInt
Expand All @@ -73,6 +75,9 @@ class BrowserActivity : AppCompatActivity(), BrowserController, OnClickListener
private lateinit var searchPanel: ViewGroup
private lateinit var mainContentLayout: FrameLayout
private lateinit var subContainer: RelativeLayout
private val swipeRefreshLayout: SwipeRefreshLayout by lazy {
binding.activityMainContent.swipeRefresh
}

private var fullscreenHolder: FrameLayout? = null

Expand Down Expand Up @@ -195,6 +200,7 @@ class BrowserActivity : AppCompatActivity(), BrowserController, OnClickListener
initSearchPanel()
initOverview()
initTouchArea()
initSwipeRefreshLayout()
updateWebViewCountUI()

AdBlock(this) // For AdBlock cold boot
Expand All @@ -216,6 +222,28 @@ class BrowserActivity : AppCompatActivity(), BrowserController, OnClickListener
shouldLoadTabState = false
}

private fun initSwipeRefreshLayout() {
// change icon
try {
val f: Field = swipeRefreshLayout.javaClass.getDeclaredField("mCircleView")
f.isAccessible = true
val img = f.get(swipeRefreshLayout) as ImageView
img.setBackgroundResource(R.mipmap.ic_launcher)
} catch (e: NoSuchFieldException) {
e.printStackTrace()
} catch (e: IllegalAccessException) {
e.printStackTrace()
}

swipeRefreshLayout.setOnRefreshListener {
ninjaWebView.reload()
swipeRefreshLayout.isRefreshing = false
}
swipeRefreshLayout.viewTreeObserver.addOnScrollChangedListener {
swipeRefreshLayout.isEnabled = (ninjaWebView.scrollY === 0)
}
}

override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)

Expand Down Expand Up @@ -517,9 +545,9 @@ class BrowserActivity : AppCompatActivity(), BrowserController, OnClickListener
}
}

private fun saveBookmark() {
val currentUrl = ninjaWebView.url ?: return
val title = HelperUnit.secString(ninjaWebView.title)
private fun saveBookmark(url: String? = null, title: String? = null) {
val currentUrl = url ?: ninjaWebView.url ?: return
val title = title ?: HelperUnit.secString(ninjaWebView.title)
val context = this
try {
lifecycleScope.launch {
Expand Down Expand Up @@ -1271,6 +1299,9 @@ class BrowserActivity : AppCompatActivity(), BrowserController, OnClickListener
dialogView.contextLinkOpenWith.setOnClickListener {
dialog.dismissWithAction { HelperUnit.showBrowserChooser( this@BrowserActivity, url, getString(R.string.menu_open_with) ) }
}
dialogView.contextLinkSaveBookmark.setOnClickListener {
dialog.dismissWithAction { saveBookmark(url, title = "") }
}
dialogView.contextLinkNewTabOpen.setOnClickListener {
dialog.dismissWithAction { addAlbum(getString(R.string.app_name), url) }
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@
>

<include layout="@layout/activity_main_content"
android:id="@+id/activity_main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

Expand Down
10 changes: 9 additions & 1 deletion app/src/main/res/layout/activity_main_content.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@
android:layout_height="match_parent"
tools:showIn="@layout/activity_main">

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_transparent"
>
</FrameLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

<View android:id="@+id/touch_area_bottom_left"
android:layout_width="150dp"
android:layout_height="250dp"
Expand Down Expand Up @@ -80,7 +88,7 @@
android:id="@+id/fab_imageButtonNav"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignBottom="@+id/main_content"
android:layout_alignBottom="@+id/swipe_refresh"
android:layout_alignParentEnd="true"
android:visibility="gone"
app:borderWidth="1dp"
Expand Down
Loading

0 comments on commit 04a7e5b

Please sign in to comment.