Search in sources :

Example 1 with WeatherFragment

use of com.a5corp.weather.fragment.WeatherFragment in project Weather by Sparker0i.

the class WeatherActivity method changeCity.

public void changeCity(String city) {
    WeatherFragment wf = (WeatherFragment) getSupportFragmentManager().findFragmentById(R.id.fragment);
    wf.changeCity(city);
    new Prefs(this).setCity(city);
}
Also used : WeatherFragment(com.a5corp.weather.fragment.WeatherFragment) Prefs(com.a5corp.weather.preferences.Prefs)

Example 2 with WeatherFragment

use of com.a5corp.weather.fragment.WeatherFragment in project Weather by Sparker0i.

the class WeatherActivity method checkForCity.

private void checkForCity(final String city) {
    final FetchWeather wt = new FetchWeather(this);
    final Context context = this;
    new Thread() {

        @Override
        public void run() {
            try {
                json = wt.execute(city).get();
            } catch (InterruptedException | ExecutionException ex) {
                ex.printStackTrace();
            }
            if (json == null) {
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        new MaterialDialog.Builder(context).title(getString(R.string.city_not_found)).content(getString(R.string.city_not_found)).onAny(new MaterialDialog.SingleButtonCallback() {

                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                dialog.dismiss();
                            }
                        }).negativeText(getString(android.R.string.ok)).onNegative(new MaterialDialog.SingleButtonCallback() {

                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                dialog.dismiss();
                            }
                        });
                    }
                });
            } else {
                if (dbHelper.cityExists(json.day.getName() + "," + json.day.getSys().getCountry())) {
                    handler.post(new Runnable() {

                        @Override
                        public void run() {
                            new MaterialDialog.Builder(context).title(getString(R.string.city_already_exists)).content(getString(R.string.need_not_add)).negativeText(getString(android.R.string.ok)).onNegative(new MaterialDialog.SingleButtonCallback() {

                                @Override
                                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                    dialog.dismiss();
                                }
                            }).show();
                        }
                    });
                } else {
                    dbHelper.addCity(json.day.getName() + "," + json.day.getSys().getCountry());
                    handler.post(new Runnable() {

                        @Override
                        public void run() {
                            SecondaryDrawerItem itemx = new SecondaryDrawerItem().withName(json.day.getName() + "," + json.day.getSys().getCountry()).withIcon(new IconicsDrawable(context).icon(GoogleMaterial.Icon.gmd_place)).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

                                @Override
                                public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                                    if (!(f instanceof WeatherFragment)) {
                                        wf = new WeatherFragment().setCity(json.day.getName() + "," + json.day.getSys().getCountry());
                                        getSupportFragmentManager().beginTransaction().replace(R.id.fragment, wf).commit();
                                    }
                                    return true;
                                }
                            });
                            drawer.addItemAtPosition(itemx, ++i);
                        }
                    });
                }
            }
        }
    }.start();
}
Also used : Context(android.content.Context) IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) WeatherFragment(com.a5corp.weather.fragment.WeatherFragment) Drawer(com.mikepenz.materialdrawer.Drawer) SecondaryDrawerItem(com.mikepenz.materialdrawer.model.SecondaryDrawerItem) View(android.view.View) FetchWeather(com.a5corp.weather.internet.FetchWeather) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(androidx.annotation.NonNull) IconicsDrawable(com.mikepenz.iconics.IconicsDrawable)

Example 3 with WeatherFragment

use of com.a5corp.weather.fragment.WeatherFragment in project Weather by Sparker0i.

the class WeatherActivity method initDrawer.

