Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reintroduced the "Hotspot Feature" for custom apps. #4223

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Reintroduced the "Hotspot Feature" for custom apps.
MohitMaliDeveloper committed Feb 12, 2025
commit 0485691ab007346c9a95f6d497c9870c6bc894ed
5 changes: 0 additions & 5 deletions app/detekt_baseline.xml
Original file line number Diff line number Diff line change
@@ -43,11 +43,6 @@
<ID>PackageNaming:SimplePageChangeListener.kt$package org.kiwix.kiwixmobile.zimManager</ID>
<ID>PackageNaming:StartMultiSelection.kt$package
org.kiwix.kiwixmobile.zimManager.fileselectView.effects</ID>
<ID>PackageNaming:HotspotNotificationManager.kt$package org.kiwix.kiwixmobile.webserver.wifi_hotspot</ID>
<ID>PackageNaming:HotspotStateReceiver.kt$package org.kiwix.kiwixmobile.webserver.wifi_hotspot</ID>
<ID>PackageNaming:IpAddressCallbacks.kt$package org.kiwix.kiwixmobile.webserver.wifi_hotspot</ID>
<ID>PackageNaming:HotspotService.kt$package org.kiwix.kiwixmobile.webserver.wifi_hotspot</ID>
<ID>PackageNaming:ServerStatus.kt$package org.kiwix.kiwixmobile.webserver.wifi_hotspot</ID>
<ID>PackageNaming:ZimManageViewModel.kt$package org.kiwix.kiwixmobile.zimManager</ID>
<ID>ReturnCount:Fat32Checker.kt$Fat32Checker$private fun canCreate4GbFile(storage: String): Boolean</ID>
<ID>TooGenericExceptionCaught:FileWritingFileSystemChecker.kt$FileWritingFileSystemChecker$e: Exception</ID>
Original file line number Diff line number Diff line change
@@ -35,7 +35,6 @@ import org.kiwix.kiwixmobile.Findable.StringId.TextId
import org.kiwix.kiwixmobile.Findable.Text
import org.kiwix.kiwixmobile.Findable.ViewId
import org.kiwix.kiwixmobile.core.R
import org.kiwix.kiwixmobile.R.id
import org.kiwix.kiwixmobile.core.utils.files.Log
import org.kiwix.kiwixmobile.testutils.TestUtils
import org.kiwix.kiwixmobile.testutils.TestUtils.testFlakyView
@@ -75,7 +74,7 @@ class ZimHostRobot : BaseRobot() {
fun startServer() {
// stop the server if it is already running.
stopServerIfAlreadyStarted()
clickOn(ViewId(id.startServerButton))
clickOn(ViewId(R.id.startServerButton))
assetWifiDialogDisplayed()
testFlakyView({ onView(withText("PROCEED")).perform(click()) })
}
@@ -116,7 +115,7 @@ class ZimHostRobot : BaseRobot() {
} catch (assertionFailedError: AssertionFailedError) {
try {
val recyclerViewItemsCount =
RecyclerViewItemCount(id.recyclerViewZimHost).checkRecyclerViewCount()
RecyclerViewItemCount(R.id.recyclerViewZimHost).checkRecyclerViewCount()
(0 until recyclerViewItemsCount)
.asSequence()
.filter { it != 0 }
@@ -130,14 +129,14 @@ class ZimHostRobot : BaseRobot() {
private fun selectZimFile(position: Int) {
try {
onView(
RecyclerViewMatcher(id.recyclerViewZimHost).atPositionOnView(
RecyclerViewMatcher(R.id.recyclerViewZimHost).atPositionOnView(
position,
R.id.itemBookCheckbox
)
).check(matches(ViewMatchers.isChecked()))
} catch (assertionError: AssertionFailedError) {
onView(
RecyclerViewMatcher(id.recyclerViewZimHost).atPositionOnView(
RecyclerViewMatcher(R.id.recyclerViewZimHost).atPositionOnView(
position,
R.id.itemBookCheckbox
)
@@ -148,14 +147,14 @@ class ZimHostRobot : BaseRobot() {
fun assertItemHostedOnServer(itemCount: Int) {
val checkedCheckboxCount =
RecyclerViewSelectedCheckBoxCountAssertion(
id.recyclerViewZimHost,
R.id.recyclerViewZimHost,
R.id.itemBookCheckbox
).countCheckedCheckboxes()
assertThat(checkedCheckboxCount, CoreMatchers.`is`(itemCount))
}

fun stopServer() {
testFlakyView({ onView(withId(id.startServerButton)).perform(click()) })
testFlakyView({ onView(withId(R.id.startServerButton)).perform(click()) })
}

fun assertServerStopped() {
@@ -164,11 +163,11 @@ class ZimHostRobot : BaseRobot() {
}

fun assertQrShown() {
isVisible(ViewId(id.serverQrCode))
isVisible(ViewId(R.id.serverQrCode))
}

fun assertQrNotShown() {
isNotVisible(ViewId(id.serverQrCode))
isNotVisible(ViewId(R.id.serverQrCode))
}

private fun pauseForBetterTestPerformance() {
3 changes: 0 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -152,8 +152,5 @@
<action android:name="KiwixSearchWidget.STAR_CLICKED" />
</intent-filter>
</receiver>
<service
android:name=".webserver.wifi_hotspot.HotspotService"
android:foregroundServiceType="dataSync" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -22,8 +22,7 @@ import dagger.BindsInstance
import dagger.Subcomponent
import org.kiwix.kiwixmobile.core.di.ActivityScope
import org.kiwix.kiwixmobile.core.di.components.CoreActivityComponent
import org.kiwix.kiwixmobile.webserver.ZimHostModule
import org.kiwix.kiwixmobile.webserver.ZimHostFragment
import org.kiwix.kiwixmobile.core.webserver.ZimHostModule
import org.kiwix.kiwixmobile.di.modules.KiwixActivityModule
import org.kiwix.kiwixmobile.intro.IntroFragment
import org.kiwix.kiwixmobile.intro.IntroModule
@@ -50,7 +49,6 @@ interface KiwixActivityComponent : CoreActivityComponent {
fun inject(deleteFiles: DeleteFiles)
fun inject(localFileTransferFragment: LocalFileTransferFragment)
fun inject(languageFragment: LanguageFragment)
fun inject(zimHostFragment: ZimHostFragment)
fun inject(kiwixSettingsFragment: KiwixSettingsFragment)
fun inject(introActivity: IntroFragment)
fun inject(kiwixMainActivity: KiwixMainActivity)
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@ package org.kiwix.kiwixmobile.di.components
import dagger.Component
import org.kiwix.kiwixmobile.core.di.components.CoreComponent
import org.kiwix.kiwixmobile.di.KiwixScope
import org.kiwix.kiwixmobile.di.components.ServiceComponent.Builder
import org.kiwix.kiwixmobile.di.modules.KiwixModule
import org.kiwix.kiwixmobile.di.modules.KiwixViewModelModule

@@ -32,5 +31,4 @@ import org.kiwix.kiwixmobile.di.modules.KiwixViewModelModule
)
interface KiwixComponent {
fun activityComponentBuilder(): KiwixActivityComponent.Builder
fun serviceComponent(): Builder
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@

import dagger.Module
import org.kiwix.kiwixmobile.core.di.modules.ActivityModule
import org.kiwix.kiwixmobile.core.webserver.ZimHostModule

@Module(includes = [ActivityModule::class])
@Module(includes = [ActivityModule::class, ZimHostModule::class])

Check warning on line 25 in app/src/main/java/org/kiwix/kiwixmobile/di/modules/KiwixActivityModule.kt

Codecov / codecov/patch

app/src/main/java/org/kiwix/kiwixmobile/di/modules/KiwixActivityModule.kt#L25

Added line #L25 was not covered by tests
class KiwixActivityModule
Original file line number Diff line number Diff line change
@@ -20,7 +20,6 @@ package org.kiwix.kiwixmobile.di.modules

import android.content.Context
import android.location.LocationManager
import android.net.wifi.WifiManager
import android.net.wifi.p2p.WifiP2pManager
import dagger.Module
import dagger.Provides
@@ -56,9 +55,4 @@ object KiwixModule {
// See: https://github.com/kiwix/kiwix-android/issues/2488
fun providesWiFiP2pManager(context: Context): WifiP2pManager? =
context.getSystemService(Context.WIFI_P2P_SERVICE) as WifiP2pManager?

@Provides
@KiwixScope
fun provideWifiManager(context: Context): WifiManager =
context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
}

This file was deleted.

17 changes: 2 additions & 15 deletions app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@ import android.content.res.Configuration
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.ActionMode
import androidx.core.content.pm.ShortcutInfoCompat
@@ -46,7 +45,6 @@ import kotlinx.coroutines.launch
import org.kiwix.kiwixmobile.BuildConfig
import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.core.R.drawable
import org.kiwix.kiwixmobile.core.R.id
import org.kiwix.kiwixmobile.core.R.mipmap
import org.kiwix.kiwixmobile.core.R.string
import org.kiwix.kiwixmobile.core.base.FragmentActivityExtensions
@@ -107,6 +105,8 @@ class KiwixMainActivity : CoreMainActivity() {
override val notesFragmentResId: Int = R.id.notesFragment
override val readerFragmentResId: Int = R.id.readerFragment
override val helpFragmentResId: Int = R.id.helpFragment
override val zimHostFragmentResId: Int = R.id.zimHostFragment
override val navGraphId: Int = R.navigation.kiwix_nav_graph
override val topLevelDestinations =
setOf(R.id.downloadsFragment, R.id.libraryFragment, R.id.readerFragment)

@@ -310,19 +310,6 @@ class KiwixMainActivity : CoreMainActivity() {
}
}

override fun onNavigationItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
id.menu_host_books -> openZimHostFragment()
else -> return super.onNavigationItemSelected(item)
}
return true
}

private fun openZimHostFragment() {
disableDrawer()
navigate(R.id.zimHostFragment)
}

override fun getIconResId() = mipmap.ic_launcher

override fun createApplicationShortcuts() {
2 changes: 1 addition & 1 deletion app/src/main/res/navigation/kiwix_nav_graph.xml
Original file line number Diff line number Diff line change
@@ -125,7 +125,7 @@
tools:layout="@layout/activity_language" />
<fragment
android:id="@+id/zimHostFragment"
android:name="org.kiwix.kiwixmobile.webserver.ZimHostFragment"
android:name="org.kiwix.kiwixmobile.core.webserver.ZimHostFragment"
android:label="ZimHostFragment"
tools:layout="@layout/activity_zim_host" />
<fragment
5 changes: 5 additions & 0 deletions core/detekt_baseline.xml
Original file line number Diff line number Diff line change
@@ -51,6 +51,11 @@
<ID>PackageNaming:MountPointProducer.kt$package org.kiwix.kiwixmobile.core.zim_manager</ID>
<ID>PackageNaming:SelectionMode.kt$package org.kiwix.kiwixmobile.core.zim_manager.fileselect_view</ID>
<ID>PackageNaming:TagsView.kt$package org.kiwix.kiwixmobile.core.zim_manager</ID>
<ID>PackageNaming:HotspotNotificationManager.kt$package org.kiwix.kiwixmobile.core.webserver.wifi_hotspot</ID>
<ID>PackageNaming:HotspotStateReceiver.kt$package org.kiwix.kiwixmobile.core.webserver.wifi_hotspot</ID>
<ID>PackageNaming:IpAddressCallbacks.kt$package org.kiwix.kiwixmobile.core.webserver.wifi_hotspot</ID>
<ID>PackageNaming:HotspotService.kt$package org.kiwix.kiwixmobile.core.webserver.wifi_hotspot</ID>
<ID>PackageNaming:ServerStatus.kt$package org.kiwix.kiwixmobile.core.webserver.wifi_hotspot</ID>
<ID>PackageNaming:ConnectivityBroadcastReceiver.kt$package org.kiwix.kiwixmobile.core.zim_manager</ID>
<ID>PackageNaming:NetworkState.kt$package org.kiwix.kiwixmobile.core.zim_manager</ID>
<ID>ReturnCount:FileUtils.kt$FileUtils$@JvmStatic fun getAllZimParts(book: Book): List&lt;File></ID>
3 changes: 3 additions & 0 deletions core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -95,5 +95,8 @@
<service
android:name=".downloader.downloadManager.DownloadMonitorService"
android:foregroundServiceType="dataSync" />
<service
android:name=".webserver.wifi_hotspot.HotspotService"
android:foregroundServiceType="dataSync" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -36,10 +36,12 @@ import org.kiwix.kiwixmobile.core.page.notes.viewmodel.effects.ShowOpenNoteDialo
import org.kiwix.kiwixmobile.core.search.SearchFragment
import org.kiwix.kiwixmobile.core.search.viewmodel.effects.ShowDeleteSearchDialog
import org.kiwix.kiwixmobile.core.settings.CorePrefsFragment
import org.kiwix.kiwixmobile.core.webserver.ZimHostFragment
import org.kiwix.kiwixmobile.core.webserver.ZimHostModule

@ActivityScope
@Subcomponent(
modules = [ActivityModule::class]
modules = [ActivityModule::class, ZimHostModule::class],
)
interface CoreActivityComponent {
fun inject(searchFragment: SearchFragment)
@@ -55,6 +57,7 @@ interface CoreActivityComponent {
fun inject(helpFragment: HelpFragment)
fun inject(notesFragment: NotesFragment)
fun inject(navigationHistoryDialog: NavigationHistoryDialog)
fun inject(zimHostFragment: ZimHostFragment)

@Subcomponent.Builder
interface Builder {
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ import android.app.Application
import android.app.NotificationManager
import android.content.Context
import android.net.ConnectivityManager
import android.net.wifi.WifiManager
import dagger.BindsInstance
import dagger.Component
import eu.mhutti1.utils.storage.StorageSelectDialog
@@ -102,6 +103,7 @@ interface CoreComponent {
fun downloadRoomDao(): DownloadRoomDao
fun newBookmarksDao(): NewBookmarksDao
fun connectivityManager(): ConnectivityManager
fun wifiManager(): WifiManager
fun objectBoxToLibkiwixMigrator(): ObjectBoxToLibkiwixMigrator
fun libkiwixBookmarks(): LibkiwixBookmarks
fun recentSearchRoomDao(): RecentSearchRoomDao
Original file line number Diff line number Diff line change
@@ -25,12 +25,14 @@ import org.kiwix.kiwixmobile.core.di.CoreServiceScope
import org.kiwix.kiwixmobile.core.di.modules.CoreServiceModule
import org.kiwix.kiwixmobile.core.downloader.downloadManager.DownloadMonitorService
import org.kiwix.kiwixmobile.core.read_aloud.ReadAloudService
import org.kiwix.kiwixmobile.core.webserver.wifi_hotspot.HotspotService

@Subcomponent(modules = [CoreServiceModule::class])
@CoreServiceScope
interface CoreServiceComponent {
fun inject(readAloudService: ReadAloudService)
fun inject(downloadMonitorService: DownloadMonitorService)
fun inject(hotspotService: HotspotService)

@Subcomponent.Builder
interface Builder {
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ import android.app.Application
import android.app.NotificationManager
import android.content.Context
import android.net.ConnectivityManager
import android.net.wifi.WifiManager
import android.os.storage.StorageManager
import dagger.Module
import dagger.Provides
@@ -101,4 +102,9 @@ class ApplicationModule {
@Singleton
fun provideConnectivityManager(context: Context): ConnectivityManager =
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager

@Provides
@Singleton
fun provideWifiManager(context: Context): WifiManager =
context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
}
Original file line number Diff line number Diff line change
@@ -19,11 +19,18 @@
package org.kiwix.kiwixmobile.core.di.modules

import android.app.NotificationManager
import android.app.Service
import android.content.Context
import dagger.Module
import dagger.Provides
import org.kiwix.kiwixmobile.core.di.CoreServiceScope
import org.kiwix.kiwixmobile.core.qr.GenerateQR
import org.kiwix.kiwixmobile.core.read_aloud.ReadAloudNotificationManger
import org.kiwix.kiwixmobile.core.webserver.KiwixServer
import org.kiwix.kiwixmobile.core.webserver.WebServerHelper
import org.kiwix.kiwixmobile.core.webserver.wifi_hotspot.HotspotNotificationManager
import org.kiwix.kiwixmobile.core.webserver.wifi_hotspot.HotspotStateReceiver
import org.kiwix.kiwixmobile.core.webserver.wifi_hotspot.IpAddressCallbacks

@Module
class CoreServiceModule {
@@ -33,4 +40,39 @@ class CoreServiceModule {
notificationManager: NotificationManager,
context: Context
): ReadAloudNotificationManger = ReadAloudNotificationManger(notificationManager, context)

@Provides
@CoreServiceScope
fun providesWebServerHelper(
kiwixServerFactory: KiwixServer.Factory,
ipAddressCallbacks: IpAddressCallbacks
): WebServerHelper = WebServerHelper(kiwixServerFactory, ipAddressCallbacks)

@Provides
@CoreServiceScope
fun providesIpAddressCallbacks(service: Service): IpAddressCallbacks =
service as IpAddressCallbacks

@Provides
@CoreServiceScope
fun providesHotspotNotificationManager(
notificationManager: NotificationManager,
context: Context,
generateQR: GenerateQR,
): HotspotNotificationManager =
HotspotNotificationManager(notificationManager, context, generateQR)

@Provides
@CoreServiceScope
fun providesHotspotStateReceiver(callback: HotspotStateReceiver.Callback): HotspotStateReceiver =
HotspotStateReceiver(callback)

@Provides
@CoreServiceScope
fun providesHotspotStateReceiverCallback(service: Service): HotspotStateReceiver.Callback =
service as HotspotStateReceiver.Callback

@Provides
@CoreServiceScope
fun providesGenerateQr(): GenerateQR = GenerateQR()
}
Original file line number Diff line number Diff line change
@@ -97,6 +97,8 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
abstract val historyFragmentResId: Int
abstract val notesFragmentResId: Int
abstract val helpFragmentResId: Int
abstract val zimHostFragmentResId: Int
abstract val navGraphId: Int
abstract val cachedComponent: CoreActivityComponent
abstract val topLevelDestinations: Set<Int>
abstract val navHostContainer: FragmentContainerView
@@ -307,11 +309,17 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider {
R.id.menu_notes -> openNotes()
R.id.menu_history -> openHistory()
R.id.menu_bookmarks_list -> openBookmarks()
R.id.menu_host_books -> openZimHostFragment()
else -> return false
}
return true
}

private fun openZimHostFragment() {
navigate(zimHostFragmentResId)
handleDrawerOnNavigation()
}

private fun openHelpFragment() {
navigate(helpFragmentResId)
handleDrawerOnNavigation()
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
*
*/

package org.kiwix.kiwixmobile.webserver
package org.kiwix.kiwixmobile.core.webserver

import android.content.Context
import kotlinx.coroutines.Dispatchers
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.kiwix.kiwixmobile.webserver
package org.kiwix.kiwixmobile.core.webserver

import io.reactivex.Flowable
import io.reactivex.android.schedulers.AndroidSchedulers
@@ -27,8 +27,8 @@ import org.kiwix.kiwixmobile.core.utils.ServerUtils.INVALID_IP
import org.kiwix.kiwixmobile.core.utils.ServerUtils.getIp
import org.kiwix.kiwixmobile.core.utils.ServerUtils.getIpAddress
import org.kiwix.kiwixmobile.core.utils.files.Log
import org.kiwix.kiwixmobile.webserver.wifi_hotspot.IpAddressCallbacks
import org.kiwix.kiwixmobile.webserver.wifi_hotspot.ServerStatus
import org.kiwix.kiwixmobile.core.webserver.wifi_hotspot.IpAddressCallbacks
import org.kiwix.kiwixmobile.core.webserver.wifi_hotspot.ServerStatus
import java.util.concurrent.TimeUnit
import javax.inject.Inject

Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.kiwix.kiwixmobile.webserver
package org.kiwix.kiwixmobile.core.webserver

interface ZimHostCallbacks {
fun onServerStarted(ip: String)
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.kiwix.kiwixmobile.webserver
package org.kiwix.kiwixmobile.core.webserver

import org.kiwix.kiwixmobile.core.base.BaseContract
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
*
*/

package org.kiwix.kiwixmobile.webserver
package org.kiwix.kiwixmobile.core.webserver

import android.Manifest
import android.Manifest.permission.POST_NOTIFICATIONS
@@ -42,7 +42,7 @@ import androidx.appcompat.widget.Toolbar
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.fragment.app.FragmentActivity
import org.kiwix.kiwixmobile.R.layout
import org.kiwix.kiwixmobile.core.CoreApp.Companion.coreComponent
import org.kiwix.kiwixmobile.core.R
import org.kiwix.kiwixmobile.core.base.BaseActivity
import org.kiwix.kiwixmobile.core.base.BaseFragment
@@ -67,12 +67,12 @@ import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BookOnDisk
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskAdapter
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem.BookOnDisk
import org.kiwix.kiwixmobile.databinding.ActivityZimHostBinding
import org.kiwix.kiwixmobile.main.KiwixMainActivity
import org.kiwix.kiwixmobile.webserver.wifi_hotspot.HotspotService
import org.kiwix.kiwixmobile.webserver.wifi_hotspot.HotspotService.Companion.ACTION_CHECK_IP_ADDRESS
import org.kiwix.kiwixmobile.webserver.wifi_hotspot.HotspotService.Companion.ACTION_START_SERVER
import org.kiwix.kiwixmobile.webserver.wifi_hotspot.HotspotService.Companion.ACTION_STOP_SERVER
import org.kiwix.kiwixmobile.core.databinding.ActivityZimHostBinding
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.cachedComponent
import org.kiwix.kiwixmobile.core.webserver.wifi_hotspot.HotspotService
import org.kiwix.kiwixmobile.core.webserver.wifi_hotspot.HotspotService.Companion.ACTION_CHECK_IP_ADDRESS
import org.kiwix.kiwixmobile.core.webserver.wifi_hotspot.HotspotService.Companion.ACTION_START_SERVER
import org.kiwix.kiwixmobile.core.webserver.wifi_hotspot.HotspotService.Companion.ACTION_STOP_SERVER
import javax.inject.Inject

class ZimHostFragment : BaseFragment(), ZimHostCallbacks, ZimHostContract.View {
@@ -178,7 +178,16 @@ class ZimHostFragment : BaseFragment(), ZimHostCallbacks, ZimHostContract.View {
}

override fun inject(baseActivity: BaseActivity) {
(baseActivity as KiwixMainActivity).cachedComponent.inject(this)
baseActivity.cachedComponent.inject(this)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
coreComponent
.activityComponentBuilder()
.activity(requireActivity())
.build()
.inject(this)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.kiwix.kiwixmobile.webserver
package org.kiwix.kiwixmobile.core.webserver

import dagger.Binds
import dagger.Module
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.kiwix.kiwixmobile.webserver
package org.kiwix.kiwixmobile.core.webserver

import org.kiwix.kiwixmobile.core.utils.files.Log
import io.reactivex.SingleObserver
@@ -24,8 +24,8 @@ import org.kiwix.kiwixmobile.core.base.BasePresenter
import org.kiwix.kiwixmobile.core.data.DataSource
import org.kiwix.kiwixmobile.core.di.ActivityScope
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem
import org.kiwix.kiwixmobile.webserver.ZimHostContract.Presenter
import org.kiwix.kiwixmobile.webserver.ZimHostContract.View
import org.kiwix.kiwixmobile.core.webserver.ZimHostContract.Presenter
import org.kiwix.kiwixmobile.core.webserver.ZimHostContract.View
import javax.inject.Inject

@ActivityScope
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.kiwix.kiwixmobile.webserver.wifi_hotspot
package org.kiwix.kiwixmobile.core.webserver.wifi_hotspot

import android.annotation.SuppressLint
import android.app.Notification
@@ -29,8 +29,6 @@ import androidx.core.app.NotificationCompat
import androidx.navigation.NavDeepLinkBuilder
import org.kiwix.kiwixmobile.core.CoreApp
import org.kiwix.kiwixmobile.core.R
import org.kiwix.kiwixmobile.R.id
import org.kiwix.kiwixmobile.R.navigation
import org.kiwix.kiwixmobile.core.qr.GenerateQR
import org.kiwix.kiwixmobile.core.utils.HOTSPOT_SERVICE_CHANNEL_ID
import javax.inject.Inject
@@ -62,8 +60,8 @@ class HotspotNotificationManager @Inject constructor(
val contentIntent = NavDeepLinkBuilder(context).setComponentName(
coreMainActivity.mainActivity::class.java
)
.setGraph(navigation.kiwix_nav_graph)
.setDestination(id.zimHostFragment)
.setGraph(coreMainActivity.navGraphId)
.setDestination(coreMainActivity.zimHostFragmentResId)
.createPendingIntent()
hotspotNotificationChannel()
val stopIntent = Intent(context, HotspotService::class.java).setAction(
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.kiwix.kiwixmobile.webserver.wifi_hotspot
package org.kiwix.kiwixmobile.core.webserver.wifi_hotspot

import android.app.Service
import android.content.Intent
@@ -26,14 +26,14 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.kiwix.kiwixmobile.KiwixApp
import org.kiwix.kiwixmobile.core.CoreApp.Companion.coreComponent
import org.kiwix.kiwixmobile.core.R
import org.kiwix.kiwixmobile.core.extensions.registerReceiver
import org.kiwix.kiwixmobile.core.utils.ServerUtils.getSocketAddress
import org.kiwix.kiwixmobile.webserver.WebServerHelper
import org.kiwix.kiwixmobile.webserver.ZimHostCallbacks
import org.kiwix.kiwixmobile.webserver.ZimHostFragment
import org.kiwix.kiwixmobile.webserver.ZimHostFragment.Companion.RESTART_SERVER
import org.kiwix.kiwixmobile.core.webserver.WebServerHelper
import org.kiwix.kiwixmobile.core.webserver.ZimHostCallbacks
import org.kiwix.kiwixmobile.core.webserver.ZimHostFragment
import org.kiwix.kiwixmobile.core.webserver.ZimHostFragment.Companion.RESTART_SERVER
import java.lang.ref.WeakReference
import javax.inject.Inject

@@ -58,18 +58,18 @@ class HotspotService :
private val serviceBinder: IBinder = HotspotBinder(this)

override fun onCreate() {
(this.application as KiwixApp).kiwixComponent
.serviceComponent()
coreComponent
.coreServiceComponent()
.service(this)
.build()
.inject(this)
super.onCreate()
hotspotStateReceiver?.let(this::registerReceiver)
hotspotStateReceiver?.let(::registerReceiver)
}

override fun onDestroy() {
webServerHelper?.dispose()
hotspotStateReceiver?.let(this@HotspotService::unregisterReceiver)
hotspotStateReceiver?.let(::unregisterReceiver)
super.onDestroy()
}

Original file line number Diff line number Diff line change
@@ -15,12 +15,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.kiwix.kiwixmobile.webserver.wifi_hotspot
package org.kiwix.kiwixmobile.core.webserver.wifi_hotspot

import android.content.Context
import android.content.Intent
import org.kiwix.kiwixmobile.core.base.BaseBroadcastReceiver
import org.kiwix.kiwixmobile.webserver.wifi_hotspot.HotspotStateReceiver.HotspotState.DISABLED
import org.kiwix.kiwixmobile.core.webserver.wifi_hotspot.HotspotStateReceiver.HotspotState.DISABLED
import javax.inject.Inject

const val EXTRA_WIFI_AP_STATE = "wifi_state"
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.kiwix.kiwixmobile.webserver.wifi_hotspot
package org.kiwix.kiwixmobile.core.webserver.wifi_hotspot

interface IpAddressCallbacks {
fun onIpAddressValid()
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
*
*/

package org.kiwix.kiwixmobile.webserver.wifi_hotspot
package org.kiwix.kiwixmobile.core.webserver.wifi_hotspot

data class ServerStatus(
val isServerStarted: Boolean,
Original file line number Diff line number Diff line change
@@ -22,14 +22,15 @@ import android.app.Activity
import dagger.BindsInstance
import dagger.Subcomponent
import org.kiwix.kiwixmobile.core.di.ActivityScope
import org.kiwix.kiwixmobile.core.webserver.ZimHostModule
import org.kiwix.kiwixmobile.core.di.components.CoreActivityComponent
import org.kiwix.kiwixmobile.custom.download.CustomDownloadFragment
import org.kiwix.kiwixmobile.custom.main.CustomMainActivity
import org.kiwix.kiwixmobile.custom.main.CustomReaderFragment
import org.kiwix.kiwixmobile.custom.settings.CustomSettingsFragment

@ActivityScope
@Subcomponent(modules = [CustomActivityModule::class])
@Subcomponent(modules = [CustomActivityModule::class, ZimHostModule::class])
interface CustomActivityComponent : CoreActivityComponent {
fun inject(customMainActivity: CustomMainActivity)
fun inject(customSettingsFragment: CustomSettingsFragment)
Original file line number Diff line number Diff line change
@@ -75,6 +75,8 @@ class CustomMainActivity : CoreMainActivity() {
override val historyFragmentResId: Int = R.id.historyFragment
override val notesFragmentResId: Int = R.id.notesFragment
override val helpFragmentResId: Int = R.id.helpFragment
override val zimHostFragmentResId: Int = R.id.zimHostFragment
override val navGraphId: Int = R.navigation.custom_nav_graph
override val cachedComponent by lazy { customActivityComponent }
override val topLevelDestinations =
setOf(R.id.customReaderFragment)
@@ -114,7 +116,7 @@ class CustomMainActivity : CoreMainActivity() {
* For more info see https://github.com/kiwix/kiwix-android/pull/3516,
* https://github.com/kiwix/kiwix-android/issues/4026
*/
menu.findItem(org.kiwix.kiwixmobile.core.R.id.menu_host_books)?.isVisible = false
menu.findItem(org.kiwix.kiwixmobile.core.R.id.menu_host_books)?.isVisible = true
/**
* Hide the `HelpFragment` from custom apps.
* We have not removed the relevant code for `HelpFragment` from custom apps.
4 changes: 4 additions & 0 deletions custom/src/main/res/navigation/custom_nav_graph.xml
Original file line number Diff line number Diff line change
@@ -55,6 +55,10 @@
android:id="@+id/bookmarksFragment"
android:name="org.kiwix.kiwixmobile.core.page.bookmark.BookmarksFragment"
android:label="BookmarksFragment" />
<fragment
android:id="@+id/zimHostFragment"
android:name="org.kiwix.kiwixmobile.core.webserver.ZimHostFragment"
android:label="ZimHostFragment" />
<fragment
android:id="@+id/helpFragment"
android:name="org.kiwix.kiwixmobile.custom.help.CustomHelpFragment"