From a1e99677718f7d27b3c336d273896af9cef1fe7d Mon Sep 17 00:00:00 2001 From: s-ayush2903 Date: Sun, 21 Jun 2020 21:14:18 +0530 Subject: [PATCH 1/4] fix #2155 converted KiwixWifiP2pBroadcastReceiver class to kotlin --- .../KiwixWifiP2pBroadcastReceiver.java | 86 ------------------ .../KiwixWifiP2pBroadcastReceiver.kt | 90 +++++++++++++++++++ 2 files changed, 90 insertions(+), 86 deletions(-) delete mode 100644 app/src/main/java/org/kiwix/kiwixmobile/local_file_transfer/KiwixWifiP2pBroadcastReceiver.java create mode 100644 app/src/main/java/org/kiwix/kiwixmobile/local_file_transfer/KiwixWifiP2pBroadcastReceiver.kt diff --git a/app/src/main/java/org/kiwix/kiwixmobile/local_file_transfer/KiwixWifiP2pBroadcastReceiver.java b/app/src/main/java/org/kiwix/kiwixmobile/local_file_transfer/KiwixWifiP2pBroadcastReceiver.java deleted file mode 100644 index de19db033..000000000 --- a/app/src/main/java/org/kiwix/kiwixmobile/local_file_transfer/KiwixWifiP2pBroadcastReceiver.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Kiwix Android - * Copyright (c) 2019 Kiwix - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package org.kiwix.kiwixmobile.local_file_transfer; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.net.NetworkInfo; -import android.net.wifi.p2p.WifiP2pDevice; -import android.net.wifi.p2p.WifiP2pManager; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -/** - * Helper class for the local file sharing module. - * - * Handles the broadcasts pertaining to the wifi p2p group formed in WiFi Direct. Works along with - * the wifi p2p manager in {@link WifiDirectManager}. - */ -public class KiwixWifiP2pBroadcastReceiver extends BroadcastReceiver { - - private P2pEventListener p2pEventListener; - - public KiwixWifiP2pBroadcastReceiver(@NonNull P2pEventListener p2pEventListener) { - this.p2pEventListener = p2pEventListener; - } - - @Override - public void onReceive(@NonNull Context context, @NonNull Intent intent) { - - switch (intent.getAction()) { - case WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION: { - int wifiP2pState = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1); - p2pEventListener.onWifiP2pStateChanged( - (wifiP2pState == WifiP2pManager.WIFI_P2P_STATE_ENABLED)); - break; - } - - case WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION: { - p2pEventListener.onPeersChanged(); - break; - } - - case WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION: { - NetworkInfo networkInfo = intent.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO); - p2pEventListener.onConnectionChanged(networkInfo.isConnected()); - break; - } - - case WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION: { - WifiP2pDevice userDevice = intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE); - p2pEventListener.onDeviceChanged(userDevice); - break; - } - - default: - break; - } - } - - public interface P2pEventListener { - void onWifiP2pStateChanged(boolean isEnabled); - - void onPeersChanged(); - - void onConnectionChanged(boolean isConnected); - - void onDeviceChanged(@Nullable WifiP2pDevice userDevice); - } -} diff --git a/app/src/main/java/org/kiwix/kiwixmobile/local_file_transfer/KiwixWifiP2pBroadcastReceiver.kt b/app/src/main/java/org/kiwix/kiwixmobile/local_file_transfer/KiwixWifiP2pBroadcastReceiver.kt new file mode 100644 index 000000000..9ecc56dcd --- /dev/null +++ b/app/src/main/java/org/kiwix/kiwixmobile/local_file_transfer/KiwixWifiP2pBroadcastReceiver.kt @@ -0,0 +1,90 @@ +/* + * Kiwix Android + * Copyright (c) 2019 Kiwix + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +@file:Suppress("PackageNaming") + +package org.kiwix.kiwixmobile.local_file_transfer + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import android.net.NetworkInfo +import android.net.wifi.p2p.WifiP2pDevice +import android.net.wifi.p2p.WifiP2pManager.EXTRA_NETWORK_INFO +import android.net.wifi.p2p.WifiP2pManager.EXTRA_WIFI_P2P_DEVICE +import android.net.wifi.p2p.WifiP2pManager.EXTRA_WIFI_STATE +import android.net.wifi.p2p.WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION +import android.net.wifi.p2p.WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION +import android.net.wifi.p2p.WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION +import android.net.wifi.p2p.WifiP2pManager.WIFI_P2P_STATE_ENABLED +import android.net.wifi.p2p.WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION +import android.util.Log + +/** + * Helper class for the local file sharing module. + * + * Handles the broadcasts pertaining to the wifi p2p group formed in WiFi Direct. Works along with + * the wifi p2p manager in [WifiDirectManager]. + */ + +class KiwixWifiP2pBroadcastReceiver(private val p2pEventListener: P2pEventListener) : + BroadcastReceiver() { + + override fun onReceive(context: Context, intent: Intent) { + when (intent.action) { + + WIFI_P2P_STATE_CHANGED_ACTION -> { + val wifiP2pState = intent.getIntExtra(EXTRA_WIFI_STATE, -1) + p2pEventListener.onWifiP2pStateChanged( + wifiP2pState == WIFI_P2P_STATE_ENABLED + ) + } + + WIFI_P2P_PEERS_CHANGED_ACTION -> { + p2pEventListener.onPeersChanged() + } + + WIFI_P2P_CONNECTION_CHANGED_ACTION -> { + val networkInfo = + intent.getParcelableExtra(EXTRA_NETWORK_INFO) + p2pEventListener.onConnectionChanged(networkInfo.isConnected) + } + + WIFI_P2P_THIS_DEVICE_CHANGED_ACTION -> { + val userDevice = + intent.getParcelableExtra(EXTRA_WIFI_P2P_DEVICE) + p2pEventListener.onDeviceChanged(userDevice) + } + + else -> { + Log.d(TAG, "onReceive: No change in P2P connection detected!") + } + } + } + + companion object { + private const val TAG = "WifiP2pBroadcastRecvr" + } + + interface P2pEventListener { + fun onWifiP2pStateChanged(isEnabled: Boolean) + fun onPeersChanged() + fun onConnectionChanged(isConnected: Boolean) + fun onDeviceChanged(userDevice: WifiP2pDevice?) + } +} From 9273e3146bf9fc5e3e37fdb2fa9a5a7473758f2c Mon Sep 17 00:00:00 2001 From: s-ayush2903 Date: Mon, 22 Jun 2020 23:04:21 +0530 Subject: [PATCH 2/4] linted file --- .../KiwixWifiP2pBroadcastReceiver.kt | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/local_file_transfer/KiwixWifiP2pBroadcastReceiver.kt b/app/src/main/java/org/kiwix/kiwixmobile/local_file_transfer/KiwixWifiP2pBroadcastReceiver.kt index 9ecc56dcd..88d457f5b 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/local_file_transfer/KiwixWifiP2pBroadcastReceiver.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/local_file_transfer/KiwixWifiP2pBroadcastReceiver.kt @@ -44,36 +44,24 @@ import android.util.Log class KiwixWifiP2pBroadcastReceiver(private val p2pEventListener: P2pEventListener) : BroadcastReceiver() { - override fun onReceive(context: Context, intent: Intent) { when (intent.action) { - WIFI_P2P_STATE_CHANGED_ACTION -> { val wifiP2pState = intent.getIntExtra(EXTRA_WIFI_STATE, -1) - p2pEventListener.onWifiP2pStateChanged( - wifiP2pState == WIFI_P2P_STATE_ENABLED - ) + p2pEventListener.onWifiP2pStateChanged(wifiP2pState == WIFI_P2P_STATE_ENABLED) } - - WIFI_P2P_PEERS_CHANGED_ACTION -> { - p2pEventListener.onPeersChanged() - } - + WIFI_P2P_PEERS_CHANGED_ACTION -> p2pEventListener.onPeersChanged() WIFI_P2P_CONNECTION_CHANGED_ACTION -> { val networkInfo = intent.getParcelableExtra(EXTRA_NETWORK_INFO) p2pEventListener.onConnectionChanged(networkInfo.isConnected) } - WIFI_P2P_THIS_DEVICE_CHANGED_ACTION -> { val userDevice = intent.getParcelableExtra(EXTRA_WIFI_P2P_DEVICE) p2pEventListener.onDeviceChanged(userDevice) } - - else -> { - Log.d(TAG, "onReceive: No change in P2P connection detected!") - } + else -> Log.d(TAG, "onReceive: No change in P2P connection detected!") } } From 824ee0868f4944ccfb3719c6ee2ef691064bc6b6 Mon Sep 17 00:00:00 2001 From: s-ayush2903 Date: Wed, 24 Jun 2020 02:25:28 +0530 Subject: [PATCH 3/4] Reverted useless logging --- .../local_file_transfer/KiwixWifiP2pBroadcastReceiver.kt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/local_file_transfer/KiwixWifiP2pBroadcastReceiver.kt b/app/src/main/java/org/kiwix/kiwixmobile/local_file_transfer/KiwixWifiP2pBroadcastReceiver.kt index 88d457f5b..a45ae0647 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/local_file_transfer/KiwixWifiP2pBroadcastReceiver.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/local_file_transfer/KiwixWifiP2pBroadcastReceiver.kt @@ -33,7 +33,6 @@ import android.net.wifi.p2p.WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION import android.net.wifi.p2p.WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION import android.net.wifi.p2p.WifiP2pManager.WIFI_P2P_STATE_ENABLED import android.net.wifi.p2p.WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION -import android.util.Log /** * Helper class for the local file sharing module. @@ -61,14 +60,9 @@ class KiwixWifiP2pBroadcastReceiver(private val p2pEventListener: P2pEventListen intent.getParcelableExtra(EXTRA_WIFI_P2P_DEVICE) p2pEventListener.onDeviceChanged(userDevice) } - else -> Log.d(TAG, "onReceive: No change in P2P connection detected!") } } - companion object { - private const val TAG = "WifiP2pBroadcastRecvr" - } - interface P2pEventListener { fun onWifiP2pStateChanged(isEnabled: Boolean) fun onPeersChanged() From 0825eaa9b5686c501a891e9e05c9e793bf1e8778 Mon Sep 17 00:00:00 2001 From: HissPirat Date: Wed, 24 Jun 2020 16:06:43 +0200 Subject: [PATCH 4/4] #2161 moved isChecked to above where the onCheckedListener is set for bookmarks and history activity. --- .../kiwix/kiwixmobile/core/page/bookmark/BookmarksActivity.kt | 2 +- .../org/kiwix/kiwixmobile/core/page/history/HistoryActivity.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/page/bookmark/BookmarksActivity.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/page/bookmark/BookmarksActivity.kt index 5fdf8abc4..92c0d1708 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/page/bookmark/BookmarksActivity.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/page/bookmark/BookmarksActivity.kt @@ -83,10 +83,10 @@ class BookmarksActivity : OnItemClickListener, BaseActivity() { recycler_view.adapter = bookmarksAdapter recycler_view.layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false) + bookmarks_switch.isChecked = sharedPreferenceUtil.showBookmarksAllBooks bookmarks_switch.setOnCheckedChangeListener { _, isChecked -> bookmarkViewModel.actions.offer(Action.UserClickedShowAllToggle(isChecked)) } - bookmarks_switch.isChecked = sharedPreferenceUtil.showBookmarksAllBooks compositeDisposable.add(bookmarkViewModel.effects.subscribe { it.invokeWith(this) }) } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/page/history/HistoryActivity.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/page/history/HistoryActivity.kt index d309b70b0..404e45937 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/page/history/HistoryActivity.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/page/history/HistoryActivity.kt @@ -88,10 +88,10 @@ class HistoryActivity : OnItemClickListener, BaseActivity() { recycler_view.adapter = historyAdapter compositeDisposable.add(historyViewModel.effects.subscribe { it.invokeWith(this) }) + history_switch.isChecked = sharedPreferenceUtil.showHistoryAllBooks history_switch.setOnCheckedChangeListener { _, isChecked -> historyViewModel.actions.offer(Action.UserClickedShowAllToggle(isChecked)) } - history_switch.isChecked = sharedPreferenceUtil.showHistoryAllBooks } override fun onCreateOptionsMenu(menu: Menu): Boolean {