Skip to content

Commit

Permalink
Refactored the unnecessary code.
Browse files Browse the repository at this point in the history
  • Loading branch information
MohitMaliDeveloper committed Feb 24, 2025
1 parent 8527e20 commit 422e93c
Show file tree
Hide file tree
Showing 28 changed files with 590 additions and 631 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ import uk.co.deanwild.materialshowcaseview.R.id
*/

fun localFileTransfer(func: LocalFileTransferRobot.() -> Unit) =
LocalFileTransferRobot()
.applyWithViewHierarchyPrinting(func)
LocalFileTransferRobot().applyWithViewHierarchyPrinting(func)

class LocalFileTransferRobot : BaseRobot() {
fun assertReceiveFileTitleVisible() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ import org.kiwix.kiwixmobile.testutils.TestUtils.TEST_PAUSE_MS_FOR_DOWNLOAD_TEST
import org.kiwix.kiwixmobile.testutils.TestUtils.testFlakyView

fun searchWidget(func: SearchWidgetRobot.() -> Unit) =
SearchWidgetRobot()
.applyWithViewHierarchyPrinting(func)
SearchWidgetRobot().applyWithViewHierarchyPrinting(func)

class SearchWidgetRobot : BaseRobot() {
fun removeWidgetIfAlreadyAdded(uiDevice: UiDevice) {
Expand Down
11 changes: 6 additions & 5 deletions app/src/main/java/org/kiwix/kiwixmobile/intro/IntroPresenter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ import org.kiwix.kiwixmobile.intro.IntroContract.Presenter
import org.kiwix.kiwixmobile.intro.IntroContract.View
import javax.inject.Inject

class IntroPresenter @Inject internal constructor(private val preferences: SharedPreferenceUtil) :
BasePresenter<View?>(), Presenter {
override fun setIntroShown() {
preferences.setIntroShown()
}
class IntroPresenter @Inject internal constructor(
private val preferences: SharedPreferenceUtil
) : BasePresenter<View?>(), Presenter {
override fun setIntroShown() {
preferences.setIntroShown()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,38 @@ import org.kiwix.kiwixmobile.webserver.ZimHostContract.View
import javax.inject.Inject

@ActivityScope
class ZimHostPresenter @Inject internal constructor(private val dataSource: DataSource) :
BasePresenter<View>(),
class ZimHostPresenter @Inject internal constructor(
private val dataSource: DataSource
) : BasePresenter<View>(),
Presenter {
override fun loadBooks(previouslyHostedBooks: Set<String>) {
dataSource.getLanguageCategorizedBooks()
.map { books ->
books
.filterIsInstance<BooksOnDiskListItem.BookOnDisk>()
.forEach {
it.isSelected =
previouslyHostedBooks.contains(it.book.title) || previouslyHostedBooks.isEmpty()
}
books
}.subscribe(
object : SingleObserver<List<BooksOnDiskListItem>> {
override fun onSubscribe(d: Disposable) {
compositeDisposable.add(d)
}
override fun loadBooks(previouslyHostedBooks: Set<String>) {
dataSource.getLanguageCategorizedBooks()
.map { books ->
books
.filterIsInstance<BooksOnDiskListItem.BookOnDisk>()
.forEach {
it.isSelected =
previouslyHostedBooks.contains(it.book.title) || previouslyHostedBooks.isEmpty()
}
books
}.subscribe(
object : SingleObserver<List<BooksOnDiskListItem>> {
override fun onSubscribe(d: Disposable) {
compositeDisposable.add(d)
}

override fun onSuccess(books: List<BooksOnDiskListItem>) {
view?.addBooks(books)
}
override fun onSuccess(books: List<BooksOnDiskListItem>) {
view?.addBooks(books)
}

override fun onError(e: Throwable) {
Log.e(TAG, "Unable to load books", e)
}
override fun onError(e: Throwable) {
Log.e(TAG, "Unable to load books", e)
}

Check warning on line 58 in app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostPresenter.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/org/kiwix/kiwixmobile/webserver/ZimHostPresenter.kt#L57-L58

Added lines #L57 - L58 were not covered by tests
)
}
}
)
}

companion object {
private const val TAG = "ZimHostPresenter"
}
companion object {
private const val TAG = "ZimHostPresenter"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,38 @@ const val WIFI_AP_STATE_ENABLING = 12
const val WIFI_AP_STATE_ENABLED = 13
const val WIFI_AP_STATE_FAILED = 14

class HotspotStateReceiver @Inject constructor(private val callback: Callback) :
BaseBroadcastReceiver() {
override val action: String = ACTION_WIFI_AP_STATE
class HotspotStateReceiver @Inject constructor(
private val callback: Callback
) : BaseBroadcastReceiver() {
override val action: String = ACTION_WIFI_AP_STATE

override fun onIntentWithActionReceived(context: Context, intent: Intent) {
if (DISABLED == hotspotState(intent)) {
callback.onHotspotDisabled()
}
override fun onIntentWithActionReceived(context: Context, intent: Intent) {
if (DISABLED == hotspotState(intent)) {
callback.onHotspotDisabled()
}
}

private fun hotspotState(intent: Intent) =
HotspotState.from(
intent.getIntExtra(
EXTRA_WIFI_AP_STATE,
-1
)
private fun hotspotState(intent: Intent) =
HotspotState.from(
intent.getIntExtra(
EXTRA_WIFI_AP_STATE,
-1
)
)

interface Callback {
fun onHotspotDisabled()
}
interface Callback {
fun onHotspotDisabled()
}

private enum class HotspotState(val state: Int) {
DISABLING(WIFI_AP_STATE_DISABLING),
DISABLED(WIFI_AP_STATE_DISABLED),
ENABLING(WIFI_AP_STATE_ENABLING),
ENABLED(WIFI_AP_STATE_ENABLED),
FAILED(WIFI_AP_STATE_FAILED);
private enum class HotspotState(val state: Int) {
DISABLING(WIFI_AP_STATE_DISABLING),
DISABLED(WIFI_AP_STATE_DISABLED),
ENABLING(WIFI_AP_STATE_ENABLING),
ENABLED(WIFI_AP_STATE_ENABLED),
FAILED(WIFI_AP_STATE_FAILED);

companion object {
fun from(state: Int) = HotspotState.values().firstOrNull { state == it.state }
}
companion object {
fun from(state: Int) = HotspotState.values().firstOrNull { state == it.state }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ class MountFileSystemChecker @Inject constructor(
override fun checkFilesystemSupports4GbFiles(path: String) =
recursivelyDetermineFilesystem(mountPointProducer.produce(), path)

private fun recursivelyDetermineFilesystem(mountPoints: List<MountInfo>, path: String): FileSystemCapability =
private fun recursivelyDetermineFilesystem(
mountPoints: List<MountInfo>,
path: String
): FileSystemCapability =
mountPoints.maxBy { it.matchCount(path) }
?.takeIf { it.matchCount(path) > 0 }
?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import org.kiwix.kiwixmobile.core.base.adapter.BaseDelegateAdapter

class LibraryAdapter(
vararg delegates: AdapterDelegate<LibraryListItem>
) : BaseDelegateAdapter<LibraryListItem>(
*delegates
) {
) : BaseDelegateAdapter<LibraryListItem>(*delegates) {
override fun getIdFor(item: LibraryListItem) = item.id
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ interface AbsDelegateAdapter<
INSTANCE : SUPERTYPE,
SUPERTYPE : Any,
out VIEWHOLDER : BaseViewHolder<INSTANCE>
> :
AdapterDelegate<SUPERTYPE> {
> : AdapterDelegate<SUPERTYPE> {
val itemClass: Class<INSTANCE>

@Suppress("UNCHECKED_CAST")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,18 @@ import android.os.UserManager

class ResolveInfoFlagsCompat private constructor(

Check warning on line 27 in core/src/main/java/org/kiwix/kiwixmobile/core/compat/ResolveInfoFlagsCompat.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/compat/ResolveInfoFlagsCompat.kt#L27

Added line #L27 was not covered by tests
@ResolveInfoFlagsBitsCompat value: Long
) :
Flags(value) {
companion object {
fun of(
@ResolveInfoFlagsBitsCompat value: Long
): ResolveInfoFlagsCompat =
ResolveInfoFlagsCompat(value)
) : Flags(value) {

Check warning on line 29 in core/src/main/java/org/kiwix/kiwixmobile/core/compat/ResolveInfoFlagsCompat.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/compat/ResolveInfoFlagsCompat.kt#L29

Added line #L29 was not covered by tests
companion object {
fun of(
@ResolveInfoFlagsBitsCompat value: Long
): ResolveInfoFlagsCompat =
ResolveInfoFlagsCompat(value)

/** Helper property. Does not exist on Platform API */
val EMPTY
get() = ResolveInfoFlagsCompat(0)
}
/** Helper property. Does not exist on Platform API */
val EMPTY
get() = ResolveInfoFlagsCompat(0)
}
}

/**
* [ComponentInfo] flag: return the [ComponentInfo.metaData]
Expand Down
18 changes: 0 additions & 18 deletions core/src/main/java/org/kiwix/kiwixmobile/core/data/DataSource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,40 +34,22 @@ import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDis
*/
interface DataSource {
fun getLanguageCategorizedBooks(): Single<List<BooksOnDiskListItem>>

fun saveBook(book: BookOnDisk): Completable

fun saveBooks(book: List<BookOnDisk>): Completable

fun saveLanguages(languages: List<Language>): Completable

fun saveHistory(history: HistoryItem): Completable

fun deleteHistory(historyList: List<HistoryListItem>): Completable

fun clearHistory(): Completable

fun getBookmarks(): Flowable<List<LibkiwixBookmarkItem>>

fun getCurrentZimBookmarksUrl(): io.reactivex.rxjava3.core.Single<List<String>>

fun saveBookmark(libkiwixBookmarkItem: LibkiwixBookmarkItem): io.reactivex.rxjava3.core.Completable

fun deleteBookmarks(bookmarks: List<LibkiwixBookmarkItem>): Completable

fun deleteBookmark(bookId: String, bookmarkUrl: String): Completable?

fun booksOnDiskAsListItems(): Flowable<List<BooksOnDiskListItem>>

fun saveNote(noteListItem: NoteListItem): Completable

fun deleteNote(noteTitle: String): Completable

fun deleteNotes(noteList: List<NoteListItem>): Completable

suspend fun insertWebViewPageHistoryItems(webViewHistoryEntityList: List<WebViewHistoryEntity>)

fun getAllWebViewPagesHistory(): Single<List<WebViewHistoryEntity>>

suspend fun clearWebViewPagesHistory()
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ import retrofit2.http.Url
interface KiwixService {
@get:GET(LIBRARY_NETWORK_PATH) val library: Single<LibraryNetworkEntity?>

@GET fun getMetaLinks(
@GET
fun getMetaLinks(
@Url url: String
): Observable<MetaLinkNetworkEntity?>

/******** Helper class that sets up new services */
object ServiceCreator {
@Suppress("DEPRECATION")
fun newHackListService(okHttpClient: OkHttpClient, baseUrl: String): KiwixService {
val retrofit =
Retrofit.Builder()
.baseUrl(baseUrl)
.client(okHttpClient)
.addConverterFactory(SimpleXmlConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io()))
.build()
val retrofit = Retrofit.Builder()
.baseUrl(baseUrl)
.client(okHttpClient)
.addConverterFactory(SimpleXmlConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io()))
.build()
return retrofit.create(KiwixService::class.java)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,27 @@ abstract class ActivityModule {
fun providesMainMenuFactory(
activity: Activity,
zimReaderContainer: ZimReaderContainer
): MainMenu.Factory =
object : Factory {
override fun create(
menu: Menu,
webViews: MutableList<KiwixWebView>,
urlIsValid: Boolean,
menuClickListener: MenuClickListener,
disableReadAloud: Boolean,
disableTabs: Boolean,
disableSearch: Boolean
): MainMenu =
MainMenu(
activity,
zimReaderContainer.zimFileReader,
menu,
webViews,
urlIsValid,
disableReadAloud,
disableTabs,
disableSearch,
menuClickListener
)
}
): MainMenu.Factory = object : Factory {
override fun create(
menu: Menu,
webViews: MutableList<KiwixWebView>,
urlIsValid: Boolean,
menuClickListener: MenuClickListener,
disableReadAloud: Boolean,
disableTabs: Boolean,
disableSearch: Boolean
): MainMenu =
MainMenu(
activity,
zimReaderContainer.zimFileReader,
menu,
webViews,
urlIsValid,
disableReadAloud,
disableTabs,
disableSearch,
menuClickListener
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,15 @@ object DownloaderModule {

@Provides
@Singleton
fun provideOkHttpDownloader() =
OkHttpDownloader(
OkHttpClient.Builder()
.connectTimeout(CONNECT_TIME_OUT, TimeUnit.MINUTES)
.readTimeout(READ_TIME_OUT, TimeUnit.MINUTES)
.addInterceptor(BasicAuthInterceptor())
.followRedirects(true)
.followSslRedirects(true)
.build()
)
fun provideOkHttpDownloader() = OkHttpDownloader(
OkHttpClient.Builder()
.connectTimeout(CONNECT_TIME_OUT, TimeUnit.MINUTES)
.readTimeout(READ_TIME_OUT, TimeUnit.MINUTES)
.addInterceptor(BasicAuthInterceptor())
.followRedirects(true)
.followSslRedirects(true)
.build()
)

@Provides
@Singleton
Expand Down
Loading

0 comments on commit 422e93c

Please sign in to comment.