Add missing documentation

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-02-07 10:47:25 +01:00 committed by Alper Öztürk
parent 6884463d63
commit 79d417f475
2 changed files with 30 additions and 21 deletions

View file

@ -92,6 +92,27 @@ public class NotesRepository {
private final MutableLiveData<Boolean> syncStatus = new MutableLiveData<>(false);
private final MutableLiveData<ArrayList<Throwable>> syncErrors = new MutableLiveData<>();
private final Observer<? super ConnectionLiveData.ConnectionType> syncObserver = (Observer<ConnectionLiveData.ConnectionType>) connectionType -> {
observeNetworkStatus(connectionType);
if (context == null || executor == null) {
return;
}
if (isSyncPossible() && SSOUtil.isConfigured(context)) {
executor.submit(() -> {
try {
scheduleSync(getAccountByName(SingleAccountHelper.getCurrentSingleSignOnAccount(context).name), false);
} catch (NextcloudFilesAppAccountNotFoundException |
NoCurrentAccountSelectedException e) {
Log.v(TAG, "Can not select current SingleSignOn account after network changed, do not sync.");
}
});
}
};
private final Observer<? super ConnectionLiveData.ConnectionType> networkStatusObserver = (Observer<ConnectionLiveData.ConnectionType>) this::observeNetworkStatus;
/**
* @see <a href="https://stackoverflow.com/a/3104265">Do not make this a local variable.</a>
*/
@ -144,27 +165,6 @@ public class NotesRepository {
connectionLiveDataForNetworkStatus.observeForever(networkStatusObserver);
}
private final Observer<? super ConnectionLiveData.ConnectionType> syncObserver = (Observer<ConnectionLiveData.ConnectionType>) connectionType -> {
observeNetworkStatus(connectionType);
if (context == null || executor == null) {
return;
}
if (isSyncPossible() && SSOUtil.isConfigured(context)) {
executor.submit(() -> {
try {
scheduleSync(getAccountByName(SingleAccountHelper.getCurrentSingleSignOnAccount(context).name), false);
} catch (NextcloudFilesAppAccountNotFoundException |
NoCurrentAccountSelectedException e) {
Log.v(TAG, "Can not select current SingleSignOn account after network changed, do not sync.");
}
});
}
};
private final Observer<? super ConnectionLiveData.ConnectionType> networkStatusObserver = (Observer<ConnectionLiveData.ConnectionType>) this::observeNetworkStatus;
private void observeNetworkStatus(ConnectionLiveData.ConnectionType connectionType) {
if (connectionType == ConnectionLiveData.ConnectionType.Lost) {
networkConnected = false;

View file

@ -7,12 +7,21 @@ import android.net.NetworkCapabilities
import android.net.NetworkRequest
import androidx.lifecycle.LiveData
/**
* LiveData subclass that provides network connection status updates.
* It observes changes in network connectivity and posts updates to its observers.
*
* @property context The application context used to access system services.
*/
class ConnectionLiveData(val context: Context) : LiveData<ConnectionLiveData.ConnectionType>() {
private val connectivityManager =
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
private val networkRequest = NetworkRequest.Builder().build()
/**
* Enum representing different types of network connections.
*/
enum class ConnectionType {
Lost, WiFi, Ethernet, MobileData, Other
}