Search in sources :

Example 6 with DownloadHelper

use of xyz.zedler.patrick.grocy.helper.DownloadHelper in project grocy-android by patzly.

the class MasterStoreFragment method onViewCreated.

@Override
public void onViewCreated(@Nullable View view, @Nullable Bundle savedInstanceState) {
    activity = (MainActivity) requireActivity();
    debug = PrefsUtil.isDebuggingEnabled(activity);
    // WEB
    dlHelper = new DownloadHelper(activity, TAG);
    grocyApi = activity.getGrocyApi();
    gson = new Gson();
    // VARIABLES
    stores = new ArrayList<>();
    storeNames = new ArrayList<>();
    editStore = null;
    isRefresh = false;
    // VIEWS
    binding.frameMasterStoreCancel.setOnClickListener(v -> activity.onBackPressed());
    // swipe refresh
    binding.swipeMasterStore.setProgressBackgroundColorSchemeColor(ContextCompat.getColor(activity, R.color.surface));
    binding.swipeMasterStore.setColorSchemeColors(ContextCompat.getColor(activity, R.color.secondary));
    binding.swipeMasterStore.setOnRefreshListener(this::refresh);
    // name
    binding.editTextMasterStoreName.setOnFocusChangeListener((View v, boolean hasFocus) -> {
        if (hasFocus) {
            ViewUtil.startIcon(binding.imageMasterStoreName);
        }
    });
    // description
    binding.editTextMasterStoreDescription.setOnFocusChangeListener((View v, boolean hasFocus) -> {
        if (hasFocus) {
            ViewUtil.startIcon(binding.imageMasterStoreDescription);
        }
    });
    MasterStoreFragmentArgs args = MasterStoreFragmentArgs.fromBundle(requireArguments());
    editStore = args.getStore();
    if (editStore != null) {
        fillWithEditReferences();
    } else if (savedInstanceState == null) {
        resetAll();
        new Handler().postDelayed(() -> activity.showKeyboard(binding.editTextMasterStoreName), 50);
    }
    if (savedInstanceState == null) {
        load();
    } else {
        restoreSavedInstanceState(savedInstanceState);
    }
    // UPDATE UI
    updateUI((getArguments() == null || getArguments().getBoolean(Constants.ARGUMENT.ANIMATED, true)) && savedInstanceState == null);
}
Also used : Gson(com.google.gson.Gson) Handler(android.os.Handler) DownloadHelper(xyz.zedler.patrick.grocy.helper.DownloadHelper) View(android.view.View)

Aggregations

DownloadHelper (xyz.zedler.patrick.grocy.helper.DownloadHelper)6 Handler (android.os.Handler)5 View (android.view.View)5 Gson (com.google.gson.Gson)5 SharedPreferences (android.content.SharedPreferences)4 Bundle (android.os.Bundle)2 NavHostFragment (androidx.navigation.fragment.NavHostFragment)2 ArrayList (java.util.ArrayList)2 PluralUtil (xyz.zedler.patrick.grocy.util.PluralUtil)2 ValueAnimator (android.animation.ValueAnimator)1 Dialog (android.app.Dialog)1 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 Configuration (android.content.res.Configuration)1 Resources (android.content.res.Resources)1 Build (android.os.Build)1 Html (android.text.Html)1 Spanned (android.text.Spanned)1