Android Open Source - wifi-auto-forget Auto Forget Wifis Model






From Project

Back to project page wifi-auto-forget.

License

The source code is released under:

GNU General Public License

If you think the Android project wifi-auto-forget listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.cebesius.wifiautoforget.mvp;
// ww w. j  a  v  a2s  . c om
import android.os.AsyncTask;
import android.os.Bundle;

import com.cebesius.wifiautoforget.BuildConfig;
import com.cebesius.wifiautoforget.domain.AutoForgetWifi;
import com.cebesius.wifiautoforget.gateway.AutoForgetWifiStorage;
import com.cebesius.wifiautoforget.gateway.UserPreferenceStorage;
import com.cebesius.wifiautoforget.util.BusPortal;

import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ThreadPoolExecutor;

import static com.cebesius.wifiautoforget.mvp.AutoForgetWifisPresenter.AutoForgetWifisLoadedEvent;

/**
 * Model for the AutoForgetWifis management screen
 */
public class AutoForgetWifisModel {

    private final ActivityModelProxy activityModelProxy = new ActivityModelProxy();
    private final AutoForgetWifiStorage autoForgetWifiStorage;
    private final UserPreferenceStorage userPreferenceStorage;
    private final BusPortal busPortal;
    private List<AutoForgetWifi> autoForgetWifis;
    private HashMap<String, AutoForgetWifi> autoForgetWifisBySsid;

    public AutoForgetWifisModel(AutoForgetWifiStorage autoForgetWifiStorage, UserPreferenceStorage userPreferenceStorage, BusPortal busPortal) {
        this.autoForgetWifiStorage = autoForgetWifiStorage;
        this.userPreferenceStorage = userPreferenceStorage;
        this.busPortal = busPortal;
    }

    boolean isOnboardingEnabled() {
        return BuildConfig.FEATURE_ONBOARDING_ENABLED;
    }

    boolean hasUserCompletedOnboarding() {
        return userPreferenceStorage.hasUserCompletedOnboarding();
    }

    public ActivityModelProxy getActivityModelProxy() {
        return activityModelProxy;
    }

    void loadAutoForgetWifis() {
        new AsyncTask<Void, Void, Void>() {
            @Override
            protected Void doInBackground(Void... voids) {
                autoForgetWifis = autoForgetWifiStorage.getAllAutoForgetWifis();
                autoForgetWifisBySsid = new HashMap<>(autoForgetWifis.size());
                for (AutoForgetWifi autoForgetWifi : autoForgetWifis) {
                    autoForgetWifisBySsid.put(autoForgetWifi.getSsid(), autoForgetWifi);
                }
                busPortal.post(new AutoForgetWifisLoadedEvent());
                return null;
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }

    List<AutoForgetWifi> getAutoForgetWifis() {
        if (autoForgetWifis == null) {
            throw new IllegalStateException("Programmer error: must call loadAutoForgetWifis and receive success event before calling getAutoForgetWifis()");
        }
        return autoForgetWifis;
    }

    AutoForgetWifi findAutoForgetWifiBySsid(String ssid) {
        return autoForgetWifisBySsid.get(ssid);
    }

    void setAutoForgetWifiBehavior(final AutoForgetWifi autoForgetWifi, AutoForgetWifi.Behavior behavior) {
        autoForgetWifi.setBehavior(behavior);
        new AsyncTask<Void, Void, Void>() {
            @Override
            protected Void doInBackground(Void... voids) {
                autoForgetWifiStorage.save(autoForgetWifi);
                return null;
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }

    public static class ActivityModelProxy {

        private ActivityModelProxy() {
            // no-op
        }

        public void saveState(Bundle outState) {
            // TODO: save state
        }

        public void restoreState(Bundle savedInstanceState) {
            // TODO: restore state
        }
    }
}




Java Source Code List

antoche.HockeySender.java
com.cebesius.wifiautoforget.Secrets.java
com.cebesius.wifiautoforget.WifiAutoForgetApplication.java
com.cebesius.wifiautoforget.activity.AutoForgetWifisActivity.java
com.cebesius.wifiautoforget.adapter.AutoForgetWifisAdapter.java
com.cebesius.wifiautoforget.dialog.ChangeAutoForgetBehaviorDialog.java
com.cebesius.wifiautoforget.domain.AutoForgetWifi.java
com.cebesius.wifiautoforget.gateway.AddWifiNotificationUsageStorage.java
com.cebesius.wifiautoforget.gateway.AutoForgetWifiStorage.java
com.cebesius.wifiautoforget.gateway.NotificationIds.java
com.cebesius.wifiautoforget.gateway.SharedPreferenceKeys.java
com.cebesius.wifiautoforget.gateway.UserPreferenceStorage.java
com.cebesius.wifiautoforget.model.AutoForgetWifiModel.java
com.cebesius.wifiautoforget.mvp.ActivityView.java
com.cebesius.wifiautoforget.mvp.AddWifiModel.java
com.cebesius.wifiautoforget.mvp.AddWifiPresenter.java
com.cebesius.wifiautoforget.mvp.AddWifiView.java
com.cebesius.wifiautoforget.mvp.AppModel.java
com.cebesius.wifiautoforget.mvp.AppPresenter.java
com.cebesius.wifiautoforget.mvp.AppView.java
com.cebesius.wifiautoforget.mvp.AutoForgetWifisModel.java
com.cebesius.wifiautoforget.mvp.AutoForgetWifisPresenter.java
com.cebesius.wifiautoforget.mvp.AutoForgetWifisView.java
com.cebesius.wifiautoforget.mvp.ConnectivityChangeModel.java
com.cebesius.wifiautoforget.mvp.ConnectivityChangePresenter.java
com.cebesius.wifiautoforget.mvp.ConnectivityChangeView.java
com.cebesius.wifiautoforget.receiver.ConnectivityChangeReceiver.java
com.cebesius.wifiautoforget.service.AddWifiService.java
com.cebesius.wifiautoforget.service.ConnectivityChangeService.java
com.cebesius.wifiautoforget.util.AutoForgetDelegate.java
com.cebesius.wifiautoforget.util.BusPortal.java
com.cebesius.wifiautoforget.widget.AutoForgetWifiItem.java