mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-24 05:46:14 +03:00
Add missing documentation
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
6884463d63
commit
79d417f475
2 changed files with 30 additions and 21 deletions
|
@ -92,6 +92,27 @@ public class NotesRepository {
|
||||||
private final MutableLiveData<Boolean> syncStatus = new MutableLiveData<>(false);
|
private final MutableLiveData<Boolean> syncStatus = new MutableLiveData<>(false);
|
||||||
private final MutableLiveData<ArrayList<Throwable>> syncErrors = new MutableLiveData<>();
|
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>
|
* @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);
|
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) {
|
private void observeNetworkStatus(ConnectionLiveData.ConnectionType connectionType) {
|
||||||
if (connectionType == ConnectionLiveData.ConnectionType.Lost) {
|
if (connectionType == ConnectionLiveData.ConnectionType.Lost) {
|
||||||
networkConnected = false;
|
networkConnected = false;
|
||||||
|
|
|
@ -7,12 +7,21 @@ import android.net.NetworkCapabilities
|
||||||
import android.net.NetworkRequest
|
import android.net.NetworkRequest
|
||||||
import androidx.lifecycle.LiveData
|
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>() {
|
class ConnectionLiveData(val context: Context) : LiveData<ConnectionLiveData.ConnectionType>() {
|
||||||
|
|
||||||
private val connectivityManager =
|
private val connectivityManager =
|
||||||
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||||
private val networkRequest = NetworkRequest.Builder().build()
|
private val networkRequest = NetworkRequest.Builder().build()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enum representing different types of network connections.
|
||||||
|
*/
|
||||||
enum class ConnectionType {
|
enum class ConnectionType {
|
||||||
Lost, WiFi, Ethernet, MobileData, Other
|
Lost, WiFi, Ethernet, MobileData, Other
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue