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
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 0 additions & 5 deletions app/detekt_baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()) })
}
Expand Down Expand Up @@ -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 }
Expand All @@ -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
)
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Up @@ -20,6 +20,7 @@ package org.kiwix.kiwixmobile.di.modules

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])
class KiwixActivityModule
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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() {
Expand Down
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
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions core/detekt_baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -26,9 +26,11 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.rx3.rxSingle
import org.kiwix.kiwixmobile.core.CoreApp.Companion.instance
import org.kiwix.kiwixmobile.core.dao.entities.BookOnDiskEntity
import org.kiwix.kiwixmobile.core.dao.entities.BookOnDiskEntity_
import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity.Book
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.isCustomApp
import org.kiwix.kiwixmobile.core.reader.ZimReaderSource
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem.BookOnDisk
import javax.inject.Inject
Expand All @@ -42,7 +44,6 @@ class NewBookDao @Inject constructor(private val box: Box<BookOnDiskEntity>) {
.flatMapSingle { bookOnDiskEntity ->
val file = bookOnDiskEntity.file
val zimReaderSource = ZimReaderSource(file)

rxSingle { zimReaderSource.canOpenInLibkiwix() }
.map { canOpen ->
if (canOpen) {
Expand Down Expand Up @@ -72,7 +73,8 @@ class NewBookDao @Inject constructor(private val box: Box<BookOnDiskEntity>) {
}
}
.filter { (bookOnDiskEntity, exists) ->
exists && !isInTrashFolder(bookOnDiskEntity.zimReaderSource.toDatabase())
(instance.getMainActivity().isCustomApp() || exists) &&
!isInTrashFolder(bookOnDiskEntity.zimReaderSource.toDatabase())
}
.map(Pair<BookOnDiskEntity, Boolean>::first)
.toList()
Expand Down Expand Up @@ -152,6 +154,7 @@ class NewBookDao @Inject constructor(private val box: Box<BookOnDiskEntity>) {
}

private suspend fun removeBooksThatDoNotExist(books: MutableList<BookOnDiskEntity>) {
if (instance.getMainActivity().isCustomApp()) return
delete(books.filterNot { it.zimReaderSource.exists() })
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
Loading
Loading