public void initDrawer() {
    final IProfile profile = new ProfileDrawerItem().withName(getString(R.string.app_name)).withEmail("Version : " + BuildConfig.VERSION_NAME).withIcon(R.mipmap.ic_launcher_x);
    AccountHeader headerResult = new AccountHeaderBuilder().withActivity(this).withHeaderBackground(R.drawable.header).withTextColor(ContextCompat.getColor(this, R.color.md_amber_400)).addProfiles(profile).withSelectionListEnabled(false).withProfileImagesClickable(false).build();
    SecondaryDrawerItem item1 = new SecondaryDrawerItem().withName(R.string.drawer_item_home).withIcon(new IconicsDrawable(this).icon(WeatherIcons.Icon.wic_day_sunny)).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            wf = new WeatherFragment();
            getSupportFragmentManager().beginTransaction().replace(R.id.fragment, wf).commit();
            return true;
        }
    });
    SecondaryDrawerItem item2 = new SecondaryDrawerItem().withName(R.string.drawer_item_graph).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_trending_up)).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            if (!(f instanceof GraphsFragment)) {
                GraphsFragment graphsFragment = newGraphInstance(new ArrayList<>(wf.getDailyJson()));
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment, graphsFragment).commit();
            }
            return true;
        }
    });
    SecondaryDrawerItem item3 = new SecondaryDrawerItem().withName(R.string.drawer_item_map).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_map)).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            if (!(f instanceof MapsFragment)) {
                MapsFragment mapsFragment = new MapsFragment();
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment, mapsFragment).commit();
            }
            return true;
        }
    });
    SecondaryDrawerItem item4 = new SecondaryDrawerItem().withName(R.string.drawer_item_add_city).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_add_location)).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            showCityDialog();
            return true;
        }
    }).withSelectable(false);
    SecondaryDrawerItem item8 = new SecondaryDrawerItem().withName(R.string.drawer_item_about).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_info)).withSelectable(false).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            startActivity(new Intent(WeatherActivity.this, AboutActivity.class));
            return true;
        }
    });
    SecondaryDrawerItem item9 = new SecondaryDrawerItem().withName(R.string.settings).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_settings)).withSelectable(false).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            startActivity(new Intent(WeatherActivity.this, SettingsActivity.class));
            return true;
        }
    });
    DrawerBuilder drawerBuilder = new DrawerBuilder();
    drawerBuilder.withActivity(this).withToolbar(toolbar).withTranslucentStatusBar(true).withAccountHeader(headerResult).withActionBarDrawerToggleAnimated(true).addDrawerItems(item1, item2, item3, new DividerDrawerItem(), item4).addStickyDrawerItems(item8, item9);
    List<String> cities = dbHelper.getCities();
    final ListIterator<String> listIterator = cities.listIterator(cities.size());
    while (listIterator.hasPrevious()) {
        final String city = listIterator.previous();
        drawerBuilder.addDrawerItems(new SecondaryDrawerItem().withName(city).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_place)).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

            @Override
            public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                wf = new WeatherFragment().setCity(city);
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment, wf).commit();
                return true;
            }
        }));
    }
    drawer = drawerBuilder.build();
}
Also used : IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) DividerDrawerItem(com.mikepenz.materialdrawer.model.DividerDrawerItem) ProfileDrawerItem(com.mikepenz.materialdrawer.model.ProfileDrawerItem) ArrayList(java.util.ArrayList) AccountHeaderBuilder(com.mikepenz.materialdrawer.AccountHeaderBuilder) Intent(android.content.Intent) WeatherFragment(com.a5corp.weather.fragment.WeatherFragment) Drawer(com.mikepenz.materialdrawer.Drawer) SecondaryDrawerItem(com.mikepenz.materialdrawer.model.SecondaryDrawerItem) View(android.view.View) AccountHeader(com.mikepenz.materialdrawer.AccountHeader) MapsFragment(com.a5corp.weather.fragment.MapsFragment) IProfile(com.mikepenz.materialdrawer.model.interfaces.IProfile) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder) IconicsDrawable(com.mikepenz.iconics.IconicsDrawable) GraphsFragment(com.a5corp.weather.fragment.GraphsFragment)

Example 4 with WeatherFragment

use of com.a5corp.weather.fragment.WeatherFragment in project Weather by Sparker0i.

the class WeatherActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_weather);
    Log.i("Activity", WeatherActivity.class.getSimpleName());
    mManager = NotificationManagerCompat.from(this);
    preferences = new Prefs(this);
    toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    fab = findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            hideFab();
            showInputDialog();
        }
    });
    Intent intent = getIntent();
    handler = new Handler();
    fab.show();
    wf = new WeatherFragment();
    Bundle bundle = new Bundle();
    bundle.putInt("mode", intent.getIntExtra(Constants.MODE, 0));
    wf.setArguments(bundle);
    gf = new GraphsFragment();
    // mf = new MapsFragment();
    dbHelper = new DBHelper(this);
    getSupportFragmentManager().beginTransaction().replace(R.id.fragment, wf).commit();
    initDrawer();
    NotificationService.enqueueWork(this, new Intent(this, WeatherActivity.class));
}
Also used : Bundle(android.os.Bundle) DBHelper(com.a5corp.weather.preferences.DBHelper) Handler(android.os.Handler) Intent(android.content.Intent) WeatherFragment(com.a5corp.weather.fragment.WeatherFragment) Prefs(com.a5corp.weather.preferences.Prefs) View(android.view.View) GraphsFragment(com.a5corp.weather.fragment.GraphsFragment)

Aggregations

WeatherFragment (com.a5corp.weather.fragment.WeatherFragment)4 View (android.view.View)3 Intent (android.content.Intent)2 GraphsFragment (com.a5corp.weather.fragment.GraphsFragment)2 Prefs (com.a5corp.weather.preferences.Prefs)2 IconicsDrawable (com.mikepenz.iconics.IconicsDrawable)2 Drawer (com.mikepenz.materialdrawer.Drawer)2 SecondaryDrawerItem (com.mikepenz.materialdrawer.model.SecondaryDrawerItem)2 IDrawerItem (com.mikepenz.materialdrawer.model.interfaces.IDrawerItem)2 Context (android.content.Context)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 NonNull (androidx.annotation.NonNull)1 MapsFragment (com.a5corp.weather.fragment.MapsFragment)1 FetchWeather (com.a5corp.weather.internet.FetchWeather)1 DBHelper (com.a5corp.weather.preferences.DBHelper)1 DialogAction (com.afollestad.materialdialogs.DialogAction)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 AccountHeader (com.mikepenz.materialdrawer.AccountHeader)1 AccountHeaderBuilder (com.mikepenz.materialdrawer.AccountHeaderBuilder)1