feat: requests in-app

This commit is contained in:
nomadics9 2024-06-30 21:33:00 +03:00
parent 5c283982bb
commit f269bea184
11 changed files with 138 additions and 4 deletions

View file

@ -92,7 +92,7 @@ class MainActivity : AppCompatActivity() {
navController.addOnDestinationChangedListener { _, destination, _ ->
binding.navView.visibility = when (destination.id) {
R.id.twoPaneSettingsFragment, R.id.serverSelectFragment, R.id.addServerFragment, R.id.loginFragment, com.mikepenz.aboutlibraries.R.id.about_libraries_dest, R.id.usersFragment, R.id.serverAddressesFragment -> View.GONE
R.id.twoPaneSettingsFragment, R.id.serverSelectFragment, R.id.addServerFragment, R.id.loginFragment, com.mikepenz.aboutlibraries.R.id.about_libraries_dest, R.id.usersFragment, R.id.serverAddressesFragment, R.id.requestsWebFragment -> View.GONE
else -> View.VISIBLE
}
if (destination.id == com.mikepenz.aboutlibraries.R.id.about_libraries_dest) {

View file

@ -74,6 +74,12 @@ class HomeFragment : Fragment() {
val searchView = search.actionView as SearchView
searchView.queryHint = getString(CoreR.string.search_hint)
val requests = menu.findItem(CoreR.id.action_requests)
requests.setOnMenuItemClickListener{
navigateToRequestsWebViewFragment()
true
}
search.setOnActionExpandListener(
object : MenuItem.OnActionExpandListener {
override fun onMenuItemActionExpand(item: MenuItem): Boolean {
@ -251,4 +257,10 @@ class HomeFragment : Fragment() {
HomeFragmentDirections.actionHomeFragmentToSearchResultFragment(query),
)
}
private fun navigateToRequestsWebViewFragment() {
findNavController().navigate(
HomeFragmentDirections.actionHomeFragmentToRequestsWebFragment()
)
}
}

View file

@ -0,0 +1,71 @@
package com.nomadics9.ananas.fragments
import android.graphics.Bitmap
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.webkit.WebSettings
import android.webkit.WebView
import android.webkit.WebViewClient
import android.widget.ProgressBar
import androidx.activity.OnBackPressedCallback
import androidx.fragment.app.Fragment
import com.nomadics9.ananas.R
import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
class RequestsWebViewFragment : Fragment() {
private lateinit var webView: WebView
private lateinit var progressBar: ProgressBar
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val rootView = inflater.inflate(R.layout.fragment_webview, container, false)
webView = rootView.findViewById(R.id.webview)
progressBar = rootView.findViewById(R.id.progressBar)
val webSettings: WebSettings = webView.settings
webSettings.javaScriptEnabled = true // Enable JavaScript if required
// Set WebViewClient to handle loading URLs within the WebView
webView.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
// Return false to indicate that the WebView should load the URL
return false
}
}
// Set up WebView client to handle page loading events
webView.webViewClient = object : WebViewClient() {
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
super.onPageStarted(view, url, favicon)
progressBar.visibility = View.VISIBLE // Show progress bar when page starts loading
}
override fun onPageFinished(view: WebView?, url: String?) {
super.onPageFinished(view, url)
progressBar.visibility = View.GONE // Hide progress bar when page finishes loading
}
}
// Load your URL here
webView.loadUrl("https://r.askar.tv")
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (webView.canGoBack()) {
webView.goBack()
} else {
isEnabled = false
requireActivity().onBackPressed()
}
}
})
return rootView
}
}

View file

@ -55,5 +55,10 @@ class SettingsFragment : PreferenceFragmentCompat() {
findNavController().navigate(TwoPaneSettingsFragmentDirections.actionSettingsFragmentToAboutLibraries())
true
}
findPreference<Preference>("requests")?.setOnPreferenceClickListener {
findNavController().navigate(TwoPaneSettingsFragmentDirections.actionNavigationSettingsToRequestsWebFragment())
true
}
}
}

View file

@ -0,0 +1,16 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>

View file

@ -49,6 +49,9 @@
<action
android:id="@+id/action_homeFragment_to_searchResultFragment"
app:destination="@id/searchResultFragment" />
<action
android:id="@+id/action_homeFragment_to_requestsWebFragment"
app:destination="@id/requestsWebFragment" />
</fragment>
<fragment
@ -84,10 +87,20 @@
<action
android:id="@+id/action_settingsFragment_to_about_libraries"
app:destination="@id/about_libraries" />
<action
android:id="@+id/action_navigation_settings_to_requestsWebFragment"
app:destination="@id/requestsWebFragment" />
</fragment>
<fragment
android:id="@+id/settingsFragment"
android:name="com.nomadics9.ananas.fragments.SettingsFragment" />
android:name="com.nomadics9.ananas.fragments.SettingsFragment">
</fragment>
<fragment
android:id="@+id/requestsWebFragment"
android:name="com.nomadics9.ananas.fragments.RequestsWebViewFragment"
android:label="Requests"
tools:layout="@layout/fragment_webview">
</fragment>
<fragment
android:id="@+id/libraryFragment"
android:name="com.nomadics9.ananas.fragments.LibraryFragment"

View file

@ -1,7 +1,7 @@
import org.gradle.api.JavaVersion
object Versions {
const val appCode = 1
const val appCode = 3
const val appName = "0.14.2"
const val compileSdk = 34

View file

@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:viewportHeight="16" android:viewportWidth="16" android:width="24dp" android:tint="?attr/colorControlNormal">
<path android:fillColor="@android:color/white" android:pathData="M5,11a2,2 0,0 0,2 -2,2 2,0 0,0 -2,-2 2,2 0,0 0,-2 2A2,2 0,0 0,5 11ZM5,8a1,1 0,0 1,1 1,1 1,0 0,1 -1,1 1,1 0,0 1,-1 -1A1,1 0,0 1,5 8ZM7.5,12h-5A2.5,2.5 0,0 0,0 14.5,1.5 1.5,0 0,0 1.5,16h7A1.5,1.5 0,0 0,10 14.5,2.5 2.5,0 0,0 7.5,12ZM8.5,15h-7a0.5,0.5 0,0 1,-0.5 -0.5A1.5,1.5 0,0 1,2.5 13h5A1.5,1.5 0,0 1,9 14.5,0.5 0.5,0 0,1 8.5,15ZM16,2.5v5A2.5,2.5 0,0 1,13.5 10h-2.793l-1.853,1.854A0.5,0.5 0,0 1,8.5 12a0.489,0.489 0,0 1,-0.191 -0.038A0.5,0.5 0,0 1,8 11.5v-2a0.5,0.5 0,0 1,0.5 -0.5,0.5 0.5,0 0,1 0.5,0.5v0.793l1.146,-1.147A0.5,0.5 0,0 1,10.5 9h3A1.5,1.5 0,0 0,15 7.5v-5A1.5,1.5 0,0 0,13.5 1h-7A1.5,1.5 0,0 0,5 2.5v3a0.5,0.5 0,0 1,-0.5 0.5,0.5 0.5,0 0,1 -0.5,-0.5v-3A2.5,2.5 0,0 1,6.5 0h7A2.5,2.5 0,0 1,16 2.5ZM10.5,2L10.5,4.5L13,4.5a0.5,0.5 0,0 1,0.5 0.5,0.5 0.5,0 0,1 -0.5,0.5h-2.5L10.5,8a0.5,0.5 0,0 1,-0.5 0.5,0.5 0.5,0 0,1 -0.5,-0.5L9.5,5.5L7,5.5a0.5,0.5 0,0 1,-0.5 -0.5,0.5 0.5,0 0,1 0.5,-0.5h2.5L9.5,2a0.5,0.5 0,0 1,0.5 -0.5A0.5,0.5 0,0 1,10.5 2Z"/>
</vector>

View file

@ -3,6 +3,12 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_requests"
android:icon="@drawable/ic_requests"
android:title="@string/alaskarTV_requests"
app:showAsAction="always" />
<item
android:id="@+id/action_search"
android:icon="@drawable/ic_search"

View file

@ -192,4 +192,5 @@
<string name="unmark_as_played">Unmark as played</string>
<string name="add_to_favorites">Add to favorites</string>
<string name="remove_from_favorites">Remove from favorites</string>
<string name="alaskarTV_requests">AlaskarTV Requests</string>
</resources>

View file

@ -12,6 +12,11 @@
app:key="switchServer"
app:title="@string/settings_category_servers" />
<Preference
app:icon="@drawable/ic_requests"
app:key="requests"
app:title="@string/alaskarTV_requests" />
<Preference
app:icon="@drawable/ic_user"
app:key="switchUser